home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / asm / tchasm / tchasm.doc < prev    next >
Text File  |  1979-12-31  |  43KB  |  1,014 lines

  1. These are documents copied from CHASM by David Whitman and are provided
  2. only because TChasm is a Turbo Pascal version of CHASM.  I copied David's
  3. program almost word for word. (converting to pascal when necessary)
  4. I have placed comments in these notes preceded by {!} to note changes.
  5.  
  6. The editor included with TChasm is the FIRST-ED from Borland International's
  7. Turbo Editor Toolbox (tm).  I deleted all of the ^O commands as well as
  8. those referring to markers. (See table of editing commands that follow)
  9. I have left intact the WordStar (tm) commands and have included some
  10. additional commands, which I prefer.  The Toolbox is well worth its cost.
  11. I have provided only the source code for the assembler and the hooks into
  12. the editor.  The only significant change I have made to the editor routines
  13. is adding an OK := true; (or false) in the EditReaTxtFil procedure to see
  14. if there was enough memory left after loading the source file into memory.
  15. (I leave this bit of coding to you)
  16.  
  17. To compile the program, you will need the Editor Toolbox.  Merge VARS.PAS
  18. into VARS.ED and INIT.PAS into INIT.ED.  Comment out any code relating to
  19. Window commands (the O-commands) and Markers, otherwise the resulting code
  20. will be too large and you will need to use overlays.  Make the above change
  21. to EditReaTxtFil.  I have made changes to EditKeypressed to allow the various
  22. keys to have new meanings.  I've been able to compile and run from memory
  23. the program on an IBM PC with 256K.
  24.  
  25. If you have a computer with little memory, you may want to change the program
  26. to have overlays. (I would suggest swapping the editor and assembler routines
  27. in and out of memory)  I don't care for overlays because you must stay in
  28. one directory - Well, actually you don't, but I didn't want to write the extra
  29. code necessary. (see MicroStar included with the Editor Toolbox)
  30.  
  31. As I am placing this program out here for public use, don't send me any money.
  32. If you feel it is of any use or value, send a donation to Mr. Whitman.  He
  33. has obviously worked very hard to develop CHASM and I am indebted to him for
  34. not forcing me to pay for it.  I would like to hear about any bugs (egads!) or
  35. improvements you may discover.  This is only Version 1.0, so I'm sure there
  36. will be updates.  (I would really enjoy hearing about a way to make this a
  37. single pass assembler, if it is at all possible)   Please write and let me
  38. know how you like it.  (by not paying me, I also stipulate that YOU not sell
  39. this program to anyone either)
  40.                                 Mark Streich
  41.                                 1160 Glen Arbor Ave.
  42.                                 Los Angeles, CA 90041
  43.  
  44. P.S. I can be reached on the ECANET RBBS (seems to be one of the few BBS's
  45. around that I am able to get on often enough to check messages) at
  46. 818-896-7450.
  47.  
  48. Editor Commands (use of arrow keys or control keys is up to you)
  49. ---------------
  50. ^A [^Left] Left Word       ^F [^Right] Right Word
  51. ^S         Left Char       ^D          Right Char
  52. ^E         Up Line         ^X          Down Line
  53. ^C [PgDn]  Down Page       ^R [PgUp]   Up Page
  54. ^W         Scroll Up       ^Z          Scroll Down
  55. ^Y         Delete Line     ^N          Insert Line
  56. ^G [Del]   Delete Char     ^P          Insert Ctrl Char
  57. ^I [Tab]   Tab             ^T          Delete Word
  58. ^V [Ins]   Toggle Insert   ^L [F4]     Repeat Last Find or Replace
  59.    [Esc]   Undo (after delete lines - 20 lines max)
  60.  
  61. ^Q^C [^PgDn] End of File     ^Q^R [^PgUp] Top of File
  62. ^Q^B         To Beg. Block   ^Q^K         To End of Block
  63. ^Q^A [F3]    Find/Replace    ^Q^F [F2]    Find
  64. ^Q^D [End]   End of Line     ^Q^S [Home]  Start of Line
  65. ^Q^I         Auto Indent     ^Q^Y         Delete to End of Line
  66.  
  67. ^K^B [F7]    Begin Block     ^K^K [F8]    End Block
  68. ^K^C         Copy Block      ^K^V         Move Block
  69. ^K^Y         Delete Block    ^K^H         Hide Block
  70. ^K^R         Read File       ^K^W         Write Block
  71. ^K^D [F1]    Quit Edit       ^K^T         Set Tab Width
  72. ^K^S         Save File (from within Editor)
  73.  
  74. Main Screen Functions are all fairly self-explanatory.
  75. L - Logged Directory, changes current directory
  76. W - Work File, Changes current working file (assumes .ASM extension)
  77. O - Output Location, Lists output to either Screen, Printer, a File,
  78.     or none.  (You will get a progress status on screen)  The program
  79.     always creates a .COM file even if there are errors. You will need to
  80.     exit TChasm to run them. (I can't replicate Turbo Pascal!)
  81. File Location - Just lets you know whether the file is in memory or on the
  82.     disk. (it is on Disk whenever there isn't enough memory to hold it)
  83. E - Edit, Takes you into the editor if there is enough memory to hold the
  84.     file.
  85. S - Save the file which is currently in memory.  The Editor does NOT make
  86.     a .BAK file when saving.  If you want to be safe, do a Block Write to
  87.     another file.
  88. A - Assemble, begins the two-pass assembling of the work file.
  89. D - Directory, (from Turbo Tutor by Borland Int'l.)  Could have used some
  90.     of the other public domain directory listers, but this one works fine.
  91. Q - Quit,  If changes have been made to file, will prompt for saving.
  92.  
  93. The program KAZOO.ASM is for your amusement and practice.  It is copied from
  94. Robert Lafore's "Assembly Language Primer for the IBM PC & XT."  I have found
  95. the book easy to read and useful.  Now that I've written an assembler, I intend
  96. to learn assembly language.
  97.  
  98. {CHASM.DOC by David Whitman begins here.}
  99.  
  100.                       NOTE:
  101.  
  102. You can print out this file by pressing CTRL PrtSc and
  103. then: TYPE CHASM.DOC.  Before you do, note the following:
  104.  
  105.    1. The documentation is about 30 pages long - have
  106.       lots of paper ready.
  107.  
  108.    2. If your printer has a condensed (132 column) mode,
  109.       turn it on before printing.  If you do, the resulting
  110.       pages can be cut down to 5 1/4 X 8 1/2 inches to fit
  111.       in an IBM document binder.
  112.  
  113. If you do not have access to a printer, the author
  114. will provide a copy of the documentation for $5.
  115. The $5 fee covers the cost of Xeroxing and mailing,
  116. and is not included in the $20 suggested donation.
  117.  
  118.                                (tm)
  119.                               CHASM
  120.  
  121.                         Cheap Assembler
  122.                   for the IBM Personal Computer
  123.  
  124.                      (1983) by David Whitman
  125.                            Version 1.9
  126.  
  127.                        Table of Contents
  128.  
  129.      Why Chasm?...........................................2
  130.  
  131.      What can Chasm do?...................................3
  132.  
  133.      What WON'T it do?....................................3
  134.  
  135.      Syntax...............................................4
  136.  
  137.      Operands.............................................6
  138.  
  139.      Resolution of Ambiguities...........................10
  140.  
  141.      Pseudo-Operations...................................13
  142.  
  143.      Outside the Program Segment.........................16
  144.  
  145.      Running Chasm.......................................18
  146.  
  147.      Error and Diagnostic Messages.......................20
  148.  
  149.      Execution of Assembled Programs.....................23
  150.  
  151.      Notes for Those Upgrading to This Version of Chasm..26
  152.  
  153.      Miscellaneous and A Word From Our Sponsor...........28
  154.  
  155.      I. Why Chasm?
  156.  
  157.          Why go to the trouble to write an assembler, when
  158.      one already exists?  The IBM Macro Assembler is a very
  159.      powerful software tool available off the shelf.  It
  160.      supports features such as macros, definition of
  161.      multiple segments, and linking to external procedures.
  162.  
  163.          Unfortunately, all of this power doesn't fit into a
  164.      64K machine, and even when using the small subset
  165.      version, 64K users are limited by memory to only very
  166.      small programs. The macro assembler is also very
  167.      complex, hard to understand, and costs a hundred bucks.
  168.  
  169.          Even though the price of memory keeps dropping, I
  170.      suspect that the majority of the IBM PC's out there have
  171.      no more than 64K installed.  Also, I suspect that most
  172.      end-user assembly language programmers are like myself,
  173.      and are not interested in writing huge, complicated
  174.      programs in assembler. I want to write short
  175.      subroutines to call from BASIC, small patches to
  176.      existing assembler programs (such as DOS), and perhaps
  177.      some games. For such uses, I think the combination of
  178.      the Macro Assembler and a tub full of extra memory
  179.      represents an incredible overkill. Chasm is, I hope, a
  180.      more reasonable compromise between power and
  181.      accessability (both in cost and complexity).
  182.  
  183.      II. What can Chasm do?
  184.  
  185.          Chasm takes a text file, consisting of mnemonics,
  186.      user-defined symbols, numbers, and pseudo-ops, and
  187.      produces a file of corresponding machine language for
  188.      the 8088 processor. Chasm allows you to define labels
  189.      for branching, rather than requiring you to figure out
  190.      offsets or addresses to jump to.  It allows you to
  191.      represent with a name any constants you want to use,
  192.      making your programs easier to understand. Most
  193.      importantly, it translates mnemonics to their machine
  194.      language equivalents freeing you from the task of hand
  195.      translation.
  196.  
  197.      III. What WON'T it do?
  198.  
  199.          In the interest of simplicity, Chasm has a number
  200.      of restrictions:
  201.  
  202.          1. Statement syntax is not quite as free as in the
  203.             macro assembler.
  204.  
  205.          2. The number of pseudo-ops is severely cut down
  206.             from the macro assembler.
  207.  
  208.          3. Macros are not supported.  (Note that the IBM
  209.             assembler doesn't support macros in systems
  210.             smaller than 96K)
  211.  
  212.          4. Expressions (such as BUFFER - 2 ) are not
  213.             supported, at least in version 1.0.
  214.  
  215.          5. Multiple segment definitions are not allowed, at
  216.             least in version 1.0. Chasm assumes that your
  217.             entire program fits in one segment, that the cs,
  218.             ds, and es registers all point to this same
  219.             segment, and that the ss register points to a
  220.             valid stack area.
  221.  
  222.          6. External linking is not supported, at least in
  223.             version 1.0.
  224.  
  225.      IV. Syntax
  226.  
  227.      Chasm accepts a standard DOS text file for input. Lines
  228.      may be any combination of upper and lower case
  229.      characters. Chasm does not distinguish between the two
  230.      cases:  everything except single quoted strings are
  231.      automatically converted to upper case during the
  232.      parsing process. Thus, BUFFER, Buffer, buffer, and
  233.      bUFFer all refer to the same symbol.
  234.  
  235.      The characters  blank ( ) , comma (,), single quote (')
  236.      and semi-colon (;) are reserved, and have special
  237.      meaning to Chasm (see below).
  238.  
  239. {!}  TChasm uses the first character found in the second line of
  240.      TChasm.DAT as the Quote character.  This can be any character
  241.      you want.  So if you don't like the default of a Double Quote,
  242.      change it.
  243.  
  244.      Each line must be less than 256 characters long and
  245.      have the following format:
  246.  
  247.      Label Operation Operand(s) ;comment
  248.  
  249.      The differant fields of an input line are separated
  250.      by the delimiters blank ( ) or comma (,).  Any number of
  251.      either delimiter may be used to separate fields.
  252.  
  253.      Explanation of Fields:
  254.  
  255.      Label: A label is a string of characters, beginning in
  256.         column 1. Depending on the operation field, the label
  257.         might represent a program location for branching, a
  258.         memory location, or a numeric constant. Note that
  259.         anything  beginning in column 1, except a comment, is
  260.         considered a label.
  261.  
  262.      Operation: Either a pseudo-op (see section VII) or an
  263.         instruction mnemonic as defined in "The 8086 Book" by
  264.         Rector and Alexy.
  265.  
  266.         Note 1: Except as modified below,"The 8086 Book" is
  267.            the definitive referance for use with Chasm.
  268.  
  269.         Note 2: There are several ways to resolve some
  270.            ambiguities in 8086 assembly language. Please read
  271.            page 3-285 of The 8086 Book, and section VI of
  272.            this document.
  273.  
  274.      Operand(s): A list of one or more operands,as defined
  275.         in section V, separated by delimiters.
  276.  
  277.      Comment: Any string of characters, beginning with a
  278.         semicolon (;).  Anything to the right of a semicolon
  279.         will be ignored by Chasm.
  280.  
  281.      Note that except for the case of an operation which
  282.      requires operands, or the EQU pseudo-op which requires
  283.      a label, all of the fields are optional. The fields
  284.      MUST appear in the order shown.
  285.  
  286.      V. Operands
  287.  
  288.      The following operand types are allowed.
  289.  
  290.      1. Immediate data: A number, stored as part of the
  291.         program's object code.  Immediate data are classified
  292.         as either byte, expressable as an 8 bit binary
  293.         integer; or word, expressable as a 16 bit binary
  294.         integer. If context requires it, CHASM will left-pad
  295.         byte values with zeroes to convert them to word values.
  296.         Attempts to use a word value where only a byte will
  297.         fit will cause an error message to be printed.
  298.  
  299.      Immediate data may be represented in 5 ways:
  300.  
  301.         A. An optionally signed decimal number in the range
  302.            -32768 to 32767. Examples:
  303.  
  304.             MOV AL,21
  305.             MOV BX,-6300
  306.  
  307.         B.1. A series of up to 4 hex digits, followed by the
  308.              letter H. Examples:
  309.  
  310.            ADD CX,1234H
  311.            ADD DL FDH
  312.  
  313. {!}     B.2. A series of binary digits followed by letter B.
  314.            ADD CX,11110111B
  315.  
  316.         C. A symbol representing types A or B above,
  317.            defined using the EQU pseudo-op.  Examples:
  318.  
  319.            MASK EQU 10H
  320.            MAX  EQU 1000
  321.                 AND  CL,MASK
  322.                 SUB  AX,MAX
  323.  
  324.         D. The offset of a label or storage location returned
  325.            by the OFFSET operator.  OFFSET always returns a
  326.            word value. OFFSET is used to get the address
  327.            of a named memory location, rather than its contents.
  328.            Example:
  329.  
  330.                   MOV DI,OFFSET(BUFFER)
  331.            BUFFER DS  FFH
  332.  
  333.         E. The ASCII value of a printable character,
  334.            represented by the character enclosed in single
  335.            quotes (').  Thus, the following lines will
  336.            generate the same object code:
  337. {!}       Any quote Character you want for Tchasm. (see opening remarks)
  338.           Default is Double Quotes rather than single Quote.
  339.  
  340.                   MOV AL,41H  ;ascii code for 'A'
  341.                   MOV AL,'A'
  342.  
  343.      2. Register Operands: One of the 8088's internal
  344.         registers.
  345.  
  346.         A. An 8 bit register from the following list:
  347.            AH    AL
  348.            BH    BL
  349.            CH    CL
  350.            DH    DL
  351.  
  352.         B. A 16 bit register from the following list:
  353.            AX   BX   CX   DX   SP   BP   SI   DI
  354.  
  355.         C. A segment register from the following list:
  356.            CS   SS   DS   ES
  357.  
  358.      3. Memory Operands: The contents of a memory
  359.         location addressed by one of the following
  360.         methods. Note that none of the memory
  361.         adressing options specifies the whether a
  362.         byte or word operand is being referanced.
  363.         See section VI for more on this topic.
  364.  
  365.         A. Direct address.
  366.  
  367.            1. A number, or symbol representing a
  368.               number, enclosed in brackets, indicating
  369.               an offset into the data segment. Example:
  370.  
  371.               BUFFER EQU 5A5AH
  372.                      MOV BH,[BUFFER]
  373.                      MOV [80H],DI
  374.  
  375.            2. A symbol, defined to be a variable (i.e.
  376.               a named memory location) using the EQU
  377.               pseudo-op. Example:
  378.  
  379.                   FCB EQU [80H]
  380.                       MOV DI,FCB
  381.  
  382.             3. A symbol, defined to be a variable by its
  383.                use on a storage defining pseudo-op.
  384.                Examples:
  385.  
  386.                     MOV AX,FLAG
  387.                     MOV DATE,BX
  388.                FLAG DS 1
  389.                DATE DB 31
  390.  
  391.          B. Indirect Address:  The address of the operand is
  392.             the sum of the contents of the indicated
  393.             register(s) and a displacement. The register, or
  394.             sum of registers, are enclosed in square
  395.             brackets: []
  396.  
  397.             The displacement is optional, and takes the
  398.             form of an immediate operand, placed without
  399.             intervening delimiters to the left of the first
  400.             bracket.  Displacements in the range -128 to 127
  401.             (i.e. hex 0 - 7F, FF80 - FFFF) are interpreted as
  402.             signed 8 bit quantities. All other displacements
  403.             are interpreted as unsigned 16 bit quantities.
  404.             (Note that although the 8088 supports unsigned 16
  405.             bit displacements up to hex FFFF for indirect
  406.             adressing, Chasm isn't smart enough to distinguish
  407.             between -1 and FFFFH.)
  408.  
  409.             The following indirect modes are allowed:
  410.  
  411.             1. Indirect through a base register (BX or BP).
  412.                Examples:
  413.  
  414.                ENTRYLENGTH EQU 6
  415.                            MOV AX, ENTRYLENGTH[BP]
  416.                            MOV DL, -2[BX]
  417.                            MOV CX, [BP]
  418.                            MOV 9A9AH[BX], AX
  419.  
  420.             2. Indirect through an index register (DI or SI).
  421.                Examples:
  422.  
  423.                MOV [DI], CX
  424.                MOV CX, -5[SI]
  425.  
  426.             3. Indirect through the sum of one base register
  427.                and one index register. Examples:
  428.  
  429.                MOV [BP+DI], SP      ;note that no spaces are
  430.                MOV BX, 10H[BX+SI]   ;allowed within the
  431.                MOV CL, [BP+SI]      ;brackets.
  432.                MOV DH, -2[BX+DI]
  433.  
  434.        4. Labels
  435.  
  436.             A label on a machine instruction may be used as
  437.             an operand for call and jump instructions.
  438.             Examples:
  439.  
  440.                START PROC NEAR
  441.                      CALL GETINPUT
  442.                      JMPS START
  443.                      ENDP
  444.             GETINPUT PROC NEAR
  445.  
  446.        5. Strings
  447.             A string is any sequence of characters (including
  448.             delimiters) surrounded by single quotes (').
  449. {!}         Any character you want for TChasm ( "Copyright May 15, 1985" )
  450.             Example:
  451.  
  452.             DB 'Copyright May 15,1982'
  453.  
  454.      VI. Resolution of Ambiguities.
  455.  
  456.          The language defined in "The 8086 Book" contains a
  457.      number of ambiguities which must be resolved by an
  458.      assembler. This is discussed throughout the book, but
  459.      pages 3-285 and 3-286 specifically cover this topic.
  460.      Chasm's solutions of these problems are discussed in
  461.      this section.
  462.  
  463.      A. Memory referances:
  464.  
  465.          When one specifies the address of a memory
  466.      location, it is unclear how large an operand is being
  467.      referanced. An operand might be a byte, or a word.
  468.  
  469.          1. If a register is present as an operand, it is
  470.             assumed that the memory operand matches the
  471.             register in size. An exception to this rule are
  472.             the shift and rotate instructions, where the CL
  473.             register is used as a counter, and has nothing
  474.             to do with the size of the other operand. Examples:
  475.  
  476.             MOV MASK,AX   ;mask is a word
  477.             MOV DH,[BX]   ;BX points to a byte
  478.             NEG [SI]      ;error, operand of unknown size
  479.             SHR FLAG,CL   ;error, flag is of unknown size
  480.  
  481.          2. If no register is present, (or if the only
  482.             register is CL being used as a counter) the size
  483.             of the memory operand is specified by adding the
  484.             suffix "B" or "W" to the instruction mnemonic.
  485.             Examples:
  486.  
  487.             NEGB [SI]       ;SI points to a byte
  488.             SHRW FLAG,CL    ;flag is a word
  489.             MOVW MASK,0AH   ;mask is a word
  490.             MOVB MASK,0AH   ;mask is a byte
  491.             MOVW MASK,9A9AH ;must specify size even though
  492.                             ;immediate operand implies word
  493.             MOVB DH,[BX]    ;error(!), register already
  494.                             ;specifies size
  495.  
  496.      B. Indirect Branching.
  497.  
  498.          The 8088 supports two flavors of indirect
  499.      branching: intra, and inter segment. A register is set
  500.      to point at a memory location which contains a new
  501.      value for the program counter, and in the case of
  502.      intersegment branching, a new value for the CS register
  503.      as well.
  504.  
  505.          The syntax of "The 8086 Book" does not specify
  506.      which flavor of branch is being invoked.  Chasm adds
  507.      the suffixes "N" (for near, or intrasegment) and "F"
  508.      (for far, or intersegment) to the indirect CALL and JMP
  509.      mnemonics. Examples:
  510.  
  511.          CALLN [BX]    ;intrasegment call
  512.          JMPF  [DI]    ;intersegment jump
  513.          JMP   [BP]    ;error, unspecified flavor
  514.  
  515.      C. Long and Short Jumps
  516.  
  517.      Two types of relative jumps are supported by the
  518.      8088: short (specified by a signed 8 bit displacement)
  519.      and long (specified by an unsigned 16 bit displacement).
  520.      Both are implemented in Chasm as a jump to a label.
  521.  
  522.      The short jump is specified by mnemonic JMPS, in accord
  523.      with the IBM disassembler, but not with The 8086 Book, which
  524.      uses JMP.  Since one of the displacement bits is used as a sign
  525.      bit, only seven are left to express the magnitude of jump.  JMPS
  526.      (and similarly, all the jump on condition instructions) is thus
  527.      limited to branching to labels within a range of -128 to +127
  528.      bytes.
  529.  
  530.      Chasm reserves mnemonic JMP for the long jump.  Note that JMP
  531.      may only be used to jump in the forward direction, since the
  532.      sixteen bit displacement is unsigned, and assumed to be positive.
  533.      Examples:
  534.  
  535.          START PROC NEAR
  536.                JMPS START   ;short jump
  537.                JMPS END     ;short jump
  538.                JMP  END     ;long jump
  539.                JMP  START   ;error: reverse long jump
  540.          END   ENDP
  541.  
  542.      D. Instruction Prefixes.
  543.  
  544.          The 8088 supports three instruction prefixes:
  545.  
  546.          1. SEG: segment override. An alternate segment
  547.             register is specified for a referance to memory
  548.  
  549.          2. REP, REPE,REPNE,REPZ,REPNZ: repeat. A string
  550.             primitive is repeated until a condition is met.
  551.  
  552.          3. LOCK: Turns on the LOCK signal. Only useful in
  553.             multiprocessor situations.
  554.  
  555.          Chasm implements these prefixes as separate
  556.      instructions, rather than prefixes to another
  557.      instruction.  They appear on a separate line,
  558.      immediately before the instruction which they modify.
  559.      This is in accord with the output of the IBM
  560.      disassembler, but not with the IBM macro assembler.
  561.      Examples:
  562.  
  563.          SEG ES
  564.          MOV AX,FLAG  ;flag is in the extra segment
  565.          REP
  566.          MOVSB        ;move bytes until CX decremented to 0
  567.  
  568.      VII. Pseudo-Operations
  569.  
  570.          The following pseudo-ops are implemented:
  571.  
  572.          A. DB: Declare Bytes
  573.  
  574.             Memory locations are filled with values from the
  575.             operand list. Any number of operands may appear,
  576.             but all must fit on one line. Acceptable operands
  577.             are numbers between 0 and FFH (0-255 decimal), or
  578.             strings enclosed in single quotes (').  If a label
  579.             appears, it is considered a variable, and the
  580.             location may be refered to using the label, rather
  581.             than an address. Examples:
  582.  
  583.                     MOV AX,MASK
  584.               MASK  DB  00H,01H
  585.               STG   DB  'A string operand'
  586.  
  587.          B. DS: Declare Storage
  588.  
  589.             Used to declare large blocks of identically
  590.             initialized storage.  The first operand is
  591.             required, a number specifying how many bytes
  592.             are declared.  If a second operand in the form
  593.             of a number 0-FFH appears, the locations will
  594.             all be initialized to this value. If the second
  595.             operand is not present, locations are initialized
  596.             to 0. As with DB, any label is considered a
  597.             variable.  To save space, the object code does not
  598.             appear on the listing. Examples:
  599.  
  600.             DS 10         ;10 locs initialized to 0
  601.             DS 100H,1AH   ;256 locs initialized to 1AH
  602.  
  603.          C. ENDP: End of Procedure
  604.  
  605.             See PROC (below) for details.
  606.  
  607.          D. EQU: Equate
  608.  
  609.             Used to equate a symbolic name with a number.
  610.             The symbol may then be used anywhere the
  611.             number would be used.  Use of symbols makes
  612.  
  613.             programs more understandable, and simplifies
  614.             modification.
  615.  
  616.             An alternate form of EQU encloses the number
  617.             in square brackets: [].  The symbol is then
  618.             interpreted as a variable, and may be used as an
  619.             address for memory access.  This version is
  620.             provided to allow symbolic referance to locations
  621.             outside the program segment.
  622.  
  623.             Warning: Difficult to debug errors may result
  624.             from using a symbol prior to its being defined
  625.             by EQU.  I strongly urge that all equates be
  626.             grouped together at the beginning of programs,
  627.             before any machine instructions. See "Phase Error"
  628.             in section IX. Examples:
  629.  
  630.                 MOFFSET    EQU B000H
  631.                 MONOCHROME EQU [0000H]
  632.  
  633.          E. ORG: Origin
  634.  
  635.             Allows direct manipulation of the location
  636.             counter during assembly.  By default, Chasm
  637.             assembles code to start at offset 100H, the
  638.             origin expected by COMMAND.COM for .COM
  639.             programs.  Using ORG you may override this
  640.             default. Example:
  641.  
  642.                ORG 0   ;Code will be assembled for starting
  643.                        ;offset of 0
  644.  
  645.          F. PROC ...ENDP: Procedure Definition
  646.  
  647.             Declares a procedure.  One operand is required on
  648.             PROC, either the word NEAR, or the word FAR.
  649.             This pseudo-op warns Chasm whether to assemble
  650.             returns as intra (near) or intersegment (far).
  651.             Procedures called from within your program should
  652.             be declared NEAR. All others should be FAR.
  653.             ENDP terminates the procedure, and requires no
  654.             operands.  If a RET is encountered outside of a
  655.             declared procedure, an error occurs.  Procedures
  656.             may be nested, up to 10 deep. Example:
  657.  
  658.                 MAIN   PROC  FAR
  659.                        ...
  660.                        ...      ;body of procedure
  661.                        ENDP
  662.  
  663.      VIII. Outside the Program Segment
  664.  
  665.          As mentioned previously, Chasm does not support
  666.      multiple segment definitions.  Provision is made for
  667.      limited access outside of the program segment, however.
  668.  
  669.          A. Memory Referances
  670.             To access memory outside the program segment, you
  671.             simply move a new segment address into the DS
  672.             register, then address using offsets in the new
  673.             segment.  The memory option of the EQU pseudo-op
  674.             allows you to give a variable name to offsets in
  675.             other segments. For example, to access the graphics
  676.             charactor table in ROM:
  677.  
  678.             BIOS       EQU  F000H
  679.             CHARTABLE  EQU  [FA6EH]
  680.                        MOV  AX,BIOS   ;can't move immed. to DS
  681.                        MOV  DS,AX
  682.                        MOV  AL,CHARTABLE ;1st byte of char. table
  683.  
  684.          B. Code Branching
  685.  
  686.             Chasm supports 4 instructions for branching
  687.             outside the program segment.
  688.  
  689.             1. Direct CALL and JMP
  690.                New values for the PC and CS registers are
  691.                included in the instruction as two immediate
  692.                operands. Example:
  693.  
  694.                BIOS        EQU  F000H    ;RAM bios segment
  695.                DISKETE_IO  EQU  EC59     ;disk handler
  696.                            JMP  DISKETE_IO,BIOS
  697.  
  698.             2. Indirect CALLF and JMPF
  699.                Four consecutive bytes in memory are
  700.                initialized with new values for the PC and CS
  701.                registers.  The CALLF or JMPF then referances
  702.                the address of the new values. Example:
  703.  
  704.                BIOS        EQU   F000H    ;RAM bios segment
  705.                PRINTER_IO  EQU   EFD2H    ;printer routine
  706.                            MOV   [DI],PRINTER_IO
  707.  
  708.                            MOV   2[DI],BIOS
  709.                            CALLF [DI]
  710.  
  711. {!}      Running Tchasm : Type TChasm    (TChasm.Dat and TChasm.Msg must
  712.          both be in same directory).
  713.          You will be greeted with a message and then the main screen.
  714.          This is where you get to all the features.  After assembling,
  715.          you will be back at the Main Screen.  (maybe somebody can figure
  716.          out how to let assembly language programs run from within
  717.          TChasm - Probably has a lot of changing of interrupts etc.)
  718.          If there are any errors listed however, I would suggest you not
  719.          run your program. (Even if you pick no Output, you will be given
  720.          a message about how many errors were detected.
  721.  
  722.      X. Error and Diagnostic Messages
  723.  
  724.      Error messages generated on pass one appear on the
  725.      listing before any source code is printed, and mention
  726.      the line number to which they refer.  The majority of
  727.      messages occur during pass two, and will appear in the
  728.      listing immediately prior to the line which caused the
  729.      message.
  730.  
  731.      Could Use JMPS: Diagnostic.  The specified label
  732.         requires an offset of less than 128 bytes; specifying
  733.         the short jump would result in more compact code.
  734.         The assembled code is correct, however.
  735.  
  736.      Data too Long: The value of a immediate byte is
  737.         found not to be in the range 0-FFH
  738.  
  739.      Duplicate Definition of XXX in (linenum): Pass 1
  740.         error. An attempt was made to define a symbol already
  741.         present in the symbol table.
  742.  
  743.      ENDP without PROC: An ENDP was encountered, but no
  744.         corresponding PROC was found.
  745.  
  746.      EQU Without Label: No symbol was found to equate
  747.         with the operand
  748.  
  749.      Illegal or Undefined Argument for Offset: The
  750.         argument for the Offset function was not present in
  751.         the symbol table as a near label or memory location
  752.         on pass 2.
  753.  
  754.      Illegal Reverse Long Jump: Long jumps must in the
  755.         forward direction, since they are expressed with an
  756.         unsigned displacement.
  757.  
  758.      Missing ENDP: The end of the input file was
  759.         encountered, and at least one PROC had not been
  760.         terminated by an ENDP.
  761.  
  762.      Phase Error: A near label or memory location is
  763.         found to have differant values on pass 1 and pass 2.
  764.         A difficult to debug error: generally the problem is
  765.         not caused by the statement which received the error
  766.         message.
  767.  
  768.            The only documented way to generate this error is
  769.         by using a symbol prior to defining it using EQU. On
  770.         pass 1, Chasm assumes that unrecognized symbols are
  771.         either labels or memory addresses which will be
  772.         defined later in the program.  If the symbol is
  773.         subsequently defined as immediate data, the location
  774.         counter may get all messed up.  I would appreciate
  775.         hearing about any other situations which cause this
  776.         message to appear.
  777.  
  778.      Procedures Nested Too Deeply: Procedures may be
  779.         nested no more than 10 deep.
  780.  
  781.      Specify Word or Byte Operation: Diagnostic. Chasm
  782.         suggests that the Syntax Error might be resolved by
  783.         adding the suffix "B" or "W" to the instruction
  784.         mnemonic.  Most, but not all, ambiguous memory
  785.         referances are flagged with this diagnostic. 
  786.        
  787.      Syntax Error: (OP) (DTYPE) (STYPE).  Chasm was
  788.         unable to find a version of the instruction (OP)
  789.         which allows the operand types (DTYPE) and (STYPE).
  790.         Either the instruction doesn't exist, or it is misspelled, 
  791.         or it is an inappropriate choice for the given operands.
  792.         DTYPE and STYPE are numbers which encode Chasm's
  793.         guess as to what the 1st and 2nd operands might be.
  794.         The numbers are sums of the types given in the following
  795.         list: 
  796.      
  797.           1 = 8 bit accumulator          2 = 16 bit accumulator
  798.           4 = 8 bit register             8 = 16 bit register
  799.          16 = a register or indirect    32 = CS register
  800.               memory referance
  801.          64 = other segment register   128 = memory location
  802.         256 = immediate byte           512 = immediate word
  803.        1024 = none                    2048 = string
  804.        4096 = near label              8192 = far label
  805.       16384 = CL (count) register
  806.  
  807.      Too Far For Short Jump: The displacement to the
  808.         specified label is not in the range -128 to +127.
  809.  
  810.      Too Many User Symbols in (linenum): Pass one error.
  811.         The symbol table is full.
  812.  
  813.      Undefined Operand for EQU: Any operands on an EQU
  814.         statement must have been previously defined.
  815.  
  816.      Undefined Symbol XXX: The symbol XXX was used as an
  817.         operand, but never appeared as a label, and is not a
  818.         predefined symbol.
  819.  
  820.      Unrecognized Operand XXX: XXX is used in the DB
  821.         operand list, but is not a string or byte value.
  822.  
  823.      XI. Execution of Assembled Programs
  824.      
  825.      A. Object code format
  826.      
  827.      The object code file produced by CHASM is in the form
  828.      of a memory image, exactly as will be present in your
  829.      computer at run time.  No link step is required.
  830.      Provided that the segment registers are set correctly,
  831.      the architecture of the 8088 guarantees that code is
  832.      self-relocating, and will run correctly loaded anywhere
  833.      in memory. Storing a program as an exact image of
  834.      memory at run time is called the COM format by IBM.
  835.  
  836.      This COM format is *not* that produced by the IBM
  837.      assembler.  The output of the IBM assembler is in the
  838.      form of an "object module" suitable for input to the
  839.      linker.  To the best of my knowlege, the object module
  840.      is not directly executable, but must first be "filtered"
  841.      through the linker.  This adds an extra step to the
  842.      process of producing a working program, but gives you
  843.      the option of combining multiple object modules into
  844.      one program.  The resulting linked program is *still*
  845.      not a memory image, but has a header which is used to
  846.      perform relocation during loading.  This linked program
  847.      plus header is called the EXE format by IBM.
  848.  
  849.      B. Running Assembled Programs From DOS
  850.  
  851.      DOS provides a loader for running machine language
  852.      programs.  To run a program, you merely type it's name,
  853.      with or without the extension.  This is what you're
  854.      doing every time you use a DOS external command such as
  855.      FORMAT or CHKDSK.  In fact, the COM format is named
  856.      after "external COMmand".
  857.  
  858.      When you type the name, DOS examines the file extension
  859.      to determine what format the file is in, either COM or
  860.      EXE.  This is why CHASM defaults to using the extension
  861.      .com for your object file.  If you plan to run the
  862.      program from DOS, don't change the extension.
  863.  
  864.      For COM programs, DOS builds a 255 byte long "program
  865.      segment prefix" and sets the segment registers to point
  866.      to this PSP.  The contents of the file are then loaded
  867.      verbatim right after the PSP, at offset hex 100 in the
  868.      segment defined by the segment registers.  As soon as
  869.      loading is complete, your program is executed starting
  870.      with the instruction at hex 100.  Although you can
  871.      totally ignore the PSP, you should read pages E-3
  872.      through E-11 of the DOS manual to see what DOS puts
  873.      there for you.  It turns out there are some real goodies
  874.      which your program might want to use.
  875.  
  876.      When your program is done, it must transfer control
  877.      back to DOS, otherwise the 8088 will continue to fetch
  878.      what it believes are instructions from whatever garbage
  879.      or bit-hash happens to follow your program in memory.
  880.      The easiest way to return to DOS is to execute the
  881.      instruction:
  882.  
  883.      INT 20H
  884.  
  885.      This is the vectored interrupt reserved by DOS for
  886.      program termination.
  887.  
  888.      While we're on the topic of vectored interrupts, you
  889.      would be well rewarded to study both the DOS manual and
  890.      Technical Referance to find out what happens when you
  891.      execute some of the other interrupts.  Some very useful
  892.      functions, such as file handling and screen i/o, are
  893.      available at the machine language level through this
  894.      mechanism.
  895.  
  896.      By changing the interrupt vector for a given function
  897.      to point to your own code, you can overide the way DOS
  898.      or the BIOS does something, and do it your way.  This
  899.      document was produced from Easywriter directly, in
  900.      standard DOS format, by printing it to disk.  It was
  901.      not necessary to manually add an end of paragraph
  902.      marker at the end of each line, and I didn't need to
  903.      run it through the program TRANSFER which IBM provides.
  904.      I had changed the vector for printer support to point
  905.      to some code which sent the output to disk.  Easywriter
  906.      thought it was using the printer, and formatted
  907.      everything nicely.
  908.  
  909.      C. Debugging Assembled Programs
  910.  
  911.      IBM provides an excellent utility with DOS, called
  912.      DEBUG.COM.  By specifying your program's name as a
  913.      parameter when invoking DEBUG, you can observe your
  914.      program execute with DEBUG's trace and other functions.
  915.      To debug your program from DOS, type:
  916.  
  917.      DEBUG progname.COM
  918.  
  919.      DEBUG builds a PSP and loads your program just like DOS
  920.      does, but you have the added power of the debugging
  921.      commands to monitor your program while it runs.  See
  922.      chapter 6 of the DOS manual for more details about
  923.      using DEBUG.
  924.  
  925.      D. Using Assembled Programs in BASIC
  926.  
  927.      To incorporate a machine language subroutine in a BASIC
  928.      program, write it in assembly language, then assemble
  929.      it with CHASM.  You should read page C-7 of the BASIC
  930.      manual for some conventions to use in writing your
  931.      subroutine.  In particular, note that you must declare
  932.      the routine to CHASM as a FAR procedure using the PROC
  933.      pseudo-op, and that the last instruction of the routine
  934.      should be a RET.
  935.  
  936.      For short routines, probably the easiest way to get the
  937.      code into a BASIC program is to just hand copy the
  938.      object code from the listing into a DATA statement. The
  939.      BASIC program can then READ the data and POKE it into
  940.      memory.  An example program to do this is given on page
  941.      C-6 of the BASIC manual.  An alternative approach would
  942.      be to store the routine in a string variable, which
  943.      could later be located with the VARPTR function.
  944.  
  945.      You transfer control to your routine with either the
  946.      USR  function, or the CALL statement.  Syntax for these
  947.      statements can be found in the BASIC manual.
  948.  
  949.      XIII. Miscellaneous and A Word From Our Sponsor...
  950.  
  951.          There is a bewildering array of files on your disk.
  952.      As you've discovered by now, the file CHASM.DOC is
  953.      documentation, and need not be present for Chasm to
  954.      run.  Some of the others may need explanation, however.
  955.  
  956.          The actual program is in CHASM.BAS.  To run the
  957.      program, three other files *must* be present.  You must
  958.      copy BASIC.COM from your DOS disk to interpret the
  959.      program.  CHASM.DAT contains data about the various
  960.      instruction mnemonics Chasm recognizes, and must be
  961.      present.  The last file needed is CHASM.OVL.  OVL is an
  962.      empty file, which is merged to fool BASIC into
  963.      deleting some of the initialization code to make
  964.      more room for the symbol table.
  965.  
  966.         The file CHASM.BAT is a batch file to make it easier
  967.      to start Chasm from DOS.  With CHASM.BAT, you can just
  968.      type: chasm.  Without it you'd type: basic chasm/c:0.
  969.  
  970.          TCHASM.BAT is a batch file use to breed new CHASM
  971.      disks, if you want to give a copy to someone else.  It
  972.      copys the program, documentation, data; the whole
  973.      works.  Please only distribute the complete CHASM
  974.      system, as generated by this batch file.
  975. {!}  TCHASM.BAT is not related to TChasm.Pas that I'm distributing.
  976.  
  977.      Disclaimer:  CHASM is distributed as is, with no guarantee
  978.                   that it will work correctly in all situations.
  979.                   I cannot be responsable for any damages
  980.                   associated with its use.  Nonetheless, it
  981.                   is my intention to correct any genuine bugs
  982.                   which are brought to my attention.  Drop
  983.                   me a line if you think you've found a
  984.                   problem.
  985.  
  986. {!}  The same disclaimer goes for me.  I'm not able to guarantee that the
  987.      program will work properly.  It seems to work fine on my IBM PC.
  988.      The Turbo Editor Toolbox contains routines which write directly to
  989.      Video RAM, so if your computer isn't VERY compatible, you may have
  990.      difficulty running the program.
  991.  
  992.          I am joining the experiment started by the folks at
  993.      Freeware (tm), by distributing un-protected software,
  994.      and *encouraging* copying.  The catch, (of course
  995.      there's a catch) is that I request that all users who
  996.      think the program is worthwhile send a donation.  The
  997.      suggested donation is $20, but send what you think the
  998.      program is worth to *you*.  There is obviously no way I
  999.      can enforce payment, but I hope people will recognize
  1000.      the amount of work that went into writing and
  1001.      documenting Chasm, and will make a donation.  If the
  1002.      monetary response is great enough, I will release upgrades to
  1003.      this program (version 2.0 is already in the works) and
  1004.      other programs of comparible magnitude (future projects
  1005.      include a macro pre-processor to run in 64K for use with
  1006.      either CHASM or BASIC).  I hope folks find CHASM
  1007.      useful.
  1008.  
  1009.  
  1010.                     David Whitman
  1011.                     Department of Chemistry
  1012.                     Dartmouth College
  1013.                     Hanover, NH 03755
  1014.                     (603) 643-2115