home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource4 / 276_01 / az80.doc < prev    next >
Encoding:
Text File  |  1989-10-03  |  42.3 KB  |  1,097 lines

  1. /*
  2.     HEADER:        CUG276;
  3.     TITLE:        Z-80 Cross-Assembler (Portable);
  4.     FILENAME:    AZ80.DOC;
  5.     VERSION:    0.1;
  6.     DATE:        08/27/1988;
  7.     SEE-ALSO:    AZ80.H;
  8.     AUTHORS:    William C. Colley III;
  9. */
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.                            Z-80 Cross-Assembler (Portable)
  25.  
  26.  
  27.                                      Version 0.1
  28.  
  29.  
  30.                    Copyright (c) 1986-1988 William C. Colley, III
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.                               The manual such as it is.
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.           Legal Note:    This package may be used for any commercial or
  50.                          non-commercial purpose.  It may be copied and
  51.                          distributed freely provided that any fee charged
  52.                          by the distributor of the copy does not exceed the
  53.                          sum of:  1) the cost of the media the copy is
  54.                          written on,  2) any required costs of shipping the
  55.                          copy, and  3) a nominal handling fee.  Any other
  56.                          distribution requires the written permission of
  57.                          the author.  Also, the author's copyright notices
  58.                          shall not be removed from the program source, the
  59.                          program object, or the program documentation.
  60.  
  61.  
  62.  
  63.                                   Table of Contents
  64.  
  65.           1.0  How to Use the Cross-Assembler Package ..................  3
  66.           2.0  Format of Cross-Assembler Source Lines ..................  4
  67.                2.1  Labels .............................................  5
  68.                2.2  Numeric Constants ..................................  5
  69.                2.3  String Constants ...................................  6
  70.                2.4  Expressions ........................................  6
  71.           3.0  Machine Opcodes .........................................  7
  72.           4.0  Pseudo Opcodes ..........................................  8
  73.                4.1  Pseudo-ops -- DB, DEFB, DEFM .......................  8
  74.                4.2  Pseudo-ops -- DC ...................................  9
  75.                4.3  Pseudo-ops -- DEFS, DS .............................  9
  76.                4.4  Pseudo-ops -- DEFW, DW .............................  9
  77.                4.5  Pseudo-ops -- END ..................................  9
  78.                4.6  Pseudo-ops -- EQU .................................. 10
  79.                4.7  Pseudo-ops -- COND, ELSE, ENDC, ENDIF, IF .......... 10
  80.                4.8  Pseudo-ops -- INCL ................................. 11
  81.                4.9  Pseudo-ops -- ORG .................................. 11
  82.                4.10 Pseudo-ops -- PAGE ................................. 11
  83.                4.11 Pseudo-ops -- TITLE ................................ 12
  84.                4.12 Pseudo-ops -- DEFL, VAR ............................ 12
  85.           5.0  Assembly Errors ......................................... 12
  86.                5.1  Error * -- Missing Statement ....................... 12
  87.                5.2  Error ( -- Parenthesis Imbalance ................... 13
  88.                5.3  Error " -- Missing Quotation Mark .................. 13
  89.                5.4  Error B -- Branch Target Too Far Away .............. 13
  90.                5.5  Error D -- Illegal Digit ........................... 13
  91.                5.6  Error E -- Illegal Expression ...................... 13
  92.                5.7  Error I -- IF-ENDIF Imbalance ...................... 14
  93.                5.8  Error L -- Illegal Label ........................... 14
  94.                5.9  Error M -- Multiply Defined Label .................. 14
  95.                5.10 Error O -- Illegal Opcode .......................... 14
  96.                5.11 Error P -- Phasing Error ........................... 14
  97.                5.12 Error R -- Illegal Register Specification .......... 15
  98.                5.12 Error S -- Illegal Syntax .......................... 15
  99.                5.13 Error T -- Too Many Arguments ...................... 15
  100.                5.14 Error U -- Undefined Label ......................... 15
  101.                5.15 Error V -- Illegal Value ........................... 15
  102.           6.0  Warning Messages ........................................ 15
  103.                6.1  Warning -- Illegal Option Ignored .................. 16
  104.                6.2  Warning -- -l Option Ignored -- No File Name ....... 16
  105.                6.3  Warning -- -o Option Ignored -- No File Name ....... 16
  106.                6.4  Warning -- Extra Source File Ignored ............... 16
  107.                6.5  Warning -- Extra Listing File Ignored .............. 16
  108.                6.6  Warning -- Extra Object File Ignored ............... 16
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.                                      1
  121.  
  122.  
  123.  
  124.           7.0  Fatal Error Messages .................................... 16
  125.                7.1  Fatal Error -- No Source File Specified ............ 16
  126.                7.2  Fatal Error -- Source File Did Not Open ............ 17
  127.                7.3  Fatal Error -- Listing File Did Not Open ........... 17
  128.                7.4  Fatal Error -- Object File Did Not Open ............ 17
  129.                7.5  Fatal Error -- Error Reading Source File ........... 17
  130.                7.6  Fatal Error -- Disk or Directory Full .............. 17
  131.                7.7  Fatal Error -- File Stack Overflow ................. 17
  132.                7.8  Fatal Error -- If Stack Overflow ................... 17
  133.                7.9  Fatal Error -- Too Many Symbols .................... 17
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.                                      2
  182.  
  183.  
  184.  
  185.           1.0  How to Use the Cross-Assembler Package
  186.  
  187.                First, the question, "What does a cross-assembler do?" needs
  188.           to be addressed as there is considerable confusion on this point.
  189.           A cross-assembler is just like any other assembler except that it
  190.           runs on some CPU other than the one for which it assembles code.
  191.           For example, this package assembles Z-80 source code into Z-80
  192.           object code, but it runs on an 8088, a 68000, or whatever other
  193.           CPU you happen to have a C compiler for.  The reason that cross-
  194.           assemblers are useful is that you probably already have a CPU
  195.           with memory, disk drives, a text editor, an operating system, and
  196.           all sorts of hard-to-build or expensive facilities on hand.  A
  197.           cross-assembler allows you to use these facilites to develop code
  198.           for a Z-80.
  199.  
  200.                Note that if you compile this cross-assembler on a Z-80
  201.           system, it becomes a normal assembler instead of a cross-
  202.           assembler.  That is, it compiles Z-80 source code to Z-80 object
  203.           code while running on a Z-80.
  204.  
  205.                This program requires one input file (your Z-80 source code)
  206.           and zero to two output files (the listing and the object).  The
  207.           input file MUST be specified, or the assembler will bomb on a
  208.           fatal error.  The listing and object files are optional.  If no
  209.           listing file is specified, no listing is generated, and if no
  210.           object file is specified, no object is generated.  If the object
  211.           file is specified, the object is written to this file in "Intel
  212.           hexadecimal" format.
  213.  
  214.                The command line for the cross-assembler looks like this:
  215.  
  216.                     AZ80 source_file { >list_file } { -o object_file }
  217.  
  218.           where the { } indicates that the specified item is optional.
  219.  
  220.                Some examples are in order:
  221.  
  222.                az80 tests6.asm                    source:   testz80.asm
  223.                                                   listing:  none
  224.                                                   object:   none
  225.  
  226.                az80 testz80.asm -l testz80.prn    source:   testz80.asm
  227.                                                   listing:  testz80.prn
  228.                                                   object:   none
  229.  
  230.                az80 testz80.asm -o testz80.hex    source:   testz80.asm
  231.                                                   listing:  none
  232.                                                   object:   testz80.hex
  233.  
  234.                az80 testz80.asm -l testz80.prn -o testz80.hex
  235.                                                   source:   testz80.asm
  236.                                                   listing:  testz80.prn
  237.                                                   object:   testz80.hex
  238.  
  239.  
  240.  
  241.  
  242.                                      3
  243.  
  244.  
  245.  
  246.                The order in which the source, listing, and object files are
  247.           specified does not matter.  Note that no default file name exten-
  248.           sions are supplied by the assembler as this gives rise to porta-
  249.           bility problems.
  250.  
  251.  
  252.           2.0  Format of Cross-Assembler Source Lines
  253.  
  254.                The source file that the cross-assembler processes into a
  255.           listing and an object is an ASCII text file that you can prepare
  256.           with whatever editor you have at hand.  The most-significant
  257.           (parity) bit of each character is cleared as the character is
  258.           read from disk by the cross-assembler, so editors that set this
  259.           bit (such as WordStar's document mode) should not bother this
  260.           program.  All printing characters, the ASCII TAB character (09H),
  261.           and newline character(s) are processed by the assembler.  All
  262.           other characters are passed through to the listing file, but are
  263.           otherwise ignored.
  264.  
  265.                The source file is divided into lines by newline char-
  266.           acter(s).  The internal buffers of the cross-assembler will
  267.           accommodate lines of up to 255 characters which should be more
  268.           than ample for almost any job.  If you must use longer lines,
  269.           change the constant MAXLINE in file AZ80.H and recompile the
  270.           cross-assembler.  Otherwise, you will overflow the buffers, and
  271.           the program will mysteriously crash.
  272.  
  273.                Each source line is made up of three fields:  the label
  274.           field, the opcode field, and the argument field.  The label field
  275.           is optional, but if it is present, it must begin in column 1.
  276.           The opcode field is optional, but if it is present, it must not
  277.           begin in column 1.  If both a label and an opcode are present,
  278.           one or more spaces and/or TAB characters must separate the two.
  279.           If the opcode requires arguments, they are placed in the argument
  280.           field which is separated from the opcode field by one or more
  281.           spaces and/or TAB characters.  Finally, an optional comment can
  282.           be added to the end of the line.  This comment must begin with a
  283.           semicolon which signals the assembler to pass the rest of the
  284.           line to the listing and otherwise ignore it.  Thus, the source
  285.           line looks like this:
  286.  
  287.                {label}{ opcode{ arguments}}{;commentary}
  288.  
  289.           where the { } indicates that the specified item is optional.
  290.  
  291.                Some examples are in order:
  292.  
  293.             column 1
  294.                |
  295.                v
  296.                GRONK   LD    A, (HL)         ; This line has everything.
  297.                        INC   IX              ; This line has no label.
  298.                BEEP                          ; This line has no opcode.
  299.                ; This line has no label and no opcode.
  300.  
  301.  
  302.  
  303.                                      4
  304.  
  305.  
  306.  
  307.                ; The previous line has nothing at all.
  308.                        END                   ; This line has no argument.
  309.  
  310.  
  311.           2.1  Labels
  312.  
  313.                A label is any sequence of alphabetic or numeric characters
  314.           starting with an alphabetic.  The legal alphabetics are:
  315.  
  316.                   ! # $ % & . : ? @ [ \ ] ^ _  ` { | }  ~  A-Z  a-z
  317.  
  318.           The numeric characters are the digits 0-9.  Note that "A" is not
  319.           the same as "a" in a label.  This can explain mysterious U
  320.           (undefined label) errors occurring when a label appears to be
  321.           defined.
  322.  
  323.                A label is permitted on any line except a line where the
  324.           opcode is COND, ELSE, ENDC, ENDIF, or IF.  The label is assigned
  325.           the value of the assembly program counter before any of the rest
  326.           of the line is processed except when the opcode is DEFL, EQU,
  327.           ORG, or VAR.
  328.  
  329.                Labels can have the same name as opcodes, but they cannot
  330.           have the same name as operators or built-in condition code or
  331.           register tags.  The reserved (operator and tag) names are:
  332.  
  333.                $         A         AF        AND       B         BC
  334.                C         D         DE        E         EQ        GE
  335.                GT        H         HIGH      HL        I         IX
  336.                IY        L         LE        LT        LOW       M
  337.                MOD       NC        NE        NOT       NZ        OR
  338.                P         PE        PO        R         SHL       SHR
  339.                SP        XOR       Z
  340.  
  341.                If a label is used in an expression before it is assigned a
  342.           value, the label is said to be "forward-referenced."  For
  343.           example:
  344.  
  345.                L1   EQU  L2 + 1   ; L2 is forward-referenced here.
  346.                L2
  347.                L3   EQU  L2 + 1   ; L2 is not forward-referenced here.
  348.  
  349.  
  350.           2.2  Numeric Constants
  351.  
  352.                Numeric constants are formed according to the Intel
  353.           convention.  A numeric constant starts with a numeric character
  354.           (0-9), continues with zero or more digits (0-9, A-F), and ends
  355.           with an optional base designator.  The base designators are H for
  356.           hexadecimal, none or D for decimal, O or Q for octal, and B for
  357.           binary.  The hex digits a-f are converted to upper case by the
  358.           assembler.  Note that a numeric constant cannot begin with A-F as
  359.           it would be indistinguishable from a label.  Thus, all of the
  360.           following evaluate to 255 (decimal):
  361.  
  362.  
  363.  
  364.                                      5
  365.  
  366.  
  367.  
  368.                      0ffH   255   255D   377O   377Q   11111111B
  369.  
  370.  
  371.           2.3  String Constants
  372.  
  373.                A string constant is zero or more characters enclosed in
  374.           either single quotes (' ') or double quotes (" ").  Single quotes
  375.           only match single quotes, and double quotes only match double
  376.           quotes, so if you want to put a single quote in a string, you can
  377.           do it like this:  "'".  In all contexts except the DB, DEFB,
  378.           DEFM, and DC statements, the first character or two of the string
  379.           constant are all that are used.  The rest is ignored.  Noting
  380.           that the ASCII codes for "A" and "B" are $41 and $42, respec-
  381.           tively, will explain the following examples:
  382.  
  383.                     "" and ''           evaluate to 0000H
  384.                     "A" and 'A'         evaluate to 0041H
  385.                     "AB"                evaluates to 4142H
  386.  
  387.           Note that the null string "" is legal and evaluates to 0000H.
  388.  
  389.  
  390.           2.4  Expressions
  391.  
  392.                An expression is made up of labels, numeric constants, and
  393.           string constants glued together with arithmetic operators,
  394.           logical operators, and parentheses in the usual way that
  395.           algebraic expressions are made.  Operators have the following
  396.           fairly natural order of precedence:
  397.  
  398.                Highest        anything in parentheses
  399.                               unary +, unary -
  400.                               *, /, MOD, SHL, SHR
  401.                               binary +, binary -
  402.                               LT, LE, EQ, GE, GT, NE
  403.                               NOT
  404.                               AND
  405.                               OR, XOR
  406.                Lowest         HIGH, LOW
  407.  
  408.                A few notes about the various operators are in order:
  409.  
  410.                1)   The remainder operator MOD yields the remainder from
  411.                     dividing its left operand by its right operand.
  412.  
  413.                2)   The shifting operators SHL and SHR shift their left
  414.                     operand to the left or right the number of bits
  415.                     specified by their right operand.
  416.  
  417.                3)   The relational operators LT, LE, EQ, GE, GT, and NE can
  418.                     also be written as <, <= or =<, =, >= or =>, and <> or
  419.                     ><, respectively.  They evaluate to 0FFFFH if the
  420.                     statement is true, 0 otherwise.
  421.  
  422.  
  423.  
  424.  
  425.                                      6
  426.  
  427.  
  428.  
  429.                4)   The logical opeators NOT, AND, OR, and XOR do bitwise
  430.                     operations on their operand(s).
  431.  
  432.                5)   HIGH and LOW extract the high or low byte, of an
  433.                     expression.
  434.  
  435.                6)   The special symbol $ can be used in place of a label or
  436.                     constant to represent the value of the program counter
  437.                     before any of the current line has been processed.
  438.  
  439.                Some examples are in order at this point:
  440.  
  441.                2 + 3 * 4                          evaluates to 14
  442.                (2 + 3) * 4                        evaluates to 20
  443.                NOT 11110000B XOR 00001010B        evaluates to 00000101B
  444.                HIGH 1234H SHL 1                   evaluates to 0024H
  445.                001Q EQ 0                          evaluates to 0
  446.                001Q = 2 SHR 1                     evaluates to 0FFFFH
  447.  
  448.                All arithmetic is unsigned with overflow from the 16-bit
  449.           word ignored.  Thus:
  450.  
  451.                32768 * 2                          evaluates to 0
  452.  
  453.  
  454.           3.0  Machine Opcodes
  455.  
  456.                The instruction set of the Z-80 processor is particularly
  457.           complicated to describe.  If I followed my usual practice of
  458.           describing the allowable syntax of each machine opcode, this
  459.           section of the manual would go on for many pages.  To save a few
  460.           trees when you print up this manual, I will dispense with the
  461.           usual detail and make only general remarks about the machine
  462.           opcode syntax.
  463.  
  464.                This assembler accepts Zilog's mnemonics as opposed to the
  465.           extended 8080 mnemonics used by descendents of the TDL
  466.           assemblers.  The argument field also follows Zilog's syntax.
  467.           This means that the parentheses, (), are overloaded.  They are
  468.           used both to group subexpression in arithmetic expressions and to
  469.           designate direct or register indirect addressing instead of
  470.           immediate or register direct addressing.  If an arithmetic
  471.           expression in the argument field of a machine opcode is ENTIRELY
  472.           enclosed in parentheses, direct addressing is selected.  If a
  473.           register tag is enclosed in parentheses, register indirect
  474.           addressing is selected.  Some examples are in order:
  475.  
  476.                LD   HL, 1234H      ;Register pair HL gets set to 1234H.
  477.                LD   HL, (1234H)    ;Register pair HL gets set to the
  478.                                    ;  value contained in memory locations
  479.                                    ;  1234H and 1235H.
  480.  
  481.                INC  HL             ;Register pair HL gets incremented.
  482.                INC  (HL)           ;The memory location pointed to by
  483.                                    ;  register pair HL gets incremented.
  484.  
  485.  
  486.                                      7
  487.  
  488.  
  489.  
  490.  
  491.           Note that an expression enclosed in parentheses will cause an S
  492.           (syntax) error if direct addressing is not allowed by the parti-
  493.           cular machine opcode.  For example:
  494.  
  495.                ADD  A, 3 + 4       ;Legal -- 7 gets added to the accumu-
  496.                                    ;  lator.
  497.                ADD  A, (3) + 4     ;Legal -- Same as above.  Note that the
  498.                                    ;  expression is not entirely enclosed
  499.                                    ;  by the parentheses.
  500.                ADD  A, (3) + (4)   ;Legal -- Same as above.  The expression
  501.                                    ;  still is not completely enclosed by
  502.                                    ;  the parentheses.
  503.                ADD  A, (3 + 4)     ;Illegal -- The Z-80 cannot be told to
  504.                                    ;  add the number contained in memory
  505.                                    ;  location 7 to the accumulator, so
  506.                                    ;  this is a syntax error.
  507.                LD   A, (3 + 4)     ;Legal -- The Z-80 can be told to load
  508.                                    ;  the number contained in memory loca-
  509.                                    ;  tion 7 into the accumulator.
  510.  
  511.                For further information on the machine opcode syntax
  512.           supported by this assembler, consult Zilog's "Z-80 Assembly
  513.           Language Programming Manual."
  514.  
  515.  
  516.           4.0  Pseudo Opcodes
  517.  
  518.                Unlike Z-80 opcodes, pseudo opcodes (pseudo-ops) do not
  519.           represent machine instructions.  They are, rather, directives to
  520.           the assembler.  These directives require various numbers and
  521.           types of arguments.  They will be listed individually below.
  522.  
  523.  
  524.           4.1  Pseudo-ops -- DB, DEFB, DEFM
  525.  
  526.                The DB pseudo-op and its Zilog synonyms DEFB and DEFM allow
  527.           arbitrary bytes to be spliced into the object code.  Its argument
  528.           is a chain of one or more expressions that evaluate to -128
  529.           through 255 separated by commas.  If a comma occurs with no
  530.           preceding expression, a 00H byte is spliced into the object code.
  531.           The sequence of bytes 0FEH, 0FFH, 00H, 01H, 02H could be spliced
  532.           into the code with the following statement:
  533.  
  534.                          DB        -2, -1, , 1, 2
  535.  
  536.           A special case exists here.  If a string constant is entered with
  537.           no arithmetic done on it, then the entire string is spliced into
  538.           the code stream.  Thus, the sequence of bytes 002H, 043H, 041H,
  539.           054H, 044H could be spliced into the code with the following
  540.           statement:
  541.  
  542.                          DB        1 + 1, "CAT", "C" + 1
  543.  
  544.  
  545.  
  546.  
  547.                                      8
  548.  
  549.  
  550.  
  551.           4.2  Pseudo-ops -- DC
  552.  
  553.                The DC pseudo-op is the same as the DB pseudo-op except that
  554.           the most-significant bit of the last byte defined is set.  This
  555.           is handy for placing terminating most-significant bits on
  556.           character strings.  Thus, the sequence of bytes 43H, 41H, 0D4H
  557.           could be spliced into the code with the following statement:
  558.  
  559.                          DC        "CAT"
  560.  
  561.  
  562.           4.3  Pseudo-ops -- DEFS, DS
  563.  
  564.                The DS pseudo-op and its Zilog synonym DEFS are used to
  565.           reserve a block of storage for program variables, or whatever.
  566.           This storage is not initialized in any way, so its value at run
  567.           time will usually be random.  The argument expression (which may
  568.           contain no forward references) is added to the assembly program
  569.           counter.  The following statement would reserve 10 bytes of
  570.           storage called "STORAGE":
  571.  
  572.                STORAGE   DS        10
  573.  
  574.  
  575.           4.4  Pseudo-ops -- DEFW, DW
  576.  
  577.                The DW pseudo-op and its Zilog synonym DEFW allow 16-bit
  578.           words to be spliced into the object code.  Its argument is a
  579.           chain of zero or more expressions separated by commas.  If a
  580.           comma occurs with no preceding expression, a word of 0000H is
  581.           spliced into the code.  The word is placed into memory low byte
  582.           in low address, high byte in high address.  The sequence of bytes
  583.           0FEH, 0FFH, 00H, 00H, 01H, 02H could be spliced into the code
  584.           with the following statement:
  585.  
  586.                          DW        0FFFEH, , 0201H
  587.  
  588.  
  589.           4.5  Pseudo-ops -- END
  590.  
  591.                The END pseudo-op tells the assembler that the source
  592.           program is over.  Any further lines of the source file are
  593.           ignored and not passed on to the listing.  If an argument is
  594.           added to the END statement, the value of the argument will be
  595.           placed in the execution address slot in the Intel hex object
  596.           file.  The execution address defaults to the program counter
  597.           value at the point where the END was encountered.  Thus, to
  598.           specify that the program starts at label START, the END statement
  599.           would be:
  600.  
  601.                          END       START
  602.  
  603.                If end-of-file is encountered on the source file before an
  604.           END statement is reached, the assembler will add an END statement
  605.           to the listing and flag it with a * (missing statement) error.
  606.  
  607.  
  608.                                      9
  609.  
  610.  
  611.  
  612.  
  613.  
  614.           4.6  Pseudo-ops -- EQU
  615.  
  616.                The EQU pseudo-op is used to assign a specific value to a
  617.           label, thus the label on this line is REQUIRED.  Once the value
  618.           is assigned, it cannot be reassigned by writing the label in
  619.           column 1, by another EQU statement, or by a DEFL or VAR
  620.           statement.  Thus, for example, the following statement assigns
  621.           the value 2 to the label TWO:
  622.  
  623.                TWO       EQU       1 + 1
  624.  
  625.                The expression in the argument field must contain no forward
  626.           references.
  627.  
  628.  
  629.           4.7  Pseudo-ops -- COND, ELSE, ENDC, ENDIF, IF
  630.  
  631.                These pseudo-ops allow the assembler to choose whether
  632.           or not to assemble certain blocks of code based on the result of
  633.           an expression.  Code that is not assembled is passed through to
  634.           the listing but otherwise ignored by the assembler.  The IF
  635.           pseudo-op or its Zilog synonym COND signals the beginning of a
  636.           conditionally assembled block.  It requires one argument that may
  637.           contain no forward references.  If the value of the argument is
  638.           non-zero, the block is assembled.  Otherwise, the block is
  639.           ignored.  The ENDIF pseudo-op or its Zilog synonym ENDC signals
  640.           the end of the conditionally assembled block.  For example:
  641.  
  642.                          IF   EXPRESSION     ;This whole thing generates
  643.                          DB   01H, 02H, 03H  ;  no code whatsoever if
  644.                          ENDIF               ;  EXPRESSION is zero.
  645.  
  646.           The ELSE pseudo-op allows the assembly of either one of two
  647.           blocks, but not both.  The following two sequences are
  648.           equivalent:
  649.  
  650.                          IF   EXPRESSION
  651.                          ... some stuff ...
  652.                          ELSE
  653.                          ... some more stuff ...
  654.                          ENDIF
  655.  
  656.                TEMP_LAB  VAR  EXPRESSION
  657.                          IF   TEMP_LAB NE 0
  658.                          ... some stuff ...
  659.                          ENDIF
  660.                          IF   TEMP_LAB EQ 0
  661.                          ... some more stuff ...
  662.                          ENDIF
  663.  
  664.                The pseudo-ops in this group do NOT permit labels to exist
  665.           on the same line as the status of the label (ignored or not)
  666.           would be ambiguous.
  667.  
  668.  
  669.                                      10
  670.  
  671.  
  672.  
  673.  
  674.                All COND or IF statements (even those in ignored condition-
  675.           ally assembled blocks) must have corresponding ENDC or ENDIF
  676.           statements and all ELSE, ENDC, and ENDIF statements must have a
  677.           corresponding COND or IF statement.
  678.  
  679.                IF blocks can be nested up to 16 levels deep before the
  680.           assembler dies of a fatal error.  This should be adequate for any
  681.           conceivable job, but if you need more, change the constant
  682.           IFDEPTH in file AZ80.H and recompile the assembler.
  683.  
  684.  
  685.           4.8  Pseudo-ops -- INCL
  686.  
  687.                The INCL pseudo-op is used to splice the contents of another
  688.           file into the current file at assembly time.  The name of the
  689.           file to be INCLuded is specified as a normal string constant, so
  690.           the following line would splice the contents of file "const.def"
  691.           into the source code stream:
  692.  
  693.                          INCL      "const.def"
  694.  
  695.                INCLuded files may, in turn, INCLude other files until four
  696.           files are open simultaneously.  This limit should be enough for
  697.           any conceivable job, but if you need more, change the constant
  698.           FILES in file AZ80.H and recompile the assembler.
  699.  
  700.  
  701.           4.9  Pseudo-ops -- ORG
  702.  
  703.                The ORG pseudo-op is used to set the assembly program
  704.           counter to a particular value.  The expression that defines this
  705.           value may contain no forward references.  The default initial
  706.           value of the assembly program counter is 0000H.  The following
  707.           statement would change the assembly program counter to 0FFCH:
  708.  
  709.                          ORG       0FFCH
  710.  
  711.                If a label is present on the same line as an ORG statement,
  712.           it is assigned the new value of the assembly program counter.
  713.  
  714.  
  715.           4.10 Pseudo-ops -- PAGE
  716.  
  717.                The PAGE pseudo-op always causes an immediate page ejection
  718.           in the listing by inserting a form feed ('\f') character before
  719.           the next line.  If an argument is specified, the argument
  720.           expression specifies the number of lines per page in the listing.
  721.           Legal values for the expression are any number except 1 and 2.  A
  722.           value of 0 turns the listing pagination off.  Thus, the following
  723.           statement cause a page ejection and would divide the listing into
  724.           60-line pages:
  725.  
  726.                          PAGE      60
  727.  
  728.  
  729.  
  730.                                      11
  731.  
  732.  
  733.  
  734.  
  735.           4.11 Pseudo-ops -- TITLE
  736.  
  737.                The TITL pseudo-op sets the running title for the listing.
  738.           The argument field is required and must be a string constant,
  739.           though the null string ("") is legal.  This title is printed
  740.           after every page ejection in the listing, therefore, if page
  741.           ejections have not been forced by the PAGE pseudo-op, the title
  742.           will never be printed.  The following statement would print the
  743.           title "Random Bug Generator -- Ver 3.14159" at the top of every
  744.           page of the listing:
  745.  
  746.                          TITLE     "Random Bug Generator -- Ver 3.14159"
  747.  
  748.  
  749.           4.12 Pseudo-ops -- DEFL, VAR
  750.  
  751.                The VAR pseudo-op and its Zilog synonym DEFL function like
  752.           the EQU pseudo-op except that the VAR statement can reassign the
  753.           value of a label that has already been assigned by another VAR
  754.           statement.  Like the EQU statement, the argument expression may
  755.           contain no forward references.  A label defined by a VAR
  756.           statement cannot be redefined by writing it in column 1 or with
  757.           an EQU statement.  The following series of statements would set
  758.           the value of label "COUNT" to 1, 2, then 3:
  759.  
  760.                COUNT     VAR       1
  761.                COUNT     VAR       2
  762.                COUNT     VAR       3
  763.  
  764.  
  765.           5.0  Assembly Errors
  766.  
  767.                When a source line contains an illegal construct, the line
  768.           is flagged in the listing with a single-letter code describing
  769.           the error.  The meaning of each code is listed below.  In
  770.           addition, a count of the number of lines with errors is kept and
  771.           printed on the C "stderr" device (by default, the console) after
  772.           the END statement is processed.  If more than one error occurs in
  773.           a given line, only the first is reported.  For example, the
  774.           illegal label "=$#*'(" would generate the following listing line:
  775.  
  776.                L  0000   0D 80 00      =$#*'(     INC       IX
  777.  
  778.  
  779.           5.1  Error * -- Illegal or Missing Statement
  780.  
  781.                This error occurs when either:
  782.  
  783.                1)   the assembler reaches the end of the source file
  784.                     without seeing an END statement, or
  785.  
  786.                2)   an END statement is encountered in an INCLude file.
  787.  
  788.  
  789.  
  790.  
  791.                                      12
  792.  
  793.  
  794.  
  795.                If you are "sure" that the END statement is present when the
  796.           assembler thinks that it is missing, it probably is in the
  797.           ignored section of an IF block.  If the END statement is missing,
  798.           supply it.  If the END statement is in an INCLude file, delete
  799.           it.
  800.  
  801.  
  802.           5.2  Error ( -- Parenthesis Imbalance
  803.  
  804.                For every left parenthesis, there must be a right paren-
  805.           thesis.  Count them.  Also, certain register tags allow
  806.           expressions to reside in parentheses with them, while others do
  807.           not.  The legal forms of parenthesized register tags are:
  808.  
  809.                (IX + <expression>)                (IY + <expression>)
  810.                (IX - <expression>)                (IY - <expression>)
  811.  
  812.               (BC)     (DE)     (HL)     (SP)     (IX)     (IY)     (C)
  813.  
  814.           An expression like (HL + 3) will cause a ( error.
  815.  
  816.  
  817.           5.3  Error " -- Missing Quotation Mark
  818.  
  819.                Strings have to begin and end with either " or '.  Remember
  820.           that " only matches " while ' only matches '.
  821.  
  822.  
  823.           5.4  Error B -- Branch Target Too Far Away
  824.  
  825.                The Z-80 relative branch instructions (DJNZ and JR) will
  826.           only reach bytes that are within -126 to +129 bytes of the first
  827.           byte of the instruction.  If this error occurs, the source code
  828.           will have to be rearranged to bring the branch target into range
  829.           or a JP instruction that will reach anywhere will have to be
  830.           used.
  831.  
  832.  
  833.           5.5  Error D -- Illegal Digit
  834.  
  835.                This error occurs if a digit greater than or equal to the
  836.           base of a numeric constant is found.  For example, a 2 in a
  837.           binary number would cause a D error.  Especially, watch for 8 or
  838.           9 in an octal number.
  839.  
  840.  
  841.           5.6  Error E -- Illegal Expression
  842.  
  843.                This error occurs because of:
  844.  
  845.                1)   a missing expression where one is required
  846.  
  847.                2)   a unary operator used as a binary operator or vice-
  848.                     versa
  849.  
  850.  
  851.  
  852.                                      13
  853.  
  854.  
  855.  
  856.                3)   a missing binary operator
  857.  
  858.                4)   a SHL or SHR count that is not 0 thru 15
  859.  
  860.  
  861.           5.7  Error I -- IF-ENDIF Imbalance
  862.  
  863.                For every COND or IF there must be a corresponding ENDC or
  864.           ENDIF.  If this error occurs on an ELSE, ENDC, or ENDIF
  865.           statement, the corresponding COND or IF is missing.  If this
  866.           error occurs on an END statement, one or more ENDC or ENDIF
  867.           statements are missing.
  868.  
  869.  
  870.           5.8  Error L -- Illegal Label
  871.  
  872.                This error occurs because of:
  873.  
  874.                1)   a non-alphabetic in column 1
  875.  
  876.                2)   a reserved word used as a label
  877.  
  878.                3)   a missing label on an DEFL, EQU, or VAR statement
  879.  
  880.                4)   a label on a COND, ELSE, ENDC, ENDIF, or IF statement
  881.  
  882.  
  883.           5.9  Error M -- Multiply Defined Label
  884.  
  885.                This error occurs because of:
  886.  
  887.                1)   a label defined in column 1 or with the EQU statement
  888.                     being redefined
  889.  
  890.                2)   a label defined by a DEFL or VAR statement being
  891.                     redefined either in column 1 or with the EQU statement
  892.  
  893.                3)   the value of the label changing between assembly passes
  894.  
  895.  
  896.           5.10 Error O -- Illegal Opcode
  897.  
  898.                The opcode field of a source line may contain only a valid
  899.           machine opcode, a valid pseudo-op, or nothing at all.  Anything
  900.           else causes this error.
  901.  
  902.  
  903.           5.11 Error P -- Phasing Error
  904.  
  905.                This error occurs because of:
  906.  
  907.                1)   a forward reference in a DEFL, DEFS, DS, EQU, ORG, or
  908.                     VAR statement
  909.  
  910.                2)   a label disappearing between assembly passes
  911.  
  912.  
  913.                                      14
  914.  
  915.  
  916.  
  917.  
  918.  
  919.           5.12 Error R -- Illegal Register Specification
  920.  
  921.                This error means that you did one of the following:
  922.  
  923.                1)   Specified a register or condition code tag where no tag
  924.                     is allowed, such as RST HL, or
  925.  
  926.                2)   Specified an inappropriate register or condition code
  927.                     tag, such as JP (DE).
  928.  
  929.  
  930.           5.13 Error S -- Illegal Syntax
  931.  
  932.                This error means that an argument field is scrambled.  Sort
  933.           the mess out and reassemble.  Look for missing commas, missing
  934.           arguments, and the like.
  935.  
  936.  
  937.           5.14 Error T -- Too Many Arguments
  938.  
  939.                This error occurs if there are more items (expressions,
  940.           register designators, etc.) in the argument field than the opcode
  941.           or pseudo-op requires.  The assembler ignores the extra items but
  942.           issues this error in case something is really mangled.
  943.  
  944.  
  945.           5.15 Error U -- Undefined Label
  946.  
  947.                This error occurs if a label is referenced in an expression
  948.           but not defined anywhere in the source program.  If you are
  949.           "sure" you have defined the label, note that upper and lower case
  950.           letters in labels are different.  Defining "LABEL" does not
  951.           define "Label."
  952.  
  953.  
  954.           5.16 Error V -- Illegal Value
  955.  
  956.                This error occurs because:
  957.  
  958.                1)   an immediate value is not -128 thru 255, or
  959.  
  960.                2)   a DB argument is not -128 thru 255, or
  961.  
  962.                3)   an INCL argument refers to a file that does not exist,
  963.  
  964.                4)   an indexing offset (the <number> in (IX + <number>) is
  965.                     not in the range -128 through 127, or
  966.  
  967.                5)   a bit number in a BIT, RES, or SET instruction is
  968.                     greater than 7.
  969.  
  970.  
  971.  
  972.  
  973.  
  974.                                      15
  975.  
  976.  
  977.  
  978.           6.0  Warning Messages
  979.  
  980.                Some errors that occur during the parsing of the cross-
  981.           assembler command line are non-fatal.  The cross-assembler flags
  982.           these with a message on the C "stdout" device (by default, the
  983.           console) beginning with the word "Warning."  The messages are
  984.           listed below:
  985.  
  986.  
  987.           6.1  Warning -- Illegal Option Ignored
  988.  
  989.                The only options that the cross-assembler knows are -l and
  990.           -o.  Any other command line argument beginning with - will draw
  991.           this error.
  992.  
  993.  
  994.           6.2  Warning -- -l Option Ignored -- No File Name
  995.           6.3  Warning -- -o Option Ignored -- No File Name
  996.  
  997.                The -l and -o options require a file name to tell the
  998.           assembler where to put the listing file or object file.  If this
  999.           file name is missing, the option is ignored.
  1000.  
  1001.  
  1002.           6.4  Warning -- Extra Source File Ignored
  1003.  
  1004.                The cross-assembler will only assemble one file at a time,
  1005.           so source file names after the first are ignored.  To assemble a
  1006.           second file, invoke the assembler again.  Note that under CP/M-
  1007.           80, the old trick of reexecuting a core image will NOT work as
  1008.           the initialized data areas are not reinitialized prior to the
  1009.           second run.
  1010.  
  1011.  
  1012.           6.5  Warning -- Extra Listing File Ignored
  1013.           6.6  Warning -- Extra Object File Ignored
  1014.  
  1015.                The cross-assembler will only generate one listing and
  1016.           object file per assembly run, so -l and -o options after the
  1017.           first are ignored.
  1018.  
  1019.  
  1020.           7.0  Fatal Error Messages
  1021.  
  1022.                Several errors that occur during the parsing of the cross-
  1023.           assembler command line or during the assembly run are fatal.  The
  1024.           cross-assembler flags these with a message on the C "stdout"
  1025.           device (by default, the console) beginning with the words "Fatal
  1026.           Error."  The messages are explained below:
  1027.  
  1028.  
  1029.           7.1  Fatal Error -- No Source File Specified
  1030.  
  1031.                This one is self-explanatory.  The assembler does not know
  1032.           what to assemble.
  1033.  
  1034.  
  1035.                                      16
  1036.  
  1037.  
  1038.  
  1039.  
  1040.  
  1041.           7.2  Fatal Error -- Source File Did Not Open
  1042.  
  1043.                The assembler could not open the source file.  The most
  1044.           likely cause is that the source file as specified on the command
  1045.           line does not exist.  On larger systems, there could also be
  1046.           priviledge violations.  Rarely, a read error in the disk
  1047.           directory could cause this error.
  1048.  
  1049.  
  1050.           7.3  Fatal Error -- Listing File Did Not Open
  1051.           7.4  Fatal Error -- Object File Did Not Open
  1052.  
  1053.                This error indicates either a defective listing or object
  1054.           file name or a full disk directory.  Correct the file name or
  1055.           make more room on the disk.
  1056.  
  1057.  
  1058.           7.5  Fatal Error -- Error Reading Source File
  1059.  
  1060.                This error generally indicates a read error in the disk data
  1061.           space.  Use your backup copy of the source file (You do have one,
  1062.           don't you?) to recreate the mangled file and reassemble.
  1063.  
  1064.  
  1065.           7.6  Fatal Error -- Disk or Directory Full
  1066.  
  1067.                This one is self-explanatory.  Some more space must be found
  1068.           either by deleting files or by using a disk with more room on it.
  1069.  
  1070.  
  1071.           7.7  Fatal Error -- File Stack Overflow
  1072.  
  1073.                This error occurs if you exceed the INCLude file limit of
  1074.           four files open simultaneously.  This limit can be increased by
  1075.           increasing the constant FILES in file AZ80.H and recompiling the
  1076.           cross-assembler.
  1077.  
  1078.  
  1079.           7.8  Fatal Error -- If Stack Overflow
  1080.  
  1081.                This error occurs if you exceed the nesting limit of 16 IF
  1082.           blocks.  This limit can be increased by increasing the constant
  1083.           IFDEPTH in file AZ80.H and recompiling the cross-assembler.
  1084.  
  1085.  
  1086.           7.9  Fatal Error -- Too Many Symbols
  1087.  
  1088.                Congratulations!  You have run out of memory.  The space for
  1089.           the cross-assembler's symbol table is allocated at run-time using
  1090.           the C library function malloc(), so the cross-assembler will use
  1091.           all available memory.  The only solutions to this problem are to
  1092.           lessen the number of labels in the source program or to add more
  1093.           memory.
  1094.  
  1095.  
  1096.                                      17
  1097.