home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource4 / 219_01 / a65.doc < prev    next >
Encoding:
Text File  |  1989-01-13  |  43.9 KB  |  1,264 lines

  1. /*
  2.     HEADER:        CUG129;
  3.     TITLE:        6502/65C02 Cross-Assemblers;
  4.     FILENAME:    A65.DOC;
  5.     VERSION:    0.1;
  6.     DATE:        08/27/1988;
  7.  
  8.     DESCRIPTION:    "These programs let you use your computer to assemble
  9.             code for the MOS Technology 6502 and Rockwell 65C02
  10.             microprocessors.  The program is written in portable
  11.             C rather than BDS C.  All assembler features are
  12.             supported except relocation, linkage, and macros.";
  13.  
  14.     KEYWORDS:    Software Development, Assemblers, Cross-Assemblers,
  15.             MOS Technology, Rockwell, 6502, 65C02;
  16.  
  17.     SYSTEM:        CP/M-80, CP/M-86, HP-UX, MSDOS, PCDOS, QNIX;
  18.     COMPILERS:    Aztec C86, Aztec CII, Eco-C, HP-UX, Microsoft C,
  19.             QNIX C;
  20.  
  21.     WARNINGS:    "HP-UX is a Berkeley 4.2 UNIX look-alike, so the port
  22.             to UNIX should be trivial.  So far, the program
  23.             compiles under two different MSDOS/PCDOS compilers, so
  24.             the port to other MSDOS/PCDOS compilers should be
  25.             easy.";
  26.  
  27.     AUTHORS:    William C. Colley III;
  28. */
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.                            6502/65C02 Cross-Assemblers
  44.  
  45.  
  46.                                    Version 0.1
  47.  
  48.  
  49.                     Copyright (c) 1986 William C. Colley, III
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.                             The manual such as it is.
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.         Legal Note:    This package may be used for any commercial or 
  69.                        non-commercial purpose.  It may be copied and 
  70.                        distributed freely provided that any fee charged 
  71.                        by the distributor of the copy does not exceed the 
  72.                        sum of:  1) the cost of the media the copy is 
  73.                        written on,  2) any required costs of shipping the 
  74.                        copy, and  3) a nominal handling fee.  Any other 
  75.                        distribution requires the written permission of 
  76.                        the author.  Also, the author's copyright notices 
  77.                        shall not be removed from the program source, the 
  78.                        program object, or the program documentation.
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.                                 Table of Contents
  94.  
  95.         1.0  How to Use the Cross-Assembler Package ..................  3
  96.         2.0  Format of Cross-Assembler Source Lines ..................  4
  97.              2.1  Labels .............................................  5
  98.              2.2  Numeric Constants ..................................  5
  99.              2.3  String Constants ...................................  6
  100.              2.4  Expressions ........................................  6
  101.         3.0  Machine Opcodes .........................................  7
  102.         4.0  Pseudo Opcodes ..........................................  9
  103.              4.1  Pseudo-ops -- END ..................................  9
  104.              4.2  Pseudo-ops -- EQU .................................. 10
  105.              4.3  Pseudo-ops -- FCB .................................. 10
  106.              4.4  Pseudo-ops -- FCC .................................. 10
  107.              4.5  Pseudo-ops -- FDB .................................. 11
  108.              4.6  Pseudo-ops -- IF, ELSE, ENDI ....................... 11
  109.              4.7  Pseudo-ops -- INCL ................................. 12
  110.              4.8  Pseudo-ops -- ORG .................................. 12
  111.              4.9  Pseudo-ops -- PAGE ................................. 12
  112.              4.10 Pseudo-ops -- RMB .................................. 13
  113.              4.11 Pseudo-ops -- SET .................................. 13
  114.              4.12 Pseudo-ops -- TITL ................................. 13
  115.         5.0  Assembly Errors ......................................... 13
  116.              5.1  Error * -- Illegal or Missing Statement ............ 14
  117.              5.2  Error ( -- Parenthesis Imbalance ................... 14
  118.              5.3  Error " -- Missing Quotation Mark .................. 14
  119.              5.4  Error A -- Illegal Addressing Mode ................. 14
  120.              5.5  Error B -- Branch Target Too Distant ............... 14
  121.              5.6  Error D -- Illegal Digit ........................... 14
  122.              5.7  Error E -- Illegal Expression ...................... 15
  123.              5.8  Error I -- IF-ENDI Imbalance ....................... 15
  124.              5.9  Error L -- Illegal Label ........................... 15
  125.              5.10 Error M -- Multiply Defined Label .................. 15
  126.              5.11 Error O -- Illegal Opcode .......................... 15
  127.              5.12 Error P -- Phasing Error ........................... 16
  128.              5.13 Error R -- Illegal Register ........................ 16
  129.              5.14 Error S -- Illegal Syntax .......................... 16
  130.              5.15 Error T -- Too Many Arguments ...................... 16
  131.              5.16 Error U -- Undefined Label ......................... 16
  132.              5.17 Error V -- Illegal Value ........................... 16
  133.         6.0  Warning Messages ........................................ 17
  134.              6.1  Warning -- Illegal Option Ignored .................. 17
  135.              6.2  Warning -- -l Option Ignored -- No File Name ....... 17
  136.              6.3  Warning -- -o Option Ignored -- No File Name ....... 17
  137.              6.4  Warning -- Extra Source File Ignored ............... 17
  138.              6.5  Warning -- Extra Listing File Ignored .............. 17
  139.              6.6  Warning -- Extra Object File Ignored ............... 17
  140.         7.0  Fatal Error Messages .................................... 17
  141.              7.1  Fatal Error -- No Source File Specified ............ 17
  142.              7.2  Fatal Error -- Source File Did Not Open ............ 18
  143.              7.3  Fatal Error -- Listing File Did Not Open ........... 18
  144.              7.4  Fatal Error -- Object File Did Not Open ............ 18
  145.              7.5  Fatal Error -- Error Reading Source File ........... 18
  146.              7.6  Fatal Error -- Disk or Directory Full .............. 18
  147.              7.7  Fatal Error -- File Stack Overflow ................. 18
  148.  
  149.  
  150.  
  151.                                         1
  152.  
  153.  
  154.  
  155.              7.8  Fatal Error -- If Stack Overflow ................... 18
  156.              7.9  Fatal Error -- Too Many Symbols .................... 18
  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.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.                                         2
  213.  
  214.  
  215.  
  216.         1.0  How to Use the Cross-Assembler Package
  217.  
  218.              First, the question, "What does a cross-assembler do?" needs 
  219.         to be addressed as there is considerable confusion on this point.  
  220.         A cross-assembler is just like any other assembler except that it 
  221.         runs on some CPU other than the one for which it assembles code.  
  222.         For example, this package assembles 6502 or 65C02 source code 
  223.         into 6502 or 65C02 object code, but it runs on an 8080, a Z-80, 
  224.         an 8088, or whatever other CPU you happen to have a C compiler 
  225.         for.  The reason that cross-assemblers are useful is that you 
  226.         probably already have a CPU with memory, disk drives, a text 
  227.         editor, an operating system, and all sorts of hard-to-build or 
  228.         expensive facilities on hand.  A cross-assembler allows you to 
  229.         use these facilites to develop code for a 6502 or 65C02.
  230.  
  231.         This program requires one input file (your 6502 or 65C02 source 
  232.         code) and zero to two output files (the listing and the object).  
  233.         The input file MUST be specified, or the assembler will bomb on a 
  234.         fatal error.  The listing and object files are optional.  If no 
  235.         listing file is specified, no listing is generated, and if no 
  236.         object file is specified, no object is generated.  If the object 
  237.         file is specified, the object is written to this file in "Intel 
  238.         hexadecimal" format.
  239.  
  240.              The command line for the 6502 cross-assembler looks like 
  241.         this:
  242.  
  243.                   A65 source_file { -l list_file } { -o object_file }
  244.  
  245.         where the { } indicates that the specified item is optional.
  246.  
  247.              Some examples are in order:
  248.  
  249.              a65 test65.asm                          source:   test65.asm
  250.                                                      listing:  none
  251.                                                      object:   none
  252.  
  253.              a65 test65.asm -l test65.prn            source:   test65.asm
  254.                                                      listing:  test65.prn
  255.                                                      object:   none
  256.  
  257.              a65 test65.asm -o test65.hex            source:   test65.asm
  258.                                                      listing:  none
  259.                                                      object:   test65.hex
  260.  
  261.              a65 test65.asm -l test65.prn -o test65.hex
  262.                                                      source:   test65.asm
  263.                                                      listing:  test65.prn
  264.                                                      object:   test65.hex
  265.  
  266.              The order in which the source, listing, and object files are 
  267.         specified does not matter.  Note that no default file name exten-
  268.         sions are supplied by the assembler as this gives rise to porta-
  269.         bility problems.
  270.  
  271.  
  272.  
  273.  
  274.                                         3
  275.  
  276.  
  277.  
  278.              The 65C02 cross assembler works the same way except that the 
  279.         command is "a65c" instead of "a65".
  280.  
  281.  
  282.         2.0  Format of Cross-Assembler Source Lines
  283.  
  284.              The source file that the cross-assembler processes into a 
  285.         listing and an object is an ASCII text file that you can prepare 
  286.         with whatever editor you have at hand.  The most-significant 
  287.         (parity) bit of each character is cleared as the character is 
  288.         read from disk by the cross-assembler, so editors that set this 
  289.         bit (such as WordStar's document mode) should not bother this 
  290.         program.  All printing characters, the ASCII TAB character ($09), 
  291.         and newline character(s) are processed by the assembler.  All 
  292.         other characters are passed through to the listing file, but are 
  293.         otherwise ignored.
  294.  
  295.              The source file is divided into lines by newline char-
  296.         acter(s).  The internal buffers of the cross-assembler will 
  297.         accommodate lines of up to 255 characters which should be more 
  298.         than ample for almost any job.  If you must use longer lines, 
  299.         change the constant MAXLINE in file A65.H or A65C.H and recompile 
  300.         the cross-assembler.  Otherwise, you will overflow the buffers, 
  301.         and the program will mysteriously crash.
  302.  
  303.              Each source line is made up of three fields:  the label 
  304.         field, the opcode field, and the argument field.  The label field 
  305.         is optional, but if it is present, it must begin in column 1.  
  306.         The opcode field is optional, but if it is present, it must not 
  307.         begin in column 1.  If both a label and an opcode are present, 
  308.         one or more spaces and/or TAB characters must separate the two.  
  309.         If the opcode requires arguments, they are placed in the argument 
  310.         field which is separated from the opcode field by one or more 
  311.         spaces and/or TAB characters.  Finally, an optional comment can 
  312.         be added to the end of the line.  This comment must begin with a 
  313.         semicolon which signals the assembler to pass the rest of the 
  314.         line to the listing and otherwise ignore it.  Thus, the source 
  315.         line looks like this:
  316.  
  317.              {label}{ opcode{ arguments}}{;commentary}
  318.  
  319.         where the { } indicates that the specified item is optional.
  320.  
  321.              Some examples are in order:
  322.  
  323.           column 1
  324.              |
  325.              v
  326.              GRONK   LDA   OFFSET, X       ; This line has everything.
  327.                      STA   MAILBOX         ; This line has no label.
  328.              BEEP                          ; This line has no opcode.
  329.              ; This line has no label and no opcode.
  330.  
  331.              ; The previous line has nothing at all.
  332.                      END                   ; This line has no argument.
  333.  
  334.  
  335.  
  336.                                         4
  337.  
  338.  
  339.  
  340.         2.1  Labels
  341.  
  342.              A label is any sequence of alphabetic or numeric characters 
  343.         starting with an alphabetic.  The legal alphabetics are:
  344.  
  345.                     ! & , . : ? [ \ ] ^ _  ` { | }  ~  A-Z  a-z
  346.  
  347.         The numeric characters are the digits 0-9.  Note that "A" is not 
  348.         the same as "a" in a label.  This can explain mysterious U 
  349.         (undefined label) errors occurring when a label appears to be 
  350.         defined.
  351.  
  352.              A label is permitted on any line except a line where the 
  353.         opcode is IF, ELSE, or ENDIF.  The label is assigned the value of 
  354.         the assembly program counter before any of the rest of the line 
  355.         is processed except when the opcode is EQU, ORG, or SET.
  356.  
  357.              Labels can have the same name as opcodes, but they cannot
  358.         have the same name as operators or registers.  The reserved 
  359.         (operator and register) names are:
  360.  
  361.              A         AND       EQ        GE        GT        HIGH
  362.              LE        LT        LOW       MOD       NE        NOT
  363.              OR        SHL       SHR       X         XOR       Y
  364.  
  365.              If a label is used in an expression before it is assigned a 
  366.         value, the label is said to be "forward-referenced."  For 
  367.         example:
  368.  
  369.              L1   EQU  L2 + 1   ; L2 is forward-referenced here.
  370.              L2
  371.              L3   EQU  L2 + 1   ; L2 is not forward-referenced here.
  372.  
  373.  
  374.         2.2  Numeric Constants
  375.  
  376.              Numeric constants can be formed in two ways:  the Intel 
  377.         convention or the Motorola convention.  The cross-assembler 
  378.         supports both.
  379.  
  380.              An Intel-type numeric constant starts with a numeric 
  381.         character (0-9), continues with zero or more digits (0-9, A-F), 
  382.         and ends with an optional base designator.  The base designators 
  383.         are H for hexadecimal, none or D for decimal, O or Q for octal, 
  384.         and B for binary.  The hex digits a-f are converted to upper case 
  385.         by the assembler.  Note that an Intel-type numeric constant 
  386.         cannot begin with A-F as it would be indistinguishable from a 
  387.         label.  Thus, all of the following evaluate to 255 (decimal):
  388.  
  389.                    0ffH   255   255D   377O   377Q   11111111B
  390.  
  391.              A Motorola-type numeric constant starts with a base 
  392.         designator and continues with a string of one or more digits.  
  393.         The base designators are $ for hexadecimal, none for decimal, @ 
  394.         for octal, and % for binary.  As with Intel-type numeric 
  395.  
  396.  
  397.  
  398.                                         5
  399.  
  400.  
  401.  
  402.         constants, a-f are converted to upper case by the assembler.  
  403.         Thus, all of the following evaluate to 255 (decimal):
  404.  
  405.                           $ff   255   @377   %11111111
  406.  
  407.              If a numeric constant has a value that is too large to fit 
  408.         into a 16-bit word, it will be truncated on the left to make it 
  409.         fit.  Thus, for example, $123456 is truncated to $3456.
  410.  
  411.  
  412.         2.3  String Constants
  413.  
  414.              A string constant is zero or more characters enclosed in 
  415.         either single quotes (' ') or double quotes (" ").  Single quotes 
  416.         only match single quotes, and double quotes only match double 
  417.         quotes, so if you want to put a single quote in a string, you can 
  418.         do it like this:  "'".  In all contexts except the FCC statement, 
  419.         the first character or two of the string constant are all that 
  420.         are used.  The rest is ignored.  Noting that the ASCII codes for 
  421.         "A" and "B" are $41 and $42, respectively, will explain the 
  422.         following examples:
  423.  
  424.                   "" and ''           evaluate to $0000
  425.                   "A" and 'A'         evaluate to $0041
  426.                   "AB"                evaluates to $4142
  427.  
  428.         Note that the null string "" is legal and evaluates to $0000.
  429.  
  430.  
  431.         2.4  Expressions
  432.  
  433.              An expression is made up of labels, numeric constants, and 
  434.         string constants glued together with arithmetic operators, 
  435.         logical operators, and parentheses in the usual way that 
  436.         algebraic expressions are made.  Operators have the following 
  437.         fairly natural order of precedence:
  438.  
  439.              Highest        anything in parentheses
  440.                             unary +, unary -
  441.                             *, /, MOD, SHL, SHR
  442.                             binary +, binary -
  443.                             LT, LE, EQ, GE, GT, NE
  444.                             NOT
  445.                             AND
  446.                             OR, XOR
  447.              Lowest         HIGH, LOW
  448.  
  449.              A few notes about the various operators are in order:
  450.  
  451.              1)   The remainder operator MOD yields the remainder from 
  452.                   dividing its left operand by its right operand.
  453.  
  454.              2)   The shifting operators SHL and SHR shift their left 
  455.                   operand to the left or right the number of bits 
  456.                   specified by their right operand.
  457.  
  458.  
  459.  
  460.                                         6
  461.  
  462.  
  463.  
  464.  
  465.              3)   The relational operators LT, LE, EQ, GE, GT, and NE can 
  466.                   also be written as <, <= or =<, =, >= or =>, and <> or 
  467.                   ><, respectively.  They evaluate to $FFFF if the 
  468.                   statement is true, 0 otherwise.
  469.  
  470.              4)   The logical opeators NOT, AND, OR, and XOR do bitwise 
  471.                   operations on their operand(s).
  472.  
  473.              5)   HIGH and LOW extract the high or low byte, of an 
  474.                   expression.
  475.  
  476.              6)   The special symbol * can be used in place of a label or 
  477.                   constant to represent the value of the program counter 
  478.                   before any of the current line has been processed.
  479.  
  480.              Some examples are in order at this point:
  481.  
  482.              2 + 3 * 4                          evaluates to 14
  483.              (2 + 3) * 4                        evaluates to 20
  484.              NOT %11110000 XOR %00001010        evaluates to %00000101
  485.              HIGH $1234 SHL 1                   evaluates to $0024
  486.              @001 EQ 0                          evaluates to 0
  487.              @001 = 2 SHR 1                     evaluates to $FFFF
  488.  
  489.              All arithmetic is unsigned with overflow from the 16-bit 
  490.         word ignored.  Thus:
  491.  
  492.              32768 * 2                          evaluates to 0
  493.  
  494.  
  495.         3.0  Machine Opcodes
  496.  
  497.              The opcodes of the 6502 and 65C02 processors are listed in 
  498.         the following table along with the various legal argument field 
  499.         formats.  An X in the table indicates that the argument format is 
  500.         legal with the opcode on both processors.  A * in the table 
  501.         indicates that the argument is legal only on the 65C02 processor.  
  502.         Opcodes that are unique to the 65C02 are flagged with a *.
  503.  
  504.         Opcode                   Argument Format
  505.                   1    2    3    4    5    6    7    8    9    10   11
  506.         ADC       X         *    X         X    X    X    X
  507.         AND       X         *    X         X    X    X    X
  508.         ASL       X                   X    X
  509.         BBR *                                                       X
  510.         BBS *                                                       X
  511.         BCC            X
  512.         BCS            X
  513.         BEQ            X
  514.         BIT       X              *         *
  515.         BMI            X
  516.         BNE            X
  517.         BPL            X
  518.         BRA *          X
  519.  
  520.  
  521.  
  522.                                         7
  523.  
  524.  
  525.  
  526.         Opcode                   Argument Format
  527.                   1    2    3    4    5    6    7    8    9    10   11
  528.         BRK
  529.         BVC            X
  530.         BVS            X
  531.         CLC
  532.         CLD
  533.         CLI
  534.         CLV
  535.         CMP       X         *    X         X    X    X    X
  536.         CPX       X              X
  537.         CPY       X              X
  538.         DEC       X                   *    X
  539.         INC       X                   *    X
  540.         INX
  541.         INY
  542.         JMP       X         X                        *
  543.         JSR       X
  544.         LDA       X         *    X         X    X    X    X
  545.         LDX       X              X              X
  546.         LDY       X              X         X
  547.         LSR       X                   X    X
  548.         NOP
  549.         ORA       X         *    X         X    X    X    X
  550.         PHA
  551.         PHP
  552.         PHX *
  553.         PHY *
  554.         PLA
  555.         PLP
  556.         PLX *
  557.         PLY *
  558.         RMB *                                                  X
  559.         ROL       X                   X    X
  560.         ROR       X                   X    X
  561.         RTI
  562.         RTS
  563.         SBC       X         *    X         X    X    X    X
  564.         SEC
  565.         SED
  566.         SEI
  567.         SMB *                                                  X
  568.         STA       X         *              X    X    X    X
  569.         STX       X                             X
  570.         STY       X                        X
  571.         STZ *     X                        X
  572.         TAX
  573.         TAY
  574.         TRB *     X
  575.         TSB *     X
  576.         TSX
  577.         TXA
  578.         TXS
  579.         TYA
  580.  
  581.  
  582.  
  583.  
  584.                                         8
  585.  
  586.  
  587.  
  588.              The argument field formats are:
  589.  
  590.              1)   expression          where expression arbitrary is 
  591.                                       (except RMB and SMB where 
  592.                                       expression is 0 thru 255)
  593.  
  594.              2)   expression          where the difference between 
  595.                                       expression and the beginning of the 
  596.                                       next instruction must be -128 thru 
  597.                                       127
  598.  
  599.              3)   (expression)        where expression is arbitrary
  600.  
  601.              4)   #expression         where expression is -128 thru 255
  602.  
  603.              5)   A                   Note that the A may be attached to 
  604.                                       the opcode.  Thus "LSR A" and 
  605.                                       "LSRA" are the same.
  606.  
  607.              6)   expression, X       where expression is arbitrary 
  608.                                       (except STY where expression is 0 
  609.                                       thru 255)
  610.  
  611.              7)   expression, Y       where expression is 0 thru 255 
  612.                                       (except LDX and STX where 
  613.                                       expression is arbitrary)
  614.  
  615.              8)   (expression, X)     where expression is 0 thru 255 
  616.                                       (except JMP where expression is 
  617.                                       arbitrary)
  618.  
  619.              9)   (expression), Y     where expression is 0 thru 255
  620.  
  621.              10)  bit, expression     where bit is 0 thru 7 and 
  622.                                       expression is 0 thru 255
  623.  
  624.              11)  bit, expr1, expr2   where bit is 0 thru 7, expr1 is 0 
  625.                                       thru 255, and expr2 follows the 
  626.                                       same rule as 2) above
  627.  
  628.  
  629.         4.0  Pseudo Opcodes
  630.  
  631.              Unlike 6502/65C02 opcodes, pseudo opcodes (pseudo ops) do not 
  632.         represent machine instructions.  They are, rather, directives to 
  633.         the assembler.  These directives require various numbers and 
  634.         types of arguments.  They will be listed individually below.
  635.  
  636.  
  637.         4.1  Pseudo-ops -- END
  638.  
  639.              The END pseudo-op tells the assembler that the source 
  640.         program is over.  Any further lines of the source file are 
  641.         ignored and not passed on to the listing.  If an argument is 
  642.         added to the END statement, the value of the argument will be 
  643.  
  644.  
  645.  
  646.                                         9
  647.  
  648.  
  649.  
  650.         placed in the execution address slot in the Intel hex object 
  651.         file.  The execution address defaults to the program counter 
  652.         value at the point where the END was encountered.  Thus, to 
  653.         specify that the program starts at label START, the END statement 
  654.         would be:
  655.  
  656.                        END       START
  657.  
  658.              If end-of-file is encountered on the source file before an 
  659.         END statement is reached, the assembler will add an END statement 
  660.         to the listing and flag it with a * (missing statement) error.
  661.  
  662.  
  663.         4.2  Pseudo-ops -- EQU
  664.  
  665.              The EQU pseudo-op is used to assign a specific value to a 
  666.         label, thus the label on this line is REQUIRED.  Once the value 
  667.         is assigned, it cannot be reassigned by writing the label in 
  668.         column 1, by another EQU statement, or by a SET statement.  Thus, 
  669.         for example, the following statement assigns the value 2 to the 
  670.         label TWO:
  671.  
  672.              TWO       EQU       1 + 1
  673.  
  674.              The expression in the argument field must contain no forward 
  675.         references.
  676.  
  677.  
  678.         4.3  Pseudo-ops -- FCB
  679.  
  680.              The FCB (Form Constant Bytes) pseudo-op allows arbitrary 
  681.         bytes to be spliced into the object code.  Its argument is a 
  682.         chain of zero or more expressions that evaluate to -128 thru 255 
  683.         separated by commas.  If a comma occurs with no preceding 
  684.         expression, a $00 byte is spliced into the object code.  The 
  685.         sequence of bytes $FE $FF, $00, $01, $02 could be spliced into 
  686.         the code with the following statement:
  687.  
  688.                        FCB       -2, -1, , 1, 2
  689.  
  690.  
  691.         4.4  Pseudo-ops -- FCC
  692.  
  693.              The FCC (Form Constant Characters) pseudo-op allows 
  694.         character strings to be spliced into the object code.  Its 
  695.         argument is a chain of zero or more string constants separated by 
  696.         blanks, tabs, or commas.  If a comma occurs with no preceding 
  697.         string constant, an S (syntax) error results.  The string 
  698.         contants are not truncated to two bytes, but are instead copied 
  699.         verbatim into the object code.  Null strings result in no bytes 
  700.         of code.  The message "Kaboom!!" could be spliced into the code 
  701.         with the following statement:
  702.  
  703.                        FCC       "Kaboom!!"     ;This is 8 bytes of code.
  704.  
  705.  
  706.  
  707.  
  708.                                        10
  709.  
  710.  
  711.  
  712.  
  713.         4.5  Pseudo-ops -- FDB
  714.  
  715.              The FDB (Form Double Bytes) pseudo-op allows 16-bit words to 
  716.         be spliced into the object code.  Its argument is a chain of zero 
  717.         or more expressions separated by commas.  If a comma occurs with 
  718.         no preceding expression, a word of $0000 is spliced into the 
  719.         code.  The word is placed into memory low byte in low address, 
  720.         high byte in high address as per standard MOS Technology order.  
  721.         The sequence of bytes $FE $FF $00 $00 $01 $02 could be spliced 
  722.         into the code with the following statement:
  723.  
  724.                        FDB       $FFFE, , $0201
  725.  
  726.  
  727.         4.6  Pseudo-ops -- IF, ELSE, ENDI
  728.  
  729.              These three pseudo-ops allow the assembler to choose whether 
  730.         or not to assemble certain blocks of code based on the result of 
  731.         an expression.  Code that is not assembled is passed through to 
  732.         the listing but otherwise ignored by the assembler.  The IF 
  733.         pseudo-op signals the beginning of a conditionally assembled 
  734.         block.  It requires one argument that may contain no forward 
  735.         references.  If the value of the argument is non-zero, the block 
  736.         is assembled.  Otherwise, the block is ignored.  The ENDI pseudo-
  737.         op signals the end of the conditionally assembled block.  For 
  738.         example:
  739.  
  740.                        IF   EXPRESSION     ;This whole thing generates
  741.                        FCB  $01, $02, $03  ;  no code whatsoever if
  742.                        ENDI                ;  EXPRESSION is zero.
  743.  
  744.         The ELSE pseudo-op allows the assembly of either one of two 
  745.         blocks, but not both.  The following two sequences are 
  746.         equivalent:
  747.  
  748.                        IF   EXPRESSION
  749.                        ... some stuff ...
  750.                        ELSE
  751.                        ... some more stuff ...
  752.                        ENDI
  753.  
  754.              TEMP_LAB  SET  EXPRESSION
  755.                        IF   TEMP_LAB NE 0
  756.                        ... some stuff ...
  757.                        ENDI
  758.                        IF   TEMP_LAB EQ 0
  759.                        ... some more stuff ...
  760.                        ENDI
  761.  
  762.              The pseudo-ops in this group do NOT permit labels to exist 
  763.         on the same line as the status of the label (ignored or not) 
  764.         would be ambiguous.
  765.  
  766.  
  767.  
  768.  
  769.                                        11
  770.  
  771.  
  772.  
  773.              All IF statements (even those in ignored conditionally 
  774.         assembled blocks) must have corresponding ENDI statements and all 
  775.         ELSE and ENDI statements must have a corresponding IF statement.
  776.  
  777.              IF blocks can be nested up to 16 levels deep before the 
  778.         assembler dies of a fatal error.  This should be adequate for any 
  779.         conceivable job, but if you need more, change the constant 
  780.         IFDEPTH in file A65.H and recompile the assembler.
  781.  
  782.  
  783.         4.7  Pseudo-ops -- INCL
  784.  
  785.              The INCL pseudo-op is used to splice the contents of another 
  786.         file into the current file at assembly time.  The name of the 
  787.         file to be INCLuded is specified as a normal string constant, so 
  788.         the following line would splice the contents of file "const.def" 
  789.         into the source code stream:
  790.  
  791.                        INCL      "const.def"
  792.  
  793.              INCLuded files may, in turn, INCLude other files until four 
  794.         files are open simultaneously.  This limit should be enough for 
  795.         any conceivable job, but if you need more, change the constant 
  796.         FILES in file A65.H or A65C.H and recompile the assembler.  
  797.  
  798.  
  799.         4.8  Pseudo-ops -- ORG
  800.  
  801.              The ORG pseudo-op is used to set the assembly program 
  802.         counter to a particular value.  The expression that defines this 
  803.         value may contain no forward references.  The default initial 
  804.         value of the assembly program counter is $0000.  The following 
  805.         statement would change the assembly program counter to $F000:
  806.  
  807.                        ORG       $F000
  808.  
  809.              If a label is present on the same line as an ORG statement, 
  810.         it is assigned the new value of the assembly program counter.
  811.  
  812.  
  813.         4.9  Pseudo-ops -- PAGE
  814.  
  815.              The PAGE pseudo-op always causes an immediate page ejection 
  816.         in the listing by inserting a form feed ('\f') character before 
  817.         the next line.  If an argument is specified, the argument 
  818.         expression specifies the number of lines per page in the listing.  
  819.         Legal values for the expression are any number except 1 and 2.  A 
  820.         value of 0 turns the listing pagination off.  Thus, the following 
  821.         statement cause a page ejection and would divide the listing into 
  822.         60-line pages:
  823.  
  824.                        PAGE      60
  825.  
  826.  
  827.  
  828.  
  829.  
  830.                                        12
  831.  
  832.  
  833.  
  834.         4.10 Pseudo-ops -- RMB
  835.  
  836.              The RMB (Reserve Memory Bytes) pseudo-op is used to reserve 
  837.         a block of storage for program variables, or whatever.  This 
  838.         storage is not initialized in any way, so its value at run time 
  839.         will usually be random.  The argument expression (which may
  840.         contain no forward references) is added to the assembly program 
  841.         counter.  The following statement would reserve 10 bytes of 
  842.         storage called "STORAGE":
  843.  
  844.              STORAGE   RMB       10
  845.  
  846.  
  847.         4.11 Pseudo-ops -- SET
  848.  
  849.              The SET pseudo-op functions like the EQU pseudo-op except 
  850.         that the SET statement can reassign the value of a label that has 
  851.         already been assigned by another SET statement.  Like the EQU 
  852.         statement, the argument expression may contain no forward 
  853.         references.  A label defined by a SET statement cannot be 
  854.         redefined by writing it in column 1 or with an EQU statement.  
  855.         The following series of statements would set the value of label 
  856.         "COUNT" to 1, 2, then 3:
  857.  
  858.              COUNT     SET       1
  859.              COUNT     SET       2
  860.              COUNT     SET       3
  861.  
  862.  
  863.         4.12 Pseudo-ops -- TITL
  864.  
  865.              The TITL pseudo-op sets the running title for the listing.  
  866.         The argument field is required and must be a string constant, 
  867.         though the null string ("") is legal.  This title is printed 
  868.         after every page ejection in the listing, therefore, if page 
  869.         ejections have not been forced by the PAGE pseudo-op, the title 
  870.         will never be printed.  The following statement would print the 
  871.         title "Random Bug Generator -- Ver 3.14159" at the top of every 
  872.         page of the listing:
  873.  
  874.                        TITL      "Random Bug Generator -- Ver 3.14159"
  875.  
  876.  
  877.         5.0  Assembly Errors
  878.  
  879.              When a source line contains an illegal construct, the line 
  880.         is flagged in the listing with a single-letter code describing 
  881.         the error.  The meaning of each code is listed below.  In 
  882.         addition, a count of the number of lines with errors is kept and 
  883.         printed on the C "stderr" device (by default, the console) after 
  884.         the END statement is processed.  If more than one error occurs in 
  885.         a given line, only the first is reported.  For example, the 
  886.         illegal label "=$#*'(" would generate the following listing line:
  887.  
  888.              L  0000   FF 00 00      =$#*'(     CPX       #0
  889.  
  890.  
  891.  
  892.                                        13
  893.  
  894.  
  895.  
  896.  
  897.  
  898.         5.1  Error * -- Illegal or Missing Statement
  899.  
  900.              This error occurs when either:
  901.  
  902.              1)   the assembler reaches the end of the source file 
  903.                   without seeing an END statement, or
  904.  
  905.              2)   an END statement is encountered in an INCLude file.
  906.  
  907.              If you are "sure" that the END statement is present when the 
  908.         assembler thinks that it is missing, it probably is in the 
  909.         ignored section of an IF block.  If the END statement is missing, 
  910.         supply it.  If the END statement is in an INCLude file, delete 
  911.         it.
  912.  
  913.  
  914.         5.2  Error ( -- Parenthesis Imbalance
  915.  
  916.              For every left parenthesis, there must be a right paren-
  917.         thesis.  Count them.
  918.  
  919.  
  920.         5.3  Error " -- Missing Quotation Mark
  921.  
  922.              Strings have to begin and end with either " or '.  Remember 
  923.         that " only matches " while ' only matches '.
  924.  
  925.  
  926.         5.4  Error A -- Illegal Addressing Mode
  927.  
  928.              This error occurs if an addressing mode is specified in the 
  929.         argument field that is not legal with the opcode in the opcode 
  930.         field.  See the table in section 3.0 for the list of legal 
  931.         combinations.
  932.  
  933.  
  934.         5.5  Error B -- Branch Target Too Distant
  935.  
  936.              The 6502 relative branch instructions will only reach -128 
  937.         to +127 bytes from the first byte of the instruction following 
  938.         the branch instruction.  If this error occurs, the source code 
  939.         will have to be rearranged to shorten the distance to the branch 
  940.         target address or a long branch instruction that will reach 
  941.         anywhere (JMP) will have to be used.
  942.  
  943.  
  944.         5.6  Error D -- Illegal Digit
  945.  
  946.              This error occurs if a digit greater than or equal to the 
  947.         base of a numeric constant is found.  For example, a 2 in a 
  948.         binary number would cause a D error.  Especially, watch for 8 or 
  949.         9 in an octal number.
  950.  
  951.  
  952.  
  953.  
  954.                                        14
  955.  
  956.  
  957.  
  958.  
  959.         5.7  Error E -- Illegal Expression
  960.  
  961.              This error occurs because of:
  962.  
  963.              1)   a missing expression where one is required
  964.  
  965.              2)   a unary operator used as a binary operator or vice-
  966.                   versa
  967.  
  968.              3)   a missing binary operator
  969.  
  970.              4)   a SHL or SHR count that is not 0 thru 15
  971.  
  972.  
  973.         5.8  Error I -- IF-ENDI Imbalance
  974.  
  975.              For every IF there must be a corresponding ENDI.  If this 
  976.         error occurs on an ELSE or ENDI statement, the corresponding IF 
  977.         is missing.  If this error occurs on an END statement, one or 
  978.         more ENDI statements are missing.
  979.  
  980.  
  981.         5.9  Error L -- Illegal Label
  982.  
  983.              This error occurs because of:
  984.  
  985.              1)   a non-alphabetic in column 1
  986.  
  987.              2)   a reserved word used as a label
  988.  
  989.              3)   a missing label on an EQU or SET statement
  990.  
  991.              4)   a label on an IF, ELSE, or ENDI statement
  992.  
  993.  
  994.         5.10 Error M -- Multiply Defined Label
  995.  
  996.              This error occurs because of:
  997.  
  998.              1)   a label defined in column 1 or with the EQU statement 
  999.                   being redefined
  1000.  
  1001.              2)   a label defined by a SET statement being redefined 
  1002.                   either in column 1 or with the EQU statement
  1003.  
  1004.              3)   the value of the label changing between assembly passes
  1005.  
  1006.  
  1007.         5.11 Error O -- Illegal Opcode
  1008.  
  1009.              The opcode field of a source line may contain only a valid 
  1010.         machine opcode, a valid pseudo-op, or nothing at all.  Anything 
  1011.         else causes this error.
  1012.  
  1013.  
  1014.  
  1015.  
  1016.                                        15
  1017.  
  1018.  
  1019.  
  1020.  
  1021.         5.12 Error P -- Phasing Error
  1022.  
  1023.              This error occurs because of:
  1024.  
  1025.              1)   a forward reference in a EQU, ORG, RMB, or SET 
  1026.                   statement
  1027.  
  1028.              2)   a label disappearing between assembly passes
  1029.  
  1030.  
  1031.         5.13 Error R -- Illegal Register
  1032.  
  1033.              This error occurs either when the register designator A or B 
  1034.         is used with a machine opcode that does not permit it, or when 
  1035.         the register designator is missing with a machine opcode that 
  1036.         requires it.
  1037.  
  1038.  
  1039.         5.14 Error S -- Illegal Syntax
  1040.  
  1041.              This error means that an argument field is scrambled.  Sort 
  1042.         the mess out and reassemble.
  1043.  
  1044.  
  1045.         5.15 Error T -- Too Many Arguments
  1046.  
  1047.              This error occurs if there are more items (expressions, 
  1048.         register designators, etc.) in the argument field than the opcode 
  1049.         or pseudo-op requires.  The assembler ignores the extra items but 
  1050.         issues this error in case something is really mangled.
  1051.  
  1052.  
  1053.         5.16 Error U -- Undefined Label
  1054.  
  1055.              This error occurs if a label is referenced in an expression 
  1056.         but not defined anywhere in the source program.  If you are 
  1057.         "sure" you have defined the label, note that upper and lower case 
  1058.         letters in labels are different.  Defining "LABEL" does not 
  1059.         define "Label."
  1060.  
  1061.  
  1062.         5.17 Error V -- Illegal Value
  1063.  
  1064.              This error occurs because:
  1065.  
  1066.              1)   an index offset is not 0 thru 255, or
  1067.  
  1068.              2)   an 8-bit immediate value is not -128 thru 255, or
  1069.  
  1070.              3)   an FCB argument is not -128 thru 255, or
  1071.  
  1072.              4)   an INCL argument refers to a file that does not exist.
  1073.  
  1074.  
  1075.  
  1076.  
  1077.  
  1078.                                        16
  1079.  
  1080.  
  1081.  
  1082.         6.0  Warning Messages
  1083.  
  1084.              Some errors that occur during the parsing of the cross-
  1085.         assembler command line are non-fatal.  The cross-assembler flags 
  1086.         these with a message on the C "stdout" device (by default, the 
  1087.         console) beginning with the word "Warning."  The messages are 
  1088.         listed below:
  1089.  
  1090.  
  1091.         6.1  Warning -- Illegal Option Ignored
  1092.  
  1093.              The only options that the cross-assembler knows are -l and  
  1094.         -o.  Any other command line argument beginning with - will draw 
  1095.         this error.
  1096.  
  1097.  
  1098.         6.2  Warning -- -l Option Ignored -- No File Name
  1099.         6.3  Warning -- -o Option Ignored -- No File Name
  1100.  
  1101.              The -l and -o options require a file name to tell the 
  1102.         assembler where to put the listing file or object file.  If this 
  1103.         file name is missing, the option is ignored.
  1104.  
  1105.  
  1106.         6.4  Warning -- Extra Source File Ignored
  1107.  
  1108.              The cross-assembler will only assemble one file at a time, 
  1109.         so source file names after the first are ignored.  To assemble a 
  1110.         second file, invoke the assembler again.  Note that under CP/M-
  1111.         80, the old trick of reexecuting a core image will NOT work as 
  1112.         the initialized data areas are not reinitialized prior to the 
  1113.         second run.
  1114.  
  1115.  
  1116.         6.5  Warning -- Extra Listing File Ignored
  1117.         6.6  Warning -- Extra Object File Ignored
  1118.  
  1119.              The cross-assembler will only generate one listing and one 
  1120.         object file per assembly run, so -l and -o options after the 
  1121.         first are ignored.
  1122.  
  1123.  
  1124.         7.0  Fatal Error Messages
  1125.  
  1126.              Several errors that occur during the parsing of the cross-
  1127.         assembler command line or during the assembly run are fatal.  The 
  1128.         cross-assembler flags these with a message on the C "stdout" 
  1129.         device (by default, the console) beginning with the words "Fatal 
  1130.         Error."  The messages are explained below:
  1131.  
  1132.  
  1133.         7.1  Fatal Error -- No Source File Specified
  1134.  
  1135.              This one is self-explanatory.  The assembler does not know 
  1136.         what to assemble.
  1137.  
  1138.  
  1139.  
  1140.                                        17
  1141.  
  1142.  
  1143.  
  1144.  
  1145.  
  1146.         7.2  Fatal Error -- Source File Did Not Open
  1147.  
  1148.              The assembler could not open the source file.  The most 
  1149.         likely cause is that the source file as specified on the command 
  1150.         line does not exist.  On larger systems, there could also be 
  1151.         priviledge violations.  Rarely, a read error in the disk 
  1152.         directory could cause this error.
  1153.  
  1154.  
  1155.         7.3  Fatal Error -- Listing File Did Not Open
  1156.         7.4  Fatal Error -- Object File Did Not Open
  1157.  
  1158.              This error indicates either a defective listing or object 
  1159.         file name or a full disk directory.  Correct the file name or 
  1160.         make more room on the disk.
  1161.  
  1162.  
  1163.         7.5  Fatal Error -- Error Reading Source File
  1164.  
  1165.              This error generally indicates a read error in the disk data 
  1166.         space.  Use your backup copy of the source file (You do have one, 
  1167.         don't you?) to recreate the mangled file and reassemble.
  1168.  
  1169.  
  1170.         7.6  Fatal Error -- Disk or Directory Full
  1171.  
  1172.              This one is self-explanatory.  Some more space must be found 
  1173.         either by deleting files or by using a disk with more room on it.
  1174.  
  1175.  
  1176.         7.7  Fatal Error -- File Stack Overflow
  1177.  
  1178.              This error occurs if you exceed the INCLude file limit of 
  1179.         four files open simultaneously.  This limit can be increased by 
  1180.         increasing the constant FILES in file A65.H or A65C.H and 
  1181.         recompiling the cross-assembler.
  1182.  
  1183.  
  1184.         7.8  Fatal Error -- If Stack Overflow
  1185.  
  1186.              This error occurs if you exceed the nesting limit of 16 IF 
  1187.         blocks.  This limit can be increased by increasing the constant 
  1188.         IFDEPTH in file A65.H or A65C.H and recompiling the cross-
  1189.         assembler.
  1190.  
  1191.  
  1192.         7.9  Fatal Error -- Too Many Symbols
  1193.  
  1194.              Congratulations!  You have run out of memory.  The space for 
  1195.         the cross-assembler's symbol table is allocated at run-time using 
  1196.         the C library function alloc(), so the cross-assembler will use 
  1197.         all available memory.  The only solutions to this problem are to 
  1198.         lessen the number of labels in the source program, to use a 
  1199.  
  1200.  
  1201.  
  1202.                                        18
  1203.  
  1204.  
  1205.  
  1206.         larger memory model (MSDOS/PCDOS systems only), or to add more 
  1207.         memory to your machine.
  1208.  
  1209.  
  1210.  
  1211.  
  1212.  
  1213.  
  1214.  
  1215.  
  1216.  
  1217.  
  1218.  
  1219.  
  1220.  
  1221.  
  1222.  
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260.  
  1261.  
  1262.  
  1263.                                        19
  1264.