home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / asmutl / z80mr-a.lbr / Z80MR.DZC / Z80MR.DOC
Encoding:
Text File  |  1988-04-05  |  31.1 KB  |  758 lines

  1.  
  2.                         Documentation for Z80MR
  3.                          A Z80 Macro Assembler
  4.                   by
  5.                 Mike Rubenstein
  6.  
  7.  
  8. Introduction
  9. -------------
  10. Z80MR is a Z80 macro  assembler  with  syntax closely following RMAC and
  11. MAC.  Written by Mike Rubenstein (Hence the name  "Z80MR")  it assembles
  12. standard Zilog Z80 mnemonics into an Intel Hex format. (The accompanying
  13. Z1.COM assembles directly to a .COM file.) The resulting file (which has
  14. a .HEX extension) can be translated to a .COM file by use of LOAD.COM or
  15. the public  domain MLOAD.COM file if you used the conventional ORG 0100H
  16. with the source code.  If it ORG's  elsewhere, the .HEX file may be read
  17. into memory and manipulated with DDT.COM.
  18.  
  19.  
  20. Why Z80
  21. -------
  22. Virtually all CP/M computers placed on the market since 1981 use the Z80
  23. microprocessor.  The Z80 actually runs all  of the 8080 instructions but
  24. in addition there are more instructions unknown to the  8080.  The extra
  25. instructions were  designed for increased speed, easier programming, and
  26. more compact code.  For this reason it is to your best advantage to pro-
  27. gram in Z80 code for CP/M.
  28.  
  29.  
  30. Z80 Mnemonics
  31. -------------
  32. Z80 mnemonics are a great improvement over those used for the 8080. Some
  33. thought was given to logical,  universal  mnemonics that are much easier
  34. to remember and use.  I learned assembly language on  the  8080  and re-
  35. sisted the  change  to  Z80  at first.   After using Z80 mnemonics for a
  36. short time, I became very unwilling  to do anything with 8080 code.  Now
  37. I run almost every 8080 program that comes  in  through  a  8080  to Z80
  38. translating program  (XIZ.COM  by  Irv Hoff, another free, public domain
  39. program).  Even if you are writing programs for the 8080 it is still far
  40. easier to write in  Z80  mnemonics.  There  is a special listing command
  41. that flags Z80-only instructions for this very reason (described later).
  42.  
  43. Macros
  44. ------
  45. Macros are a way of  writing  subroutines  in assembly language and then
  46. calling the subroutine by entering the 'macro name' into the source. The
  47. macro may be called as many times as necessary anywhere  in  the proram.
  48. When the assembler is operated the lines of source code that make up the
  49. macro will  be inserted into the file by the assembler.  Note that using
  50. a macro does not reduce  the  size  of  the object code that is produced
  51. since all the lines of code that make up the macro definition are assem-
  52. bled into the object file at assembly time. This is called expanding the
  53. macro.  By using the "*MACLIST ON" option, the lines of code produced by
  54. the expansion of a macro are listed in the .PRN file.  Then the code can
  55. be examined and at times optimized in certain locations.
  56.  
  57.  
  58.                             Assembler Syntax
  59.                             ----------------
  60.  
  61. Components and General Form of Assembly Language Programs
  62. ---------------------------------------------------------
  63. The structure of an assembly  language  program  is more important to an
  64. assembler than the actual instructions you write.  A program  that would
  65. run beautifully  can  fail  to assemble if the syntax is not correct.  A
  66. program with no errors at  assembly  time  is not guaranteed to run cor-
  67. rectly (or as expected).  The assembler's report of 0 errors  means that
  68. it understood all of the instructions you entered, not that your program
  69. is logically correct.
  70.  
  71.  
  72. Fields
  73. ------
  74. Assemblers are almost always  field-oriented,  some  to a greater degree
  75. than others.  A field is a flexible position in the  line  of  code with
  76. respect to  the  right margin.  This assembler recognizes 4 fields in an
  77. assembly language source line.
  78.  
  79.  
  80. LABEL   INSTRUCTION     OPERAND         COMMENT
  81.   ^         ^              ^               ^
  82.   1         2              3               4
  83.  
  84. The assembler knows when it has reached  the end of a field when it sees
  85. a 'field delimiter'.  This can be a space or a tab  for  this assembler,
  86. though some  require semicolons.  It's immaterial whether you use spaces
  87. or tabs
  88.  
  89. Label Field
  90. -----------
  91. A symbol is a word used to represent a number. Symbols that refer to ad-
  92. dresses are called labels.  The assignment of a number to a label can be
  93. defined as the lines below:
  94.  
  95. TEN     EQU     10
  96. START   EQU     100H
  97.  
  98. or calculated by the assembler as an address for branching instructions.
  99.  
  100. START:  JP      FINISH
  101.         NOP
  102.         NOP
  103.  
  104. FINISH: JP      START
  105.  
  106. Also notice that the label is  optional  and is only for the programmers
  107. conveniance.
  108.  
  109. Labels must appear in the label field.  Some assemblers allow you to in-
  110. dent labels but this one won't.  It assumes anything in the first column
  111. is a label; if not in the first column then it's something else.
  112.  
  113.         START   EQU     100H
  114.  
  115. Will give you an error.  It assumes "START" is an instruction but is un-
  116. able to match that to a Z80 opcode.
  117.  
  118. The M80 (is the only) assembler that requires a colon after a label.  It
  119. is this distinction that  allows  such  labels to be indented.  No other
  120. assembler known to be available for either 8080 or Z80 source code needs
  121. such a colon.  Several 'format' program's (such as  FORM7  by  Irv Hoff)
  122. can optionally  place  colons after all labels where M80 expects to find
  123. them or remove any colons already present.  M80 is the only assembler to
  124. care, one way or the other.  Some people think it's easier to search for
  125. a label that has an accompanying colon.
  126.  
  127. This assembler only examines the  first  six  characters of any label or
  128. symbol so  that if the  following labels were used  in the same program:
  129.  
  130. FINISH1 EQU     1000H
  131. FINISH2 EQU     2000H
  132.  
  133. A 'D' error (duplicate symbols) would be generated.
  134.  
  135.  
  136. Operation and Operand Fields
  137. ----------------------------
  138. The operation field follows the label field and may either contain a Z80
  139. op code mnemonic, an assembler directive (or pseudo op) or a macro call.
  140. Assembler directives and macros are  described  later in this file. This
  141. field will usally contain the mnemonic for a Z80  instruction.  Some Z80
  142. instructions only  use  this field while others contain an operand which
  143. will be located in the operand field.
  144.  
  145. GOBACK: OR      A
  146.         RET     Z
  147.         LD      A,0FFH
  148.         RET
  149.  
  150. The way Z80 mnemonics were designed,  the number of nmenonics in the op-
  151. eration portion of instructions is kept to a minimum since  the operands
  152. really distinguish  the  differences  between similar instructions.  The
  153. first line above is a  good  example  of this.  The operation is an 'OR'
  154. operation on the number in the accumulator (implied) with another regis-
  155. ter.  It makes sense that the operand should be the  register containing
  156. the other  number  in the 'OR' operation.  In Z80 assembly language this
  157. is the case.  The first line  OR's the accumulator with the accumualator
  158. (used to see if the accumulator contains a 0).  Notice  that  the second
  159. line uses  the  operand field to contain the condition for a conditional
  160. jump (in this case the zero flag). The third line uses the operand field
  161. to contain both the target register  for  a load and the number to load.
  162. The last line is an unconditional return which  uses  the  same operator
  163. (RET) as  the  conditional return but does not use the operand field be-
  164. cause there are no conditons  to  place there.  This structure makes Z80
  165. programs much more readable than 8080 programs as well as making the in-
  166. structions easier to remember.  The following is the  same  code written
  167. with 8080  mnemonics.  Notice the different philosophy on the use of the
  168. fields.
  169.  
  170. GOBACK: ORA
  171.         RET     Z
  172.         MVI     A,0FFH
  173.         RET
  174.  
  175. Also the  LD  command in the  Z80  is used for all data moves while 8080
  176. users must remember a different mnemonic  for different types of  moves.
  177.  
  178.         8080                    Z80
  179.  
  180.         MOV     H,A             LD      H,A
  181.         MOV     M,A             LD      (HL),A
  182.         MVI     H,00            LD      H,00
  183.         LXI     H,0000          LD      HL,0000
  184.  
  185.  
  186. The Comment Field
  187. -----------------
  188. Comments are not limited to  the  comment  field and can actually be the
  189. entire line.  All assemblers recognize the semicolon as the beginning of
  190. a comment and then ignore the rest of the  line.  For  compatability be-
  191. tween assemblers  it is a good to begin comments with a semicolon.  This
  192. assembler only looks for a  semicolon  in the first column.  It needs no
  193. semicolon in the normal comment field.
  194. the following methods of inserting comments are good syntax.
  195.  
  196. 1. A semicolon in column one will cause the assembler to consider every-
  197.    thing following it to be considered a comment.
  198.  
  199. 2. The first blank  encountered  following  the beginning of the operand
  200.    field will cause the assembler to consider the rest of the line to be
  201.    considered a comment, thus a semicolon in the comment field is super-
  202.    fluous and its presence is ignored in any event.
  203.  
  204. ; An adventure in Comments, a short tale
  205.  
  206. START:  JP      FINISH          Finish this story
  207.         NOP                     ASM.COM, M80.COM, etc. would make errors
  208.                                 on these two lines
  209.  
  210. FINISH: RET                     That's all folks (Z80MR accepts this ok)
  211.  
  212.  
  213. NOTE:  If you are wondering how Z80MR  can determine where to locate the
  214.        comment field, it's really very simple - it counts spaces.  M80MR
  215.        would not like the following line, either:
  216.  
  217.                                 Equates start  in  the instruciton field
  218.  
  219.        Z80MR thinks this is identical to:
  220.  
  221.  Equates start in the instruciton field
  222. ^
  223. (column 1 is empty)
  224.  
  225.        since that in effect is  in  "the 2nd column.  Z80MR accepts this
  226.        next line as normal:
  227.  
  228.  JP START jump to the start of the program
  229. ^
  230. (column 1 is empty)
  231.  
  232.       since it does not begin in the first column, the next thing on the
  233.       line has to be an instruction.  If the characters do not match one
  234.       of the standard Z80 instructions, it will issue an error statement
  235.  
  236.                 Although Z80MR is very flexible in this regard,
  237.                 programs written in this manner for this assem-
  238.                 bler cannot be used by other people using their
  239.                 favorite commercial assembler.
  240.  
  241.                 This flexibility backfires completely with con-
  242.                 ditionals such as:
  243.  
  244.                         IF      NOT ZCPR3
  245.  
  246.                 since ZCPR3 is now considered to be a comment.
  247.                 There is an easy way around that, however, use
  248.                 this for such conditionals:
  249.  
  250.                         IF      NOT.ZCPR3
  251.  
  252. Numbers and Bases
  253. -----------------
  254. The assembler will accept numbers in HEX (base 16) BINARY (base 2) or in
  255. DECIMAL.  Hex numbers must end with  an  'H' and binary numbers must end
  256. with a 'B'.  Decimal numbers need no suffix letter, similar to other as-
  257. semblers with which you are familiar.that of. When  a  HEX  digit begins
  258. with a letter, the letter should be preceded with a 0.
  259.  
  260.         LD      A,0F3H
  261.         OR      01001000B
  262.         LD      HL,4000H+28
  263.  
  264.  
  265.                         Commanding the Assembler
  266.                         ------------------------
  267.  
  268. The primary responsibility of the  assembler  is to change Z80 mnemonics
  269. into object code.  The assembler also  recognizes  certain  commands and
  270. directives that  the  programmer  can  use to manipulate the assembler's
  271. output.  These are often  referred  to  as 'pseudo-ops'.  This assembler
  272. requires these pseudo-ops to be in upper case.  A  description  of these
  273. commands follows:
  274.  
  275. ORG     <expr>    Sets the origin of the  code or section of code.  This
  276.                   sets the reference number that the  assembler  uses to
  277.                   generate addresses  for  labels and instructions.  The
  278.                   <expr> can be a label or any specified value, such as:
  279.  
  280.                         ORG     0
  281.                         ORG     BASE
  282.  
  283. END     <symb>    Determines the end  of  an  assembly language program.
  284.                   <symb> if present describes the  first  executable in-
  285.                   struction of the program.
  286.  
  287. DW      wordlist
  288. DEFW    wordlist
  289.                   Both of  these  have  identical meanings.  In assembly
  290.                   language programs, 8 bit values are  called  bytes and
  291.                   16 bit  values are called words.  Addresses are assem-
  292.                   bled with the  most  significant  byte (MSB) following
  293.                   the least significant byte (LSB) because  this  is how
  294.                   the  microprocessor  handles  these  values.  This  DW
  295.                   pseudo-op allows  describing  these values in a normal
  296.                   manner (such as 01AF) with most-significant-byte first
  297.                   and still assemble correctly for the processor.
  298.  
  299.                         DW      8000H
  300.                  ;                       will assemble the same as
  301.                         DB      00H
  302.                         DB      80H
  303.  
  304.                   If more than one word  is  to follow a DW, use another
  305.                   line or a DB line to start with.  A label can  also be
  306.                   used:
  307.  
  308.                         START:  JP      FINISH
  309.                                 DW      HELLO
  310.  
  311. DDB     wordlist
  312.                   This pseudo-op is a  way  of  assembling 16 bit values
  313.                   with the MSB first (opposite of DW).
  314.  
  315.                         DDB     8000H
  316.                                         will assemble the same as
  317.                         DB      80H
  318.                         DB      00H
  319.  
  320. DB      bytelist
  321. DEFB    bytelist
  322. DEFM    bytelist
  323. DATA    bytelist
  324.                   These four  pseudo-ops  have  identical meanings.  The
  325.                   bytelist can be one byte or  multiple  bytes seperated
  326.                   with commas.  The  bytes  can  be  any mix of symbols,
  327.                   ASCII characters in  quotes,  or  numbers  on the same
  328.                   line.
  329.  
  330.                  ESC    EQU     1BH
  331.                  CLRSCR EQU     1AH
  332.                  CRLF   DDB     0D0AH
  333.                  ;
  334.                         ORG     100H
  335.                  ;
  336.                         LD      DE,MES
  337.                         LD      C,9     ; BDOS  "print  string" function
  338.                         CALL    5
  339.                         RET
  340.                  ;
  341.                  MES:   DB      CRLF,'*Your Message Here *',CRLF
  342.                         DB      '*Or Here*','$'
  343.                  ;
  344.                         END
  345.  
  346.                   If you've been waiting for an example to enter, assem-
  347.                   ble and run, try this one out. Just enter it, assemble
  348.                   and run it.
  349.  
  350.                   The program prints the message using the BDOS function
  351.                   9 (Print String).
  352.  
  353.                   Since the next bytes are just a carriage return then a
  354.                   line feed, the message with appear at the left side of
  355.                   the screen.
  356.  
  357. DS      n
  358. DEFS    n         Reserve data space ( n bytes ).  Used to position, al-
  359.                   locate or label data  storage space in a program.  'n'
  360.                   is number describing the number of bytes reserved.
  361.  
  362.                         DS      16
  363.  
  364.                   reserves 16 bytes.  The next instruction will be loca-
  365.                   ted 16 bytes from the location counter when the DS was
  366.                   16 bytes from the location counter when the DS was
  367.  
  368. label   EQU     <expr>
  369.                   The EQU sets the  label  equal to the expression.  The
  370.                   label should not be terminated with a colon  when used
  371.                   with an  EQU pseudo-op and need not be terminated with
  372.                   a colon in  any  event.  The  label  can be any symbol
  373.                   (byte or word) and the <expr> a number in  any  of the
  374.                   following forms:
  375.  
  376.                         SWEET   EQU     16          Decimal
  377.                         SWEET   EQU     10H         Hex
  378.                         SWEET   EQU     00010000B   Binary
  379.  
  380.                   With this assembler, the  EQU must be located anywhere
  381.                   after column one.  A label defined with an  EQU cannot
  382.                   be redefined later in the program.
  383.  
  384. label   DEFL    <expr>
  385.                   This assigns the value of the <expr> to the label like
  386.                   the EQU pseudo-op but a  label defined with a DEFL can
  387.                   be redefined later in the program.
  388.  
  389. *INCLUDE <filename>
  390.                   This pseudo-op causes the assembler to stop assembling
  391.                   lines in the file it  is  presently in and read in the
  392.                   file <filename>.  It then begins  assembling  lines in
  393.                   this included  file  until  it  reaches the end of the
  394.                   file after which it  returns  to the original file and
  395.                   resumes assembling lines in it, once more.  The <file-
  396.                   name> can  be any CP/M filename.ext, but if the extent
  397.                   is left off it  looks  for  the given filename with an
  398.                   extent of .LIB.  The asterisk must appear in  column 1
  399.                   with the  word  INCLUDE  immediately following with no
  400.                   embedded spaces.
  401.  
  402.                   *INCLUDE      DRIVER.AZM       will begin  assembly on
  403.                   ;                              the file DRIVER.AZM
  404.                   *INCLUDE      Z80MACRO         will begin  assembly on
  405.                   ;                              the  file  Z80MACRO.LIB
  406.  
  407.  
  408. Conditional Assembly Pseudo-Ops
  409. -------------------------------
  410.  
  411. IF      <expr>
  412. ELSE
  413. ENDIF
  414.         Conditional assembly is a way of  writing a single program so it
  415.         can be assembled different ways, or  with  different  options by
  416.         only changing  a  couple  of lines of codes.  When the assembler
  417.         encounters an IF pseudo-op,  it evaluates the symbol <expr>.  IF
  418.         <expr> is non-zero, it assembles the  following  lines  until it
  419.         reaches an  ELSE or an ENDIF.  If <expr> is 0, the lines are ig-
  420.         nored until the assembler encounters an ELSE or an ENDIF. If the
  421.         ERLSE is encountered, the  assembler begins assembling the lines
  422.         again.  The ENDIF pseudo-op causes the assembler  to  resume as-
  423.         sembling all lines.  You cannot have an IF without an ENDIF.
  424.  
  425.         Any of these pseudo-ops must appear after column one:
  426.  
  427. YES     EQU     0FFH
  428. NO      EQU     0
  429. KPRO2   EQU     YES
  430. KPRO10  EQU     NO
  431.  
  432.          IF     KPRO2
  433. BITPRT  EQU     1CH
  434.          ENDIF          KPRO2
  435. ;
  436.          IF     NOT.KPRO2
  437. BITPRT  EQU     14H
  438.          ENDIF          NOT.KPRO2
  439.  
  440.  
  441. Operators
  442. ---------
  443. Operators allow the programmer to  make  the assembler do arithmetic and
  444. logical operations.  They are normally used  to  manipulate  operands or
  445. generate symbols.  Some of them are used to create tests for conditional
  446. assembly.  There should be no embedded spaces when using these operators
  447. as the  first blank encountered terminates the operand field.  The oper-
  448. ands may be symbols or numbers  in any of the bases.  The operators sup-
  449. ported by this assembler are:
  450.  
  451. Arithmetic Operators
  452.  
  453.         +                 arithmetic addition.
  454.  
  455.         -                 arithmetic subtraction
  456.  
  457.         *                 arithmetic multiplication
  458.  
  459.         /                 arithmetic division  (truncating  the  result)
  460.  
  461. Logical Operators (Bit Manipulation)
  462.  
  463.         &
  464.         ( or .AND. )      logical AND operation
  465.  
  466.         ^
  467.         ( or .OR. )       logical OR operation
  468.  
  469.         .XOR.             logical exclusive OR operation
  470.  
  471.         \
  472.         ( or .NOT. )      logical inversion
  473.  
  474.         .SHR.             shift left operand  to  right by right operand
  475.  
  476.         .SHL.             shift left operand to  left  by  right operand
  477.  
  478.         .HIGH.            byte value  is  assigned  the  high  byte of a
  479.                           16 bit value
  480.  
  481.         .LOW.             byte value is assigned  the  low  byte of a 16
  482.                           bit value
  483.  
  484.  
  485. Conditional Assembly Operators ( return TRUE or FALSE to IF )
  486.  
  487.         =
  488.         ( or .EQU. )      logical equivalence
  489.  
  490.         >
  491.         ( or .GT. )       greater than
  492.         .UGT.             unsigned greater than
  493.  
  494.         <
  495.         ( or .LT. )       less than
  496.         .ULT.             unsigned less than
  497.  
  498.  
  499. Listing Options Pseudo-Ops
  500. --------------------------
  501. There are a number of listing options.  All of these options only effect
  502. the .PRN print file.  The options include  some for debugging as well as
  503. some for the actual format of the file on the page. The .PRN file is the
  504. basic tool assembly language programmers have for  examining  the output
  505. of the  assembler.  The pseudo-ops beginning with an asterisk must begin
  506. in the first column.
  507.  
  508. *EJECT
  509. ( or EJEC )       The next line  of  the listing should be placed at the
  510.                   top of the next page.
  511.  
  512. *HEADING          Place the text ( following  this  command ) on the top
  513.                   of each page.  Usually used to date the  listing file.
  514.  
  515. TITLE 'text'      Place  the  text in the quotation marks (either double
  516.                   or single on the top of each page in the listing file.
  517.  
  518. SPAC n            Leave n  blank  lines  in  the listing.  Used to leave
  519.                   white space in the file without  using  a  page break.
  520.  
  521. *LIST ON
  522. *LIST OFF         Turn the listing on  or  off.  This is usually used to
  523.                   omit long comments or certain sections  from  the .PRN
  524.                   file.
  525.  
  526. *MACLIST ON
  527. *MACLIST OFF      Turn the expansion of macros on or off. Seeing how the
  528.                   macros are being expanded is handy for optimizing code
  529.                   but can waste paper when that is no longer the area of
  530.                   interest.
  531.  
  532. LIST options
  533. NLIST options     These pseudo-ops allow turning on any of the supported
  534.                   listing file options on  (LIST) or off (NLIST) without
  535.                   changing the other options.  Both of  these pseudo-ops
  536.                   must be followed with one or more of the following op-
  537.                   tion letters.  If  these  pseudo-ops is used, some op-
  538.                   tions are on by default,  marked with (on) in the fol-
  539.                   lowing list.
  540.  
  541.                   A       List all bytes in DB, DW, DDB, etc.  Otherwise
  542.                           only the bytes that  can  fit  in one line are
  543.                           included in the listing (others  are implied).
  544.                   B       Place symbol table into object file.
  545.                   G       Place system generated symbols into object files
  546.                   I (on)  List  lines  of  conditional  code following a
  547.                           false conditional.  If off only  the  code ac-
  548.                           tually assembled is listed.
  549.                   M (on)  Expand macros in listing files
  550.                   O (on)  Produce an object module, show the bytes being
  551.                           being generated  by  the assembler.  Otherwise
  552.                           just the source and (optionally)  macro expan-
  553.                           sions.
  554.                   R       use absolute  displacement  for  JR  and  DJNZ
  555.                   S (on)  List source code in listing file
  556.                   T (on)  List symbol table in listing file
  557.                   X       Generate and list  cross references in listing
  558.                           file
  559.                   Z       Generate an error for Z80 only opcodes. Allows
  560.                           you to write in Z80 mnemonics for an 8080 pro-
  561.                           cessor.
  562.  
  563.  
  564.                             Error Reporting
  565.                             ---------------
  566.  
  567. When the assembler is unable  to  understand what you are instructing it
  568. to do, it generates an error message.  These are  almost  always  due to
  569. typo's or  bad  form.  It displays the error code below and the line the
  570. error was found on, to the console  and also displays the error codes in
  571. the listing file.
  572.  
  573.         D         Duplicate symbol definition.  You  will see this error
  574.                   message if you do any of the following:
  575.  
  576.                         Use the same symbol twice:
  577.  
  578.                                 FORMATX
  579.                                 FORMATC
  580.  
  581.                                 will generate an error (only 6
  582.                                 significant characters).
  583.  
  584.         U       Upper and lower case symbols with the same letters
  585.  
  586.                                 FORMAT:
  587.                                 format:
  588.  
  589.                                 are identical to the assembler.
  590.  
  591.                         Assigning a different value to a symbol that was
  592.                         previously defined with a EQU pseudo-op.  If you
  593.                         are going to reassign, use DEFL.
  594.  
  595.         E         Relocation error.  This occurs if the assembler cannot
  596.                   reassign an address as expected.
  597.  
  598.         F         Format Error.  Indicatesa problem  with  field user or
  599.                   macro format.
  600.  
  601.         K         Keyword error.  This means you tried to use one of the
  602.                   assembler's reserved words or  pseudo-ops as a symbol.
  603.  
  604.                         ORG     JP      END
  605.                                 NOP
  606.  
  607.                         END     JP      ORG
  608.  
  609.                         is in very bad taste.
  610.  
  611.         L         Label error.  The attempt to assign a value to a label
  612.                   was unsuccessful.  Also remember that labels don't end
  613.                   in a colon  when preceding  EQU.  This is  moot if you
  614.                   get in the habit of not addins colons after ANY label.
  615.  
  616.                         START:  EQU     100H    is bad news
  617.                         START   EQU     100H    is perfect
  618.  
  619.         M         Missing label.  The symbol you are using was never de-
  620.                   fined.
  621.  
  622.         N         Macro nesting error.  Macros can  be nested (that is a
  623.                   macro can call another macro) but if the  nesting gets
  624.                   too deep,  the assembler will quit and give you one of
  625.                   these errors.  You can only call macros that were pre-
  626.                   viously defined.
  627.  
  628.         O         Op code error.  If you see  this, look in the instruc-
  629.                   tion and operand fields.  Consult the  mnemonic table.
  630.                   People switching  over from 8080 will likely see a few
  631.                   of these.
  632.  
  633.         P         Phase error.  A 2-pass assembler builds a symbol table
  634.                   on the first pass and generates the object code on the
  635.                   second.  If a number that  it  calculates for a symbol
  636.                   on the first pass does not agree with a number it gen-
  637.                   erates in the second pass, this error is shown.  Check
  638.                   the symbols in the line whee the error appeared.
  639.  
  640.         Q         Questionable operand.  Actually  there's  no  question
  641.                   about it,  it is a bad operand . Typo's give you these
  642.                   as well as  blowing  op  code format.  Usually easy to
  643.                   find your mistake.
  644.  
  645.         S         Syntax error.  You broke one  of  the syntax rules de-
  646.                   scribed above.
  647.  
  648.         T         Symbol table full.  Not much you  can do with this ex-
  649.                   cept pare down the code.
  650.  
  651.         U         Undefined symbol.  You used a  symbol but perhaps for-
  652.                   got to define it in with an EQU.
  653.  
  654.         V         Value error.  Usually means you are trying to do a 16-
  655.                   bit operation with an  8-bit  number, or the other way
  656.                   around.
  657.  
  658.  
  659.                                  Macros
  660.                                  ------
  661.  
  662. The macro is a  powerful  method  of writing assembly language programs.
  663. It makes it possible to write assembly language programs in  a  way that
  664. resembles higher  level  languages.  In  fact  by  creating a library of
  665. macros you are in essence creating  your own language, and your own com-
  666. piler.
  667.  
  668. Often times in assembly  language  (particularly  writing for CP/M) each
  669. program contains source lines that are used  again  and  again  in other
  670. programs.  By using macros the routines only need to be written once and
  671. then may be called in any program.  The best thing about a macro library
  672. is that  only  the macros that are called produce object code.  So there
  673. is no penalty in having a macro  library that is large and complete even
  674. if you are only going to call one macro.
  675.  
  676. Macros have a form that is unique  and must be followed closely for cor-
  677. rect results.  The general form of a macro is
  678.  
  679. name    MACRO   #parameter1,#parameter2,....
  680.         instruction
  681.         instruction
  682.         instruction
  683.         .
  684.         .
  685.         .
  686.         ENDM
  687.  
  688. The name is the symbol that will  be used to invoke the macro.  MACRO is
  689. a keyword that will indicate to the assembler that a macro is  being de-
  690. fined.  The parameters  always  must begin with a '#' sign in macros and
  691. they are seperated by commas.  The  instruction can be Z80 instructions,
  692. or any of the assembler  commands  listed  above  incuding conditionals.
  693. The instruction  can  also  be another macro call (called nested macros)
  694. but only if the nested macro has been already defined.  The ENDM keyword
  695. tells the assembler that it has reached the end of the code that must be
  696. assembled when this macro is called. Do not use a colon behind the macro
  697. name.
  698.  
  699. The previous message program example can  be rewritten to look like this
  700. with macros.
  701.  
  702.           ORG   100H
  703.  
  704. *INCLUDE Z80MACRO
  705.  
  706.         BDOS    PRNSTR,MES
  707.         RET
  708.  
  709. MES:    DEFB    '*Your message here*'
  710.         DDB     CRLF
  711.         DEFB    '*Or here*'
  712.         END
  713.  
  714. With the following macro library called Z80MACRO.LIB
  715.  
  716.  
  717.   Call Bdos function #FUNCT using paramater contained in #DE
  718.  
  719. ESC     EQU     1BH             ASCII escape
  720. CRLF    EQU     0D0AH           ASCII   carriage return line feed
  721. PRNSTR  EQU     9
  722.  
  723. BDOS    MACRO   #FUNCT,#DE
  724.         LD      C,#FUNCT        Function number goes to C
  725.         LD      DE,#DE          Get parameter
  726.         CALL    5               Call BDOS
  727.         ENDM
  728.  
  729. We could also  rewrite  the  cursor  positioning  sequence into a macro.
  730. Note how just this small example can save us  time  in  future programs.
  731. Also, the macro library is a great place to keep frequently used symbols
  732. like ESC and CRLF.
  733.  
  734. But what about using address symbols in macros? How can we avoid the 'D'
  735. error if we call the macro  more than once.  The other keyword unique to
  736. macros is LOCAL.  This makes the assembler generate its own unique label
  737. every time the macro is expanded in a program.  Following the word LOCAL
  738. (which must be on the second line of the macro) are the symbols  we want
  739. the compiler  to generate unique labels for.  These symbols must also be
  740. preceeded with a '#' sign.
  741.  
  742. AJUMP    MACRO
  743.         LOCAL   #ADRZ,#BACK
  744.         OR      A
  745.         JR      Z,#ADRZ
  746.         LD      A,40H
  747.         JR      #BACK
  748.  
  749. #ADRZ:  LD      A,04H
  750.  
  751. #BACK:  LD      DE,0
  752.          ENDM
  753.  
  754. The macro itself is not really  useful  but  it is correct and shows the
  755. use of local labels.
  756.  
  757. ---------------------------------- end ---------------------------------
  758.