home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol023 / disasmb.doc < prev    next >
Text File  |  1984-04-29  |  11KB  |  270 lines

  1. DISASMB -- A TABLE DRIVEN DISASSEMBLER WRITTEN IN MICROSOFT BASIC
  2.  
  3. This package consists of two main programs and a set of support programs
  4. and files.
  5.  
  6. Among its features:
  7.  
  8. -- By loading assembler mnenomics tables at run-time, the program can
  9.    disassemble into any assembly language for which tables are available.
  10.  
  11. -- Output can be sent to the console, printer and/or a disk file.
  12.  
  13. -- A cross-reference file can be created as part of disassembly,
  14.    sorted, and listed on the printer and/or console.
  15.  
  16. -- Source code can be either a disk file or located in memory.
  17.  
  18. -- All 16-bit values are converted to labels, which permit relocation.
  19.  
  20. -- Every byte of code is disassembled. The program treats secondary code
  21.    as a comment.
  22.  
  23. -- In addition to its mnenomic value, the hex value and ASCII equivalent
  24.    of each byte is listed. This facilitates location of data and text
  25.    blocks.
  26.  
  27. -- The program runs reasonably fast under the Basic interpreter and can
  28.    presumably be compiled with the Microsoft Basic compiler, although
  29.    this does require a few modifications of the program.
  30.  
  31. ----------
  32.  
  33. RUNNING DISASMB.BAS
  34.  
  35. To begin with, you have to have Microsoft Basic-80 ver 5.1 or later,
  36. since this program makes use of the long variable names facilitated
  37. as part of ver 5.
  38.  
  39. The disassembler first requests the name of the assembly language to
  40. be used. A .LST file, which contains the opcode and operand mnenomics,
  41. and a .TAB file, which contains a table to define the names of each
  42. byte, must be available under that name. Thus, if INTEL is specified,
  43. the files INTEL.LST and INTEL.TAB must be found. Otherwise, an error
  44. message will be printed and a new name will be requested.
  45.  
  46. Once the tables have been loaded, a menu is displayed and the user is
  47. allowed to specify actions to be taken. The options available are:
  48.  
  49. -- END
  50.    Self explanatory.
  51.  
  52. -- CONSOLE toggle
  53.    PRINTER toggle
  54.    Switching these will determine where generated listings will be
  55.    displayed. If the printer is enabled, hitting "P" disables it,
  56.    hitting "P" again re-enables it.
  57.  
  58. -- TABLE LOAD
  59.    If you want to switch assembly languges you can do so. If the
  60.    .LST file is not found an error message is issued and the old files
  61.    remain loaded.
  62.  
  63. -- LIST OPCODES
  64.    This generates a table showing the mnenomic equivalent for each
  65.    opcode under the currently loaded assembly language tables. Note
  66.    that since Zilog index codes are disassembled by testing for
  67.    reference to the HL register, these codes are not listed in this
  68.    table.
  69.  
  70. -- WRITE LISTING TO DISK
  71.    The dissembled code is written to disk. The standard source file
  72.    extension is provided as part of the .LST file, and this is used
  73.    as a default value. If a cross-reference file has been specifed,
  74.    this file name is used as a default as well. A new name and/or
  75.    extension can, of course, be provided.
  76.  
  77. -- X-REF FILE GENERATION
  78.    A cross-reference file is generated, listing each 16-bit value loaded,
  79.    the current address and whether it is appears to be a primary or
  80.    secondary [ie: not necessarily valid] value.
  81.  
  82. -- MEMORY DISASSEMBLE
  83.    The first value requested is the starting address in memory for the
  84.    program to be disassembled. A second program starting address is then
  85.    required. The memory starting address is assumed, but if a different
  86.    value is entered the diassembler assumes the program has been
  87.    relocated in memory and acts accordingly. The final value to be
  88.    entered is the program end address, relative to the program starting
  89.    address, NOT the memory start.
  90.  
  91. -- DISK DISASSEMBLE
  92.    This disassembles from a disk file. If a write or x-ref file has been
  93.    specified that file name is assumed, as is the extension .COM. The
  94.    program start is assumed to be at 100H, but a different value can
  95.    be entered.
  96.  
  97. Miscellaneous notes:
  98.  
  99. To begin with, the disassembler has no real way of knowing what is
  100. machine instruction and what is data. Similarly, it can not know
  101. if a 16-bit value loaded into a register is an absolute value or a
  102. memory reference. Thus, for a file to be re-assembled it will first
  103. have to be edited. Some of this is easy -- blocks of text will stick
  104. out in the ASCII column -- but determining whether a 16-bit value
  105. should be be converted from a label to an absolute value, by removing the
  106. the prefix "x", can prove a bit tricky, although the x-ref listings
  107. should help.
  108.  
  109. It is also important to keep in mind that every byte of source code
  110. generates 30-40 bytes of disassembled disk file. Which means that
  111. even rather small source files can generate rather large output files.
  112.  
  113. Commands issued from the menu are entered via the INPUT$(1) command,
  114. which means that simply hitting a key serves to enter the command.
  115. By the time you hit a return it's too late.
  116.  
  117. When an assumed value is given, hitting a return means that it will
  118. be used.
  119.  
  120. The menu is updated to show the status of each function, including the
  121. names of any designated output disk files.
  122.  
  123. Output disk files are disabled at the end of any disassembly cycle
  124. but console and printer status are not changed.
  125.  
  126. The program includes a convert-to-caps routine, so that data can be entered
  127. as lower case if desired.
  128.  
  129. ----------
  130.  
  131. USING XREF.BAS
  132.  
  133. Since this program is not table-dependent, the menu is displayed
  134. immediately. The options available are:
  135.  
  136. -- CONSOLE TOGGLE
  137.    PRINTER TOGGLE
  138.    These work the same as with DISASMB.BAS.
  139.  
  140. -- SORT FILE
  141.    This sorts an .XRF file generated by DISASMB and then prints it.
  142.  
  143. -- LIST FILE
  144.    This takes a sorted file and simply lists it.
  145.  
  146. The sort program is a heap sort but under the interpreter this still
  147. takes time. So a submit file, XREF.SUB, is provided to permit MicroPro's
  148. SuperSort to do the deed with great dispatch.
  149.  
  150. The first column of the listing is the destination address, the second
  151. column contains primary source addresses, the third column contains
  152. secondary source addresses.
  153.  
  154. The listing is paginated and normally displays two columns to a page.
  155. Both of these values can be changed by modifying indicated constants at
  156. the start of the program.
  157.  
  158. ----------
  159.  
  160. CREATING .LST AND .TAB FILES
  161.  
  162. This package contains four sets of files:
  163.  
  164. -- INTEL -- standard Intel mnenomics for the 8080 and CP/M assembler.
  165.  
  166. -- 8085 -- adds the SIM and RIM instructions to INTEL.
  167.  
  168. -- ZILOG -- standard Zilog mnenomics with extension .MAC for Macro-80.
  169.  
  170. -- TDL -- TDL's Intel-extended-to-Zilog mnenomics with extension .SRC
  171.    for the InterSystems assembler.
  172.  
  173. I have included the TAB<name>.BAS and LST<name>.BAS programs which
  174. generated these files in order to facilitate changes.
  175.  
  176. The .LST file contains the mnenomic names and miscellaneous values
  177. for the disassemblers. The order is:
  178.     ALEN -- The number of columns in the .TAB file. Standard
  179.         Intel has 3, Zilog has 9.
  180.     ZCOM -- The comment character/string, generally ";".
  181.     ZLAB -- The label terminator string. This is optional but
  182.         permissible to most assemblers, but Macro-80 apparently
  183.         requires it.
  184.     ZBYTE -- The byte pseudo-op.
  185.     ZEXT -- The extension assumed by the assembler.
  186.     AZIL -- Since the index register codes can be easily
  187.         disassembled by testing for use of the HL registers,
  188.         this approach was used. However, this requires
  189.         language-dependent code, so this value tells the
  190.         disassembler what, if any, procedures to use.
  191.         The provided values are:
  192.             0 - no index-register codes
  193.             1 - standard Zilog mnenomics
  194.             2 - TDL mnenomics
  195.     Number of operands
  196.     null operand
  197.     1..n operands
  198.     Number of opcodes
  199.     null operand
  200.     "N" operand
  201.     "NN" operand
  202.     "(NN)" operand
  203.     relative displacement operand
  204.     5..n non-reserved operands
  205.  
  206. The reserved operands must be allowed for, whether or not the language
  207. provides for that instruction. Other than that, opcodes and operands
  208. may be listed in any order.
  209.  
  210. The .TAB file contains the .LST position of the opcode and the first
  211. and second operands for each byte. The values are stored as bytes.
  212. New .LST and .TAB files can be checked using the list opcodes procedure
  213. in DISASMB.
  214.  
  215. ----------
  216.  
  217. FINAL BITS OF INFORMATION
  218.  
  219. [1] MBasic allows strings to be of an arbitrary length. There is a price,
  220. however: When a string is created or changed it is simply tossed on top
  221. of the string stack. From time to time this process exhausts available
  222. memory and the intepreter has to stop to purge the stack of extraneous
  223. strings. Thus, during the generation of a disassembler listing the
  224. process will stall for a number of seconds to permit the purge.
  225.  
  226. [2] In order to conserve memory, the opcode, operand and table arrays
  227. are dynamically redimensioned in DISASMB. If this program is to be
  228. compiled using BASCOM, these have to be changed to absolute values.
  229. The maximum values for the various tables are:
  230.     
  231.     name        opcodes        operands    table
  232.     INTEL         80        22        2,255
  233.     8085         80        22        2,255
  234.     ZILOG         67        48        8,255
  235.     TDL        136        22        8,255
  236.  
  237. [3] There are two ways which MBasic can tell whether it has reached
  238. the end of an input file: (a) It is told by CP/M that it is on the
  239. last sector of the current extent and that there are no further
  240. last sector of the current extent and taht there are no further extents
  241. or (b) it encounters a control-z code at the start of a logical block
  242. (a line in a sequential file or a sector in a random file).
  243.  
  244. There are some problems with this approach. Since DISASMB reads source
  245. files as a series of sector-long records it has been instructed to
  246. continue reading if both EOF is true and the first byte on the sector
  247. is a 1AH (control-z). This may cause the program to read past the end
  248. of a file, but ultimately it will be forced to initialize a sector
  249. which will result in a proper stop.
  250.  
  251. For .XRF files the end of file is indicated by two 0FFH bytes followed
  252. by 1AH's. This is the FFZZ end flag for SuperSort.
  253.  
  254. [4] Disassembled disk files use horizontal tabs to separate columns in
  255. order to compress the length of the files at least a little.
  256.  
  257. [5] MBasic clears the input buffer for normal data input but not for
  258. INPUT$. With interrupt-based input, however, this means that it is
  259. possible to accidently enter commands in response to the menu's prompt.
  260.  
  261. [6] XREF.BAS creates and then erases two files named XREFWORK.### and
  262. XREFWORK.$$$. XREF.SUB creates and then erates XREFWORK.###.
  263.  
  264. ----------
  265.  
  266. Scott Custin
  267. 2410 20th St NW #10
  268. Washington DC 20009
  269.  
  270.