home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug113.arc / ZASM.DOC < prev   
Text File  |  1979-12-31  |  30KB  |  960 lines

  1.          ZASM ASSEMBLER USER INFORMATION
  2.          -------------------------------
  3.  
  4. FOREWORD
  5. --------
  6. This documentation assumes that the reader has some familiarity with
  7. assembly language for the Z-80: it is not a primer.  The best Z-80
  8. assembly language book that I have found is Rodnay Zaks' "How to Program
  9. the Z-80".  Another excellent book to supplement it is "Z80 Assembly
  10. Language Subroutines" by Lance A. Leventhal and Winthrop Saville.
  11.  
  12. There are also occasional references herein to the standard CP/M
  13. assembler ASM.  For example the DL pseudo of ZASM is compared to the SET
  14. statement of ASM.  Many of the pseudo instructions are the same or
  15. similar in the two assemblers, although ZASM is far more powerful.
  16.  
  17. Finally two note on the examples in this file:
  18.  
  19. *    They have NOT all been tested and I do make mistakes.
  20.  
  21. *    They have been written in uppercase only to make them stand out. 
  22. There seems to be a covenant among assembler language programmers to
  23. do everything, except comments, in uppercase.  The fact is that, as with
  24. any other programming language, lowercase is easier to read and
  25. comprehend.  ZASM will accept either case.
  26.  
  27. GENERAL
  28. -------
  29. ZASM is a Macro Assembler for the Z-80 instruction set.  It recognizes
  30. Zilog Z-80 instruction mnemonics and produces either .HEX or .REL
  31. (Microsoft standard) output.  In short, it is a very powerful and very
  32. cheap (free) assembler.  Found on a CP/M bulletin board without
  33. documentation, these notes are based on a disassembly as well as
  34. experimentation.  There is no guarantee that they are entirely accurate
  35. or comprehensive.
  36.  
  37. Some features of note in ZASM are:
  38.  
  39. *  The assembler builds a symbol table in pass one.  In pass two the
  40. listing and code are generated.  Because of its two pass nature, forward
  41. references in EQU and DL statements are permitted although they may
  42. result in 'Error in Pass 1' messages.
  43.  
  44. *    Conditional assembly (IF/ELSE/ENDIF) nested to eight levels is
  45. permitted.
  46.  
  47. *    Macros including REPT, IRP and IRPC.  Nesting to eight levels is
  48. permitted.  Macro libraries are supported.
  49.  
  50. *    Include file nesting to four levels.  Files may be included on pass
  51. one only if desired.
  52.  
  53. *    Up to 15 named common blocks are allowed.
  54.  
  55. *    Library search directives are allowed.
  56.  
  57. *    Identifiers may include the special characters $ @ _ ? . which are
  58. regarded as significant.  Names must begin with a letter or special
  59. character and may contain digits thereafter.
  60.  
  61. *    Names are considered significant to eight characters  BUT only
  62. seven characters are written to a .REL file and hence passed to the
  63. linker.  Hence only seven characters can be trusted if you are linking
  64. several modules.  Furthermore, I am told that L80 (a Microsoft product
  65. only uses six characters so that identifiers differing only in the
  66. seventh character will look the same to it.
  67.  
  68.                   COMMAND LINE
  69.                   ------------
  70.  
  71. The source file name must have the .Z80 extension.  The command line is
  72. then of the form:
  73.  
  74.     ZASM PROG.sol ARG1 ARG2 ...
  75.  
  76. where the allowable arguments are given below and the letters 'sol' are:
  77.  
  78.     s - Source device.  This must be a disk drive in the range A-H.
  79.  
  80.     o - Output device.  This must be:
  81.  
  82.         Z    no output
  83.         A-H    disk for output (.REL or .HEX)
  84.  
  85.     l - List device.  This must be:
  86.  
  87.         X    console
  88.         Y    printer
  89.         Z    no listing
  90.         A-H    disk for .PRN file
  91.  
  92. An exception to the above rules is that if any of 'sol' are blank, the
  93. default disk drive is assumed.  Hence:
  94.  
  95.     B>A:ZASM PROG        =    A:ZASM.BBB
  96.     B>A:ZASM PROG.A        =    A:ZASM.ABB
  97.     B>A:ZASM PROG.BZ    =    A:ZASM.BZB
  98.  
  99.              Command Line Arguments
  100.              ----------------------
  101.  
  102. RANGE        Mark instances where JR could be used
  103. PARITY        Mark all PE/PO/V/NV conditions (POTENTIAL 8080/Z80 conflict)
  104. XREF        Produce a symbol cross reference in listing
  105. NOXREF        Don't
  106. SYMB        Print a symbol table
  107. PAGE  = decno    Set page size for listing
  108. TOP   = decno    Set top of form margin
  109. WIDTH = decno    Set page width
  110. TRUNC = decno    Set page width and truncate
  111. MACRO =    name    Specify a macro library to load
  112. COND        List conditionals
  113. NOCOND        Don't
  114. GEN        List macro generated code
  115. NOGEN        Don't
  116. TEXT        Show all bytes generated by instruction
  117. NOTEXT        Show at most four bytes per instruction
  118. LISTON        List source code
  119. LISTOFF        Don't
  120. OPCODE        Produce an opcode cross reference in listing
  121. DEBUG        Does nothing but set an unused bit
  122. HEX        Produce HEX output rather than REL
  123. HEX   =    hexno    Hex load address (sets HEX also)
  124. DATE  =    mmddyy    Set date for listing
  125. TIME  =    hhmmss    Set time for listing
  126.  
  127.               Instruction Formats
  128.               -------------------
  129.  
  130. The assembler differentiates between the label and the opcode fields by
  131. assuming that the instruction is of one of the following forms:
  132.  
  133. LABEL:    OPCODE    PARAMS        ;COMMENT
  134. LABEL    OPCODE    PARAMS        ;COMMENT
  135.     OPCODE    PARAMS        ;COMMENT
  136.     LABEL:    OPCODE    PARAMS    ;COMMENT
  137.  
  138. The thing to note is that an identifier that begins in the first column
  139. is assumed to be a label even though it may lack a colon.  Hence opcodes,
  140. whether instructions or pseudo-instructions, should be tabbed over at
  141. least one.  For example, the statements:
  142.  
  143. TITLE    Test Program
  144.     CR    EQU    13
  145.  
  146. will be flagged as errors.  They should have been written:
  147.  
  148.     TITLE    Test Program
  149. CR    EQU    13
  150.  
  151.              Assembler Pseudo Instructions
  152.              -----------------------------
  153.  
  154. The following pseudo instructions require no special prefix characters
  155. as in some assemblers.  There are four pseudo instructions, discussed
  156. later, that do require a special asterisk prefix.
  157.  
  158. In determining how to interpret the contents of the opcode field, ZASM
  159. searches in the following order:
  160.  
  161.     - macro (hence macros may replace builtin opcodes)
  162.     - builtin opcodes
  163.  
  164. Most of these pseudos may not have a label - those that can are shown
  165. explicitly.
  166.  
  167.     ABS            Absolute program segment
  168.     COM    name        Common block
  169.     CONMSG    text        Displayed during pass 2 of assembly
  170.     DATA            Data segment
  171. [lbl]    DB    bytes        Define bytes
  172. [lbl]    DEFB    bytes        Same
  173. lbl    DL    value        Define label - same as SET in ASM
  174. lbl    DEFL    value        Same
  175. [lbl]    DM    bytes        Same as DEFB but sets bit 7 of last byte high
  176. [lbl]    DEFM    bytes        Same
  177. [lbl]    DS    size        Reserves size bytes of storage
  178. [lbl]    DEFS    size        Same
  179. [lbl]    DW    words        Define words (16 bit)
  180. [lbl]    DEFW    words        Same
  181.     EJECT            Page eject on listing
  182.     ELSE            Used with IF and ENDIF
  183. [lbl]    END    [lbl]        End statement (optional entry point)
  184.     ENDIF            Used with IF ELSE
  185.     ENDM            End of macro (includes REPT IRP IRPC)
  186.     ENTRY    labels        Entry label - same as PUBLIC in RMAC
  187. lbl    EQU    value        Equates label to fixed value (DL for variable)
  188.     EXITM            Exit from macro before ENDM statement
  189.     EXT    labels        Same as EXTRN
  190.     EXTRN    labels        External labels
  191.     FORM            Page eject (same as EJECT)
  192.     GLOBAL    labels        Either EXTRN or ENTRY - assembler will decide
  193.     IF    expr        Used with ELSE ENDIF
  194.     IRP    #a,b,c,        Indefinite repeat
  195.     IRPC    #a,'abc'    Indefinite repeat by character
  196. [lbl]    JSYS    value        Strange - RST 1 followed by byte value
  197.     LIST    params        Introduces list options
  198. macnam    MACRO    #a,#b,...    Macro definition
  199.     MEND            Macro end (same as ENDM)
  200.     MEXIT            Macro exit (same as EXITM)
  201.     NAME    name        Name module - else same as name of source file
  202. macnam    OMACRO    #a,#b,...    Like MACRO but name shows up in opcode listing
  203.     ORG    value        Origin - set program counter instruction
  204.     REL            Relocatable code segment
  205.     REM    text        Remarks statement (semicolon just as good)
  206.     REPT    value        Repeat statements
  207.     STRUCT    value        Define data structure
  208.     SUBTTL            Subtitle for listing
  209.     TITLE            Title for listing
  210.     TITLE2            Same as SUBTTL
  211.  
  212.              Standard Z-80 Mnemonics
  213.              -----------------------
  214.  
  215. The following are the Zilog mnemonics for the Z-80.  The reader is
  216. referred to Rodnay Zaks' "How to Program the Z-80" for their syntax. 
  217.  
  218. One special note is that index register offsets are calculated to 16
  219. bits before testing to ensure that they are in the range (-128 to +127). 
  220. Hence:
  221.  
  222.     LD    A,(IX + 0FFH)        is illegal
  223.  
  224.     LD    A,(IX + 0FFFFH)        is legal, as is
  225.     LD    A,(IX - 1)
  226.  
  227. Another note is that conditional jumps and calls have a somewhat
  228. expanded syntax, illustrated below.
  229.  
  230.     JP    C,    =    JP    LT,
  231.     JP    NC,    =    JP    GE,
  232.     JP    Z,    =    JP    EQ,
  233.     JP    NZ,    =    JP    NE,
  234.     JP    PE,    =    JP    V,
  235.     JP    PO,    =    JP    NV,
  236.     JP    M,    =    no other
  237.     JP    P,    =    no other
  238.  
  239. For example:
  240.  
  241.     LD    A,SAM
  242.     CP    20
  243.     JP    GE,DEST
  244.     
  245. means jump if SAM GE 20 - i.e. if A >= 20.
  246.  
  247.  
  248. ADC    ADD    AND    BIT    CALL    CCF    CP    CPD
  249. CPDR    CPI    CPIR    CPL    DAA    DEC    DI    DJNZ
  250. EI    EX    EXX    HALT    IM    IM0    IM1    IM2
  251. IN    INC    IND    INDR    INI    INIR    JP    JR
  252. LD    LDD    LDDR    LDI    LDIR    NEG    NOP    OR
  253. OTDR    OTIR    OUT    OUTD    OUTI    POP    PUSH    RES
  254. RET    RETI    RETN    RL    RLA    RLC    RLCA    RLD
  255. RR    RRA    RRC    RRCA    RRD    RST    SBC    SCF
  256. SET    SLA    SRA    SRL    SUB    XOR
  257.  
  258.                Expressions
  259.                -----------
  260.  
  261. Expressions are evaluated to 16 bits and may use the following operators
  262. as well as parentheses or brackets - i.e. () or [].  Mnemonics that
  263. require parentheses such as LD A,(HL) or ADD A,(IX+3) may not use the []
  264. form.
  265.  
  266. The priorities shown below are such that lower numbers connote higher
  267. priorities.  For equal priorities evaluation is left to right.
  268.  
  269. Unary operators
  270. ---------------
  271.  
  272.     OP    PRI    COMMENTS
  273.  
  274.     +    1    unary plus
  275.     -    1    unary minus
  276.     ^    1    2 ^ power (i.e. ^11 is a 16 bit word with bit 11 set)
  277.     ~    4    not (ones complement)
  278.     NOT    4    not (ones complement)
  279.     LOW    8    low  byte (high byte set to zero)
  280.     HIGH    8    high byte (swap bytes and set new high byte to zero)
  281.  
  282.         Binary operators
  283.  
  284.     +    3    add
  285.     -    3    subtract
  286.     *    2    multiply
  287.     /    2    divide
  288.     %    2    modulus (e.g. 13 % 5 = 3,  15 % 5 = 0)
  289.     &    5    and (bitwise)
  290.     |    6    or  (bitwise)
  291.     >>    2    shift right (e.g. 80h >> 2 = 20h)
  292.     <<    2    shift left  (e.g.  7h << 8 = 700h)
  293.     >=    7    ge
  294.     <=    7    le
  295.     <>    7    not equal
  296.     >    7    gt
  297.     <    7    lt
  298.     =    7    equal
  299.     MOD    2    mod        - same as %
  300.     SHL    2    shift left    - same as >>
  301.     SHR    2    shift right    - same as <<
  302.     AND    5    and        - same as &
  303.     OR    6    or        - same as |
  304.     XOR    6    exclusive or    - exclusive or (bitwise)
  305.     LT    7    lt        - same as <
  306.     GT    7    gt        - same as >
  307.     EQ    7    equal        - same as =
  308.     NE    7    not equal    - same as <>
  309.     LE    7    le        - same as <=
  310.     GE    7    ge        - same as >=
  311.  
  312. Expressions may use the $ symbol to refer to the value of the program
  313. counter.  In such usage, $ = the PC at the beginning of the line in
  314. question.  For example:
  315.  
  316.     START    DL    $
  317.         DS    'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  318.     NCHRS    DL    $ - START    ;number of characters
  319.  
  320. Furthermore, relational operators may be used with character strings
  321. contained in double quotes.  E.g.
  322.  
  323.     IF "SAM" < "GEORGE"
  324.  
  325. is meaningful (and false).
  326.  
  327. The mixing of types - e.g. absolute, relocatable, external etc in
  328. expressions is usually expressed in a number of complicated rules.  A
  329. little common sense will normally suffice to see what will work.  For
  330. example, the difference of two internal relocatable references is OK
  331. and will produce an absolute quantity (example - NCHRS above) since
  332. they will be given the same offset at link time.  The sum of two such
  333. quantities is a no-no as is multiplication or division involving
  334. non-absolute quantities.
  335.  
  336.              Listing Options
  337.              ---------------
  338.  
  339. These can be embedded in the source file in the form:
  340.  
  341.         LIST    NOGEN,NOCOND,TEXT
  342.  
  343. When so embedded, they are overridden by contrary listing options contained in the command line.
  344.  
  345.     GEN    NOGEN        Macro generated code
  346.     ON    OFF        Source code
  347.     COND    NOCOND        Conditionals (IF/ELSE/ENDIF)
  348.     TEXT    NOTEXT        Complete byte listing
  349.                 (else max 4 per instruction)
  350.  
  351.           Detailed Discussion of Instruction Mnemonics
  352.           --------------------------------------------
  353.  
  354. ABS    This specifies that the following code or data is to be placed
  355.     into the absolute program section. The syntax is simply:
  356.  
  357.         ABS
  358.  
  359. COM    This specifies that the following code or data is to be placed
  360.     into the common section of the given name.  Presumably, common
  361.     blocks of the same name declared in different modules will be
  362.     assigned the same start address by the linker.  The syntax is:
  363.  
  364.         COM    BLKNAME
  365.  
  366.     where BLKNAME is a legal identifier of at most seven characters.
  367.  
  368. CONMSG
  369. ------
  370. This is used to generate a message to the console during the second pass
  371. of the assembler.  It does not generate any code and can hence not be
  372. used to generate run-time messages.  For example:
  373.  
  374.     CPM    EQU    1
  375.     ...
  376.     IF    CPM = 1
  377.     CONMSG    Assembly is for CP/M
  378.     ELSE
  379.     CONMSG    Assembly is for non-CP/M system
  380.     ENDIF
  381.     ...
  382.  
  383. DATA
  384. ----
  385. This specifies that the following data is to be placed in the DATA area
  386. by the linker.  It is normally used to separate dynamic data from
  387. program code.  Such is essential when generating code to run in ROM.
  388. The syntax is simply:
  389.  
  390.     DATA
  391.  
  392. DB and DEFB
  393. -----------
  394. These are synonyms used to initialize data to given byte values.  Note
  395. that if the initial value is meaningless, the DS statement is more
  396. appropriate, simply defining the number of bytes to be reserved.
  397. Examples are:
  398.  
  399.     DB    'THIS IS A STRING WITH A NULL BYTE',0
  400.     DB    1,2,3,'SAM',4FH
  401.  
  402. DL and DEFL
  403. -----------
  404. This is like the SET statement in ASM.  In several cases the writer of
  405. ZASM seems to have been relieving himself in a windward direction in his
  406. choice of names.  It is used when the same symbol must be assigned more
  407. than one value at assembly time.  This is of the greatest importance in
  408. writing macros but is useful elsewhere also. For example:
  409.  
  410. BASE    DL    0
  411.     IF    NOT STANDARD
  412. BASE    DL    4100H
  413.     ENDIF
  414.  
  415. Of course in this case, an IF..ELSE..ENDIF construct would have allowed
  416. the use of EQU rather than DL.
  417.  
  418. In writing macros it is often necessary to have the value of a label
  419. vary.  Two examples follow:
  420.  
  421. COUNT?    MACRO    #STRING
  422. N?    DL    0
  423.     IRPC    #Z,#STRING
  424.         IF    '#Z' = '?'
  425. N?        DL    N? + 1
  426.         ENDIF
  427.     ENDM
  428.     ENDM
  429.  
  430. invoked as, say:
  431.  
  432.     COUNT?    'A?BB???C'
  433.     IF    N?
  434.     CONMSG    Found some queries.
  435.     ENDIF
  436.  
  437. would set N? to the number of ? characters in the argument string.  In
  438. the macro expansion, N? occurs L + 1 times as a label where L is the
  439. length of the string.  Futhermore, COUNT? may be invoked at more than
  440. one place.  The example seems trivial because anyone can see that there
  441. are several ?'s in the string.  The string might itself, however, be a
  442. macro parameter which sometimes contains queries and sometimes does not.
  443.  
  444.  
  445. A final example is shown below.  The LENGTH macro sets the symbol LEN to
  446. the length of the parameter.  For example, after the statement:
  447.  
  448.     LENGTH    ABCDEFGHIJKLMNOPQRSTUVWXYZ
  449.  
  450. the symbol LEN will have the value 26.  This macro, like the last,
  451. generates no code - it simply sets a value which may then be used in
  452. expressions in the following code.
  453.  
  454. LENGTH    MACRO    #NAME            ;length of a string
  455. LEN    DL    0            ;initialize to zero
  456.     IRPC    #Z,'#NAME'        ;for each character in string
  457. LEN    DL    LEN + 1            ;...bump len
  458.     ENDM                ;end of irpc
  459.     ENDM                ;end of macro
  460.  
  461.  
  462. DM and DEFM
  463. -----------
  464. This is just like DB except that the last byte specified, in a line, has
  465. bit 7 set to 1.  The chief usage of this is providing character strings
  466. for use by routines that detect 'end of string' by checking bit 7 rather
  467. than using the more traditional method of following strings by null
  468. bytes.  For example, using DM we can write:
  469.  
  470.     DM    'THE LAST BYTE HAS BIT 7 HIGH'
  471.  
  472.         rather than
  473.  
  474.     DB    'THE LAST BYTE HAS BIT 7 HIG','H'+80H
  475.  
  476. This method of indicating the end of character strings was extensively
  477. used by the writer of ZASM.  It is also used in a number of text editors
  478. - for example, in its swap file Perfect Writer sets bit 7 on line feed
  479. characters.  Wordstar does a lot with bit 7, even on the end of words.
  480.  
  481. DEFS and DS
  482. -----------
  483. These are used to specify only the amount of storage needed without
  484. providing initial values.  It would be meaningless, for example, to
  485. initialize the contents of a disk input buffer.  Areas specified by the
  486. DS statement may or may not be included in the .COM file by the linker.
  487. The syntax is as below:
  488.  
  489.     SAM:    DS    128
  490.  
  491. This assigns the label SAM to the start of a block of 128 bytes.  No
  492. assumptions may be made about the initial value of locations specified
  493. by a DS directive.  Some linkers will initialize such areas to zero and
  494. other linkers will simply leave garbage in them.  Indeed such areas will
  495. not necessarily even be included in the final .COM file.
  496.  
  497. In this assembler, DS seems to have another function which will be
  498. discussed later under STRUCT.
  499.  
  500. DEFW and DW
  501. -----------
  502. This is used to reserve and initialize one or more words (16-bit) of
  503. storage.  The syntax is:
  504.  
  505.     DW    32,SAM,'AB'
  506.  
  507. Note that this initializes the second word to contain a pointer to label
  508. SAM.
  509.  
  510. EJECT and FORM
  511. --------------
  512. These both cause a page eject on the listing.
  513.  
  514. IF/ELSE/ENDIF
  515. -------------
  516. These are used in conditional constructs which may be nested to a depth
  517. of eight.  It is used to control which portions of the program will
  518. actually be assembled.  A typical use might be:
  519.  
  520. KAYPRO    EQU    1    ;set your computer to 1, the rest to zero
  521. OSBORNE    EQU    0
  522. IBM    EQU    0
  523.  
  524. WORTH:    IF    KAYPRO
  525.         CONMSG    This is for a Kaypro - Hurrah !
  526.     ELSE
  527.         IF    OSBORNE
  528.             CONMSG    This for an Osborne - Why ?
  529.         ELSE
  530.             IF    IBM
  531.                     CONMSG    This is for an IBM - What's that ?
  532.             ELSE
  533.                 CONMSG    Improper Computer Definition !
  534.             ENDIF
  535.         ENDIF
  536.     ENDIF
  537.  
  538. Note that all of that code will only generate one byte of code - in fact
  539. none at all if the CONMSG portion is reached.  Note also that the
  540. indents are not necessary - indeed they seem to be uncommon in assembly
  541. programming. 
  542.  
  543. END
  544. ---
  545. This is used to mark the end of the source file, but ZASM is not very
  546. picky - if you leave it out it will be assumed.  Note that only one
  547. source module is permitted in a .Z80 source file.  You cannot stack a
  548. number of modules and separate them with END's.  The syntax is:
  549.  
  550.     END        or
  551.  
  552.     END    ZORK
  553.  
  554. where ZORK is a label at which you want execution to start.  The usage
  555. of this option in CP/M is unclear to me since the CCP always transfers
  556. control to the start of the TPA when a program is run.  In other systems
  557. - e.g. RT11 in PDP machines - the start address of a program is not
  558. necessarily its load address.
  559.  
  560. ENDM / MEND
  561. -----------
  562. These two statements are identical in function.  They are used to end
  563. the scope of a MACRO, OMACRO, REPT, IRP, IRPC or STRUCT block of code. 
  564. The syntax is simply:
  565.  
  566.     ENDM
  567.  
  568. ENTRY
  569. -----
  570. This is identical to the PUBLIC statement in RMAC.  It is used to inform
  571. the linker which labels in the module are to be made accessible to other
  572. modules.  See also the GLOBAL and EXTERNAL statements.  The syntax is:
  573.  
  574.     ENTRY    LABEL1,LABEL2,...
  575.  
  576. EQU
  577. ---
  578. This is like the DL statement except that once a label is equated to a
  579. value it can not be changed to another value with another EQU or DL.
  580. The EQU statement should be used for values that are truly constant in
  581. the module.  The syntax illustrated below:
  582.  
  583.     BDOS    EQU    5            or
  584.  
  585.     BUFLEN    EQU    BUFEND - BUFBEG        or
  586.  
  587.     BUFLEN    EQU    $ - BUFHED
  588.  
  589. Note that if the labels BUFEND or BUFBEG are defined below the EQU
  590. statement an 'Error in Pass 1' message will occur.  It will disappear in
  591. pass 2.
  592.  
  593. EXITM
  594. -----
  595. This is used to exit from a macro definition before the closing ENDM
  596. (which must still exist).  This can be used to simplify logical
  597. structures and perhaps speed processing.  For example:
  598.  
  599.     SPCLCH    MACRO    #CHAR
  600.         IRPC    #TEST,'._$?@'
  601.         IF    '#TEST' = '#CHAR'
  602.         CONMSG    Special character detected.
  603.         ENDIF
  604.         EXITM
  605.         ENDM
  606.  
  607. EXT / EXTRN
  608. -----------
  609. These synonyms are used to declare labels that are defined external to
  610. the current module.  They are used to tell the linker which labels must
  611. be found elsewhere and to ensure the assembler that a value will be
  612. provided for the label at link time.  This is the opposite of the ENTRY
  613. statement.  For each label shared between modules there should be one
  614. ENTRY statement, in the module defining it, and an EXTRN statement in
  615. each module referencing it.  The syntax is:
  616.  
  617.     EXTRN    LBL1,LBL2,...
  618.  
  619. See also the ENTRY and GLOBAL statements.
  620.  
  621. FORM
  622. ----
  623. Same as EJECT.
  624.  
  625. GLOBAL
  626. ------
  627. The GLOBAL statement is provided for sloppy programmers.  It can replace
  628. either the ENTRY or EXTRN declaration.  If a label is declared GLOBAL
  629. and the assembler detects it's definition in the current module, it is
  630. assumed to be an ENTRY (public) label.  If the assembler does not find
  631. it defined in the current module, it assumes the label to be of EXTRN
  632. type.  Using GLOBAL thus short-circuits any chance the assembler might
  633. have had of detecting a typo.  Furthermore it makes it very hard for the
  634. programmer to find where a shared label is defined: he has to scan the
  635. code of every module in which the label is declared GLOBAL.  If the
  636. ENTRY and EXTRN declarations are used instead, it is only necessary to
  637. scan the ENTRY statements to see which module contains the definition.
  638.  
  639. IRP
  640. ---
  641. This is a special predefined macro and hence takes up one nesting level
  642. and requires an ENDM statement.  The IRP stands for 'indefinite repeat'.
  643. The usage is illustrated below as is the ability to compare strings:
  644.  
  645. POPEM    MACRO    #R1,#R2,#R3,#R4,#R5,#R6
  646.     IRP    #REG,#R1,#R2,#R3,#R4,#R5,#R6
  647.     IF    "#REG" NE ""
  648.     PUSH    #REG
  649.     ELSE
  650.     EXITM
  651.     ENDIF
  652.     ENDM
  653.     ENDM
  654.  
  655. An invocation POPEM HL,BC,IX will expand to
  656.  
  657.     POP    HL
  658.     POP    BC
  659.     POP    IX
  660.  
  661. You may prefer the one liner, but remember to pop in reverse order to
  662. pushing. A second example follows:   
  663.  
  664.     IRP    #ADDR,BUF1,BUF2,BUF3,BUF4
  665. #ADDRP:    DW    #ADDR
  666.     DS    128
  667.     ENDM
  668.  
  669. This will be expanded into:
  670.  
  671. BUF1P:    DW    BUF1
  672. BUF1:    DS    128
  673. BUF2P:    DW    BUF2
  674. BUF2:    DS    128
  675. BUF3P:    DW    BUF3
  676. BUF3:    DS    128
  677. BUF4P:    DW    BUF4
  678. BUF4:    DS    128
  679.  
  680. The #ADDR above is a dummy parameter which will take on the macro
  681. equivalents BUF1, BUF2, etc once each.
  682.  
  683. This example also illustrates a very important consideration with
  684. respect to macro parameter matching.  The assembler matched the first
  685. characters of #ADDRP with the parameter #ADDR and assumed that the rest
  686. must be a literal character - i.e. one to be left as is.
  687.  
  688. IRPC
  689. ----
  690. This is very similar to IRP except that the dummy parameter takes on
  691. only on character on each repeat.  The syntax is illustrated below in
  692. which the example shown for IRP above is done by an IRPC instead:
  693.  
  694.     IRPC    #N,'1234'
  695. BUF#NP:    DW    BUF#N
  696. BUF#N:    DS    128
  697.     ENDM
  698.  
  699. The characters in the substitution string need not be digits.
  700.  
  701. JSYS
  702. ----
  703. This seems a bit strange.  I suspect it is a hold over from ZASM used
  704. with some other operating system.  It seems as if the syntax:
  705.  
  706.     JSYS    BYTVAL
  707.  
  708. generates the machine instructions:
  709.  
  710.     RST    1
  711.     DB    BYTVAL
  712.  
  713. This would be meaningful if location 0008H contained a jump to some code
  714. which would retrieve the BYTVAL, do something with it, and then return
  715. control to the address following BYTVAL (or maybe perform an error exit).
  716.  
  717. LIST
  718. ----
  719. This is used to switch listing options on and off at assembly time.  The
  720. listing options have been given above.  Note that listing options
  721. specified in the command line override those specified in the source
  722. code.  Hence you cannot 'hide' a piece of code - that is, prevent it
  723. from showing up in a listing.
  724.  
  725. MACRO
  726. -----
  727. The MACRO keyword is used to specify a macro - surprise.  Formal
  728. parameters in ZASM begin with a # symbol rather than the ? symbol used
  729. in RMAC.  Note that in ZASM, the query is a legal identifier character
  730. instead.  This is not a treatise on macros but a few examples below will
  731. demonstrate some simple uses.  The macro definition is given only once,
  732. and may even be hidden away in a file called a macro library.  It can
  733. then be invoked as often as desired with different actual parameters.
  734. Note that the 'values' of the parameters are the actual character
  735. strings themselves.  Note also that macros are assembly time phenomena -
  736. parameters can not depend on values generated at run time.
  737.  
  738. ;    This macro moves a 16-bit value from one address to
  739. ;    another without (seemingly) any effect on registers
  740.  
  741.     MOVE    MACRO    #SOURCE,#DESTN
  742.     PUSH    HL
  743.     LD    HL,(#SOURCE)
  744.     LD    (#DESTN),HL
  745.     POP    HL
  746.     ENDM
  747.  
  748. If invoked as MOVE  SAM,GEORGE  it would expand to:
  749.  
  750.         PUSH    HL
  751.         LD    HL,(SAM)
  752.         LD    (GEORGE),HL
  753.         POP    HL
  754.  
  755. Another example of a form frequently used is shown below.  It is used to
  756. invoke CP/M functions in a neat form.  As written, the first parameter
  757. is the CP/M function number, the second the contents of the DE register
  758. pair if required.  This example also demonstrates the use of the special
  759. symbol #SYM in macros.  #SYM expands to the number of parameters
  760. actually specified in the invocation.
  761.  
  762.     CPM    MACRO    #FN,#PARAM
  763.         PUSH    BC
  764.         PUSH    DE
  765.         LD    C,#FN
  766.         IF    #SYM > 1
  767.             LD    DE,#FN
  768.         ENDIF
  769.         CALL    5
  770.         POP    DE
  771.         POP    BC
  772.         ENDM
  773.  
  774. Then parts of the program code could be written as:
  775.  
  776.     CONIN    EQU    1
  777.     CONOUT    EQU    2
  778.     SETDMA    EQU    26
  779.  
  780.         ...
  781.  
  782.         CPM    CONOUT, '?'    ;display a ? on screen
  783.         CPM    CONIN        ;get a keyboard character
  784.         ...
  785.  
  786.         CPM    SETDMA,DISKBUF    ;set dma address to buffer
  787.  
  788. Of course, macros may not always be the most code-efficient way of doing
  789. things.  They get expanded fully at each invocation as opposed to a
  790. subroutine which exists only at one space.  If a macro expansion is long
  791. or referenced frequently, consider a subroutine.  On the other hand, for
  792. short macros the subroutine linkage (call/ret) may obviate any savings.
  793.  
  794. NAME
  795. ----
  796. This statement tells the librarian that the module name to be inserted
  797. into the .REL file is not the default one - that is, it is not the name
  798. of the .Z80 file which was assembled.  The syntax is:
  799.  
  800.     NAME    NEWNAME
  801.  
  802. OMACRO
  803. ------
  804. This is a puzzle.  It seems to behave just the same as the MACRO keyword
  805. with the exception that the macro name no longer shows up in a symbol
  806. cross reference listing - it does now show up in an opcode cross
  807. reference if such is requested.  Nevertheless there is still one piece
  808. of code that has not been fully explored and may show some other
  809. difference between these two.  Note that the same symbol may NOT be
  810. declared both as a MACRO and an OMACRO.  Also note that defining a
  811. built-in opcode (e.g. LD) as either a MACRO or an OMACRO will replace
  812. the built-in definition.
  813.  
  814. ORG
  815. ---
  816. This is used to force the assembler and linker to place program or data
  817. at specific memory locations.  Most .COM files begin at 100H but that is
  818. assumed anyways if no ORG statement is given.  The syntax is:
  819.  
  820.     ORG    value
  821.  
  822. REL
  823. ---
  824. This signals that the following is to be placed into the relocatable
  825. code program section.  The syntax is simply:
  826.  
  827.     REL
  828.  
  829. REM
  830. ---
  831. This seems to be the equivalent of a line beginning with a semicolon -
  832. i.e. pure comment.  Why it is included escapes me, unless some unweaned
  833. BASIC programmer insisted on it.
  834.  
  835. REPT
  836. ----
  837. The repeat statement is a predefined macro, taking one nest level and
  838. requiring an ENDM.  It repeats a block of statements a fixed number of
  839. times.  For example:
  840.  
  841.     ROTLEFT    MACRO    #REG,#TIMES
  842.         LD    A,#REG
  843.         REPT    #TIMES
  844.         RLCA
  845.         ENDM
  846.         LD    #REG,A
  847.         ENDM
  848.  
  849. Then the instruction:
  850.  
  851.         ROTLEFT    B,5
  852.  
  853. would expand into:
  854.  
  855.         LD    A,B
  856.         RLCA
  857.         RLCA
  858.         RLCA
  859.         RLCA
  860.         RLCA
  861.         LD    B,A
  862.  
  863. which is much more readable in the macro/repeat form above.
  864.  
  865.  
  866. STRUCT
  867. ------
  868. This is another rather strange thing but perhaps a rather nice one to.
  869. The structure block which this introduces generates no code whatsoever.
  870. Indeed any instruction that would generate code is disallowed.  Hence
  871. even DB, DW and DM instructions are illegal.  The purpose seems to be to
  872. define the structure of a block of code or data more neatly than in
  873. using ordinary artifices.  Some tentative examples of usage follow:
  874.  
  875.     STRUCT    0
  876. DRIVE:    DS    1
  877. NAME:    DS    8
  878. TYPE:    DS    3
  879. EXTENT:    DS    1
  880. S1:    DS    1
  881. S2:    DS    1
  882. RECCT:    DS    1
  883. BLOKS:    DS    16
  884. CURREC:    DS    1
  885. RANREC:    DS    2
  886. TOOBIG:    DS    1
  887.     ENDM
  888.  
  889. Then one can write, assuming that FCB is the address of a file control
  890. block:
  891.  
  892.     LD    A,(FCB+CURREC)
  893.  
  894. Of course we could have said just as well:
  895.  
  896. DRIVE    EQU    0
  897. NAME    EQU    DRIVE + 1
  898. TYPE    EQU    NAME  + 8
  899. ...
  900.  
  901. but the STRUCT is clearer.
  902.  
  903. SUBTTL / TITLE2
  904. ---------------
  905. This is the second title that will show up on pages of the listing.  The
  906. syntax is:
  907.  
  908.     SUBTTL    This is a subtitle.
  909.  
  910. TITLE
  911. -----
  912. This is the main title that will show up on each page of the listing.
  913. The syntax is as for SUBTTL.
  914.  
  915.                 Library Commands
  916.                 ----------------
  917.  
  918. There are four more special commands allowed, each beginning with an
  919. asterisk:
  920.  
  921.     *INCLUDE    filenam
  922.     *INCLUDE1    filenam
  923.     *MACLIB        filenam
  924.     *RELLIB        filenam
  925.  
  926. The asterisk must lie in column 1 of the source - no tabbing is
  927. permitted. There are no compulsory or default extensions for the
  928. filenames. The meaning of the commands is:
  929.  
  930. *INCLUDE
  931. --------
  932. Include the file named into the assembly at this point.  This file might
  933. typically contain constant definitions, entry and external declarations,
  934. some documentation detail, or simply more program code.  The include
  935. file will be read on both assembler passes.  INCLUDE's can be nested to
  936. four levels.
  937.  
  938. *INCLUDE1
  939. --------
  940. The same as INCLUDE except that it happens only on pass 1.  Since the
  941. listing is not generated until pass 2, INCLUDE1 should not be used for
  942. anything to be listed.  Also code is not generated until pass 2 so
  943. INCLUDE1 can not be used for source statements that generate code.
  944. Perhaps constant definitions, entry and external declarations, or macro
  945. definitions can be included only in pass 1.
  946.  
  947. *MACLIB
  948. -------
  949. This declares the named file to contain a number of macro definitions.
  950. I'm not sure just what happens but I think that the macro names only are
  951. loaded into memory together with their location on disk in case they are
  952. needed later.
  953.  
  954. *RELLIB
  955. -------
  956. This causes a special record to be sent to the .REL file instructing the
  957. linker to automatically search the named file to resolve external
  958. references.  This can save typing in the name of a standard library
  959. every time the link command is typed.  Any other advantage escapes me.
  960.