home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / lambda / soundpot / p / z80mr.lbr / Z80MR.DZC / Z80MR.DOC
Encoding:
Text File  |  1993-10-25  |  25.5 KB  |  701 lines

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