home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / cdactual / demobin / share / program / Pascal / ASSEM120.ZIP / ASSEMBLE.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-09-24  |  3.3 KB  |  114 lines

  1. Program AssembleTest;  { Tests the ASSEM120 unit }
  2. Uses Assem120,Crt,Dos;
  3. {$M $5000,0,$10000}
  4.  
  5. { By Joseph J. Tamburino / 7 Christopher Rd / Westford, MA 01886
  6.   Prodigy account #:  NWNJ91A }
  7.  
  8. {     TO RUN THIS PROGRAM:
  9.          1)  Substitute your own debugger and command.com paths (lines 21,22)
  10.                            -- or --
  11.              Remove the debugger portion of the code (in the main
  12.              program block)
  13.  
  14.          2)  Using Turbo Pascal, compile and run the program (Tested only with
  15.              Turbo Pascal 5.0)
  16.  
  17.          3)  Enter a legal 8088/86 instruction, and observe the results
  18. }
  19.  
  20. Const
  21.      PathCommandCom:  string=('c:\command.com'); { Substitute YOUR command.com here }
  22.      PathDebugger:  string=('symdeb');           { Substitute YOUR debugger here }
  23.  
  24. Type
  25.      HexByte = string[2];             {Storage for a 2-digit hex number}
  26.  
  27. Var
  28.      Instruction,St:  string;
  29.      TestFile:  text;
  30.      i:  integer;
  31.      Start:  word;
  32.  
  33. Function Hex(n:  byte):  HexByte;
  34. { Given a 1-byte number, n, return its hex equivalent }
  35. Const
  36.      Digits:  string='0123456789ABCDEF';
  37.  
  38. Begin
  39.      Hex:=Digits[n shr 4+1]+Digits[n and 15+1]
  40. End;
  41.  
  42. Function HexW(n:  word):  string;
  43. Begin
  44.      HexW:=Hex(Hi(n))+Hex(Lo(n))
  45. End;
  46.  
  47. Procedure Capitalize(Var St:  string);
  48. { Strip lowercase characters from St }
  49. Var
  50.      i:  integer;
  51.  
  52. Begin
  53.      For i:=1 to length(St) do St[i]:=Upcase(St[i])
  54. End;
  55.  
  56. Function FromHex(n:  string):  word;
  57. { Given a hexadecimal character string in the form "Hx[xxx]", return its
  58.   numeric equivalent }
  59. Var
  60.      n1:  byte;
  61.      Tmp:  word;
  62.      i:  integer;
  63.  
  64. Begin
  65.      Capitalize(n);
  66.      Tmp:=0;
  67.      i:=2;
  68.      While (i<=length(n)) and (n[i] in ['0'..'9','A'..'F']) do
  69.      Begin
  70.           Tmp:=Tmp shl 4;
  71.           if n[i] in ['A'..'F'] then
  72.                 n1:=15-(ord('F')-ord(n[i]))
  73.           else
  74.                 n1:=9-(ord('9')-ord(n[i]));
  75.           Tmp:=Tmp+n1;
  76.           inc(i)
  77.      End;
  78.      FromHex:=Tmp
  79. End;
  80.  
  81. Begin
  82.       ClrScr;
  83.       Write('Enter HEX offset to start from  [',HexW(InstructionAddr),']:  ');
  84.       ReadLn(St);
  85.       if St<>'' then InstructionAddr:=FromHex('h'+St);
  86.       Start:=InstructionAddr;
  87.       Repeat
  88.            WriteLn('Enter an instruction to assemble (ENTER to quit):  ');
  89.            Write('XXXX:',HexW(InstructionAddr),':  ');
  90.            ReadLn(Instruction);
  91.            if Instruction<>'' then
  92.            Begin
  93.                 Assemble(Instruction);   { <----  This does the assembling }
  94.                 WriteLn;
  95.                 assign(testfile,'testfile');
  96.                 rewrite(testfile);
  97.                 writeln(testfile,'e '+HexW(InstructionAddr));
  98.                 Inc(InstructionAddr,BytePtr-1);
  99.                 Write('Bytes for instruction:  ');
  100.                 For i:=1 to BytePtr-1 do
  101.                 Begin
  102.                       Write(Hex(Bytes[i]),' ');
  103.                       Write(testfile,Hex(Bytes[i]),' ')
  104.                 End;
  105.                 Writeln(TestFile);
  106.                 Writeln(TestFile,'u '+HexW(Start)+' '+HexW(InstructionAddr-1));
  107.                 WriteLn(TestFile,'q');
  108.                 Close(TestFile);
  109.                 WriteLn;
  110.                 Exec(PathCommandCom,'/C '+PathDebugger+' <testfile');
  111.                 WriteLn; Writeln
  112.            End
  113.       Until Instruction=''
  114. End.