home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / CROSSASM / SVASM02.ARC / SVASM02.DOC < prev    next >
Encoding:
Text File  |  1988-05-24  |  42.6 KB  |  947 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.                                 S V A S M 0 2
  11.  
  12.  
  13.  
  14.  
  15.  
  16.                     A two-pass cross-referencing assembler
  17.  
  18.                                      for
  19.  
  20.                        6502 and 65C02 microproccessors
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.                                   Written by
  30.  
  31.                               John Michne, KM2H
  32.                               10 Evergreen Ave.
  33.                         Clifton Park, New York  12065
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.                                  Version 1.0
  42.  
  43.                                   May, 1988
  44.  
  45.                                 S V A S M 0 2
  46.  
  47.                    USER'S MANUAL - Version 1.0 - May, 1988
  48.  
  49.                               TABLE OF CONTENTS
  50.  
  51.  
  52.           INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . 1
  53.  
  54.           RUNNING THE SVASM02 ASSEMBLER. . . . . . . . . . . . . . 1
  55.             Source filename. . . . . . . . . . . . . . . . . . . . 1
  56.             Object filename. . . . . . . . . . . . . . . . . . . . 1
  57.             Print filename . . . . . . . . . . . . . . . . . . . . 2
  58.  
  59.           INPUT FILE LINE STRUCTURE. . . . . . . . . . . . . . . . 2
  60.             Label field. . . . . . . . . . . . . . . . . . . . . . 2
  61.             Instruction field. . . . . . . . . . . . . . . . . . . 2
  62.             Argument field . . . . . . . . . . . . . . . . . . . . 3
  63.             Comment field. . . . . . . . . . . . . . . . . . . . . 3
  64.  
  65.           ARITHMETIC . . . . . . . . . . . . . . . . . . . . . . . 3
  66.             Symbols. . . . . . . . . . . . . . . . . . . . . . . . 3
  67.             Program counter. . . . . . . . . . . . . . . . . . . . 3
  68.             Constants. . . . . . . . . . . . . . . . . . . . . . . 3
  69.             Expressions. . . . . . . . . . . . . . . . . . . . . . 4
  70.             Arithmetic operators . . . . . . . . . . . . . . . . . 4
  71.             Logical operators. . . . . . . . . . . . . . . . . . . 5
  72.  
  73.           ADDRESSING MODE SYNTAX . . . . . . . . . . . . . . . . . 5
  74.             6502 Addressing modes. . . . . . . . . . . . . . . . . 5
  75.             65C02 Additional addressing modes. . . . . . . . . . . 7
  76.  
  77.           ASSEMBLER DIRECTIVES (Psuedo-ops). . . . . . . . . . . . 8
  78.             .BYTE. . . . . . . . . . . . . . . . . . . . . . . . . 8
  79.             .WORD. . . . . . . . . . . . . . . . . . . . . . . . . 8
  80.             .CMOS. . . . . . . . . . . . . . . . . . . . . . . . . 9
  81.             .END . . . . . . . . . . . . . . . . . . . . . . . . . 9
  82.             .LIST. . . . . . . . . . . . . . . . . . . . . . . . . 9
  83.             .NOLIST. . . . . . . . . . . . . . . . . . . . . . . . 9
  84.             .INCLUDE . . . . . . . . . . . . . . . . . . . . . . . 9
  85.             .PAGE. . . . . . . . . . . . . . . . . . . . . . . . . 9
  86.             .WIDTH . . . . . . . . . . . . . . . . . . . . . . . .10
  87.             .PRINTC. . . . . . . . . . . . . . . . . . . . . . . .10
  88.             .IF, .ELSE, .ENDIF, .LISTF . . . . . . . . . . . . . .10
  89.  
  90.           ERRORS . . . . . . . . . . . . . . . . . . . . . . . . .11
  91.             Fatal errors . . . . . . . . . . . . . . . . . . . . .11
  92.             Invocation errors. . . . . . . . . . . . . . . . . . .11
  93.             Assembler errors . . . . . . . . . . . . . . . . . . .12
  94.  
  95.           APPENDIX A
  96.             SVASM02 LST Output File Description. . . . . . . . . .14
  97.  
  98.           APPENDIX B
  99.             SVASM02 HEX Object File Description. . . . . . . . . .16
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.                               COPYRIGHT NOTICE                 
  109.  
  110.  
  111.             The  SVASM02  program and User's Manual are Copyright 
  112.             1988 by John Michne.   Both may be freely copied  and 
  113.             distributed for PRIVATE,  NON-PROFIT,  NON-COMMERCIAL 
  114.             USE ONLY.   The SVASM02 program and User's Manual may 
  115.             not  be copied and distributed commercially except as
  116.             arranged with the author.
  117.  
  118.             The   author  makes  no  warranty  or  guarantee   of 
  119.             suitability of SVASM02 for any purpose,  and will not 
  120.             be   held   liable  for  any   damages,   direct   or 
  121.             consequential,  that may arise due to the use of this 
  122.             software.
  123. INTRODUCTION
  124.  
  125. SVASM02  is  a  two-pass  cross-referencing  assembler  for  6502  and   65C02 
  126. microprocessors.   It  runs in IBM and compatible machines,  and has been  run 
  127. under both PC-DOS (Version 3.1) and MSDOS (Version 2.11).  Since it is written 
  128. in  8086  assembly language,  memory requirerments are minimal  and  execution 
  129. speed is optimum.   It is approximately 12K long, and will run in as little as 
  130. 64K.   The  original  Version  1.0 distribution was via GEnie  to  the  public 
  131. domain.   This was primarily to get the program out to where it may be useful, 
  132. and get it tested under conditions of actual use by programmers other than the 
  133. author.   Future  versions will be distributed to registered users only.   See 
  134. the file INFORMAL.DOC for details.
  135.  
  136. This document is not intended to teach assembly language programming.  It will 
  137. fully  explain  the  operation of the SVASM02  assembler,  and  with  numerous 
  138. examples, will guide the user to efficient and successful assembly of 6502 and 
  139. 65C02 code.
  140.  
  141.  
  142. RUNNING THE SVASM02 ASSEMBLER
  143.  
  144. SVASM02  is invoked in the usual manner - merely type the program  name.   The 
  145. screen will clear and a sign-on line will appear, followed by a prompt for the 
  146. input file name.  It looks like this:
  147.  
  148.      SVENSON ELECTRONICS 6502/65C02 ASSEMBLER - V.1.0 - MAY, 1988
  149.  
  150.      Source filename [.ASM]:
  151.  
  152. At  this  point,  enter the requested filename.   A valid disk designator  may 
  153. preceed  the  filename,  but a path designation may  not.   SVASM02  does  not 
  154. support  directory paths.   If no drive specifier is used,  the default logged 
  155. drive  is  assumed.   Note  in the example above the  "[.ASM]"  following  the 
  156. filename prompt.   This is the default filename extension that will be used in 
  157. the  absence  of any input filename  extension.   For  example,  the  filename 
  158. SOURCE.ASM may be input as SOURCE or as SOURCE.ASM.  If the filename extension 
  159. is  anything other than .ASM,  it must be specified.   Any error situation  is 
  160. immediately  displayed,  with  a  repeat of the prompt.   The source  file  is 
  161. expected  to be standard ASCII text,  which may be prepared with any  suitable 
  162. editor or word processor.
  163.  
  164. The next prompt is for the object filename:
  165.  
  166.      Object filename [.HEX]:
  167.  
  168. Again,  disk  designations  are supported,  paths are  not,  and  the  default 
  169. filename extension is .HEX.  If no drive specifier is used,  the default drive 
  170. is  assumed.   A  filename must be entered to obtain an object  file.   If  no 
  171. object  file is desired,  merely strike the ENTER key.   Output is normally to 
  172. disk  as ASCII characters in the standard Intel format (see Appendix B  for  a 
  173. description  of the HEX file format).   Reserved Device Names may be used  for 
  174. directing HEX output to the COM ports,  console, or printers.  This is done by 
  175. DOS,  and  is not supported by SVASM02.   Obviously,  you do this at your  own 
  176. peril.  The results may not be as expected.
  177.  
  178. The final prompt is for the name of the listing or print filename:
  179.  
  180.      Print filename [.LST]:
  181.  
  182. The same rules apply here as for the .HEX file, except the listing file may be 
  183. directed  to  the screen by entering CON or to the printer  by  entering  LPT. 
  184. Entering  a valid optional drive and filename will cause the print file to  be 
  185. written  to disk.  If no drive specifier is used,  the default logged drive is 
  186. assumed.   Use  of  the system Reserved Device Names  may  produce  unexpected 
  187. results,  except  for CON.   Drivers have been included to produce the correct 
  188. results using CON, and using LPT instead of any of the system names produces a 
  189. correct  printer output.   See Appendix A for a description of the LST  output 
  190. file format.  
  191.  
  192. Assembly now begins.  If any assembly errors are found, the offending numbered 
  193. line is output to the screen,  followed by a line containing the error  number 
  194. and  a  description of the error.   Error output to the screen  is  automatic, 
  195. regardless of the presence or absence of a .LST or .HEX file.   If a .LST file 
  196. is being written, the same error sequence will appear in it.  Errors are fully 
  197. discussed  anon.   Completion of assembly is signaled by the appearance of  an 
  198. ending  statement containing  the number of bytes assembled and the number  of 
  199. errors, followed by the DOS prompt.
  200.  
  201.  
  202. INPUT FILE LINE STRUCTURE
  203.  
  204. SVASM02 uses the standard format for assembler input.   Each instruction is on 
  205. a single line,  and each line is composed of four fields.  A line may start in 
  206. any column.  The fields are:
  207.  
  208.       Label     Instruction      Argument     ;Comment
  209.  
  210. All  fields  are  generally optional.   The argument field may or may  not  be 
  211. required depending on the nature of the instruction.   Fields are separated by 
  212. one or more space or tab characters.  The argument field may be separated from 
  213. the comment field by the comment delimiting semicolon character ";".
  214.  
  215. Label Field
  216.  
  217. Labels are used as references within the code.   Their use is optional, but if 
  218. a  label is used it is the first non-blank field on the line.   They may be up 
  219. to  six  characters long and must begin with a letter.   Only the  upper  case 
  220. alphabetic  characters  from A to Z and the numerals 0 to 9 may be used  in  a 
  221. label.   A label does NOT require a colon. In fact, use of a colon following a 
  222. label  will generate an error.   A label may be the only field on a line.
  223.  
  224. Instruction Field
  225.  
  226. The  instruction  field  is  composed  of  microprocessor  instructions.   All 
  227. instructions  are three upper case characters long.   The instruction mnemonic 
  228. is as described by the manufacturer.   The instruction field is the first non-
  229. blank field on the line if a label is not used,  or if the statement is not an 
  230. equate or directive.   If a label is used, one or more blank or tab characters 
  231. must  separate  the label field from the instruction field.   For  a  complete 
  232. listing of all of the 6502 and 65C02 instructions, see the file TEST02.ASM.
  233. Argument Field
  234.  
  235. The argument field contains any argument required by the instruction.   It may 
  236. be a constant,  a symbol,  register name, or an expression.  Numeric constants 
  237. may be expressed in decimal,  octal,  hexadecimal,  or binary.   Quoted string 
  238. constants  are  also  allowed.   See the Arithmetic  section  for  a  complete 
  239. description of constants, symbols, and expressions.
  240.  
  241. Comment Field
  242.  
  243. The comment field is the last field on a line, and must begin with a semicolon 
  244. (;).   Anything,  regardless of case,  that follows a semicolon is  considered 
  245. commentary  information  and is ignored by SVASM02.   Comments appear  in  the 
  246. source  listing  exactly as they appear in the source line.   A blank line  is 
  247. considered a comment, and need not be preceeded by a semicolon.
  248.  
  249.  
  250. ARITHMETIC
  251.  
  252. Symbols
  253.  
  254. A symbol is a name assigned to represent a value.  A symbol, once defined, may 
  255. not  be redefined.    Labels are symbols,  since the value of the label is the 
  256. value  of the program counter when the label is defined.   A label is  defined 
  257. when  it  appears  as  the first field on a  line.
  258.  
  259. Program Counter
  260.  
  261. The  program counter is represented symbolically by the asterisk (*).  If  the 
  262. program  counter  is not defined,  a starting value of zero is  assumed.   The 
  263. value assigned to the program counter may not be a forward reference.
  264.  
  265. Consider the following sequence:
  266.  
  267.      * = $100       ; The program counter is defined a value of 100 hex.
  268. FLAG * = * + 1      ; The value of FLAG is 100 hex, and the program counter
  269.                     ; is advanced by 1.
  270. START     LDA #1    ; The value of START is 101 hex
  271.  
  272. In  the  above sequence,  FLAG is uninitialized storage at location  100  hex. 
  273. START is a label having a value of the program counter, or 101 hex.
  274.  
  275. Symbols follow the same rules of syntax as labels - up to six characters (A-Z, 
  276. 0-9), beginning with a letter.
  277.  
  278. Constants
  279.  
  280. A constant is an unsigned numerical value between 0 and 65,535 (decimal).   It 
  281. may be expressed in any of four radices  - decimal,  hexadecimal,  octal,  and 
  282. binary - or  may  be a quoted string one or two characters  long.
  283.  
  284. A  decimal  constant may contain the numerals 0 through 9,  and must  have  no 
  285. leading or trailing radix specifier.
  286.  
  287. A hexadecimal constant may contain the numerals 0 through 9 and the upper case 
  288. letters  A  through  F.   It must be either preceeded by the dollar  sign  ($) 
  289. character  or contain the letter H as the last character.   If the trailing  H 
  290. specifier is used, the first character must be a numeral between 0 and 9.
  291.  
  292. An  octal constant may contain the numerals 0 through 7,  and must  be  either 
  293. preceeded by the @ character or trailed by the letter Q.
  294.  
  295. A  binary constant consists of up to sixteen 0 and 1 characters,  preceeded by 
  296. the % character or trailed by the letter B.
  297.  
  298. A quoted string constant is any one or two characters enclosed between  single 
  299. quote characters.   The value of a single character quoted string is the 8-bit 
  300. ASCII code value of the character.   A two character quoted string has similar 
  301. characteristics,  being the 16-bit value of the characters, in ascending order 
  302. (from  left  to right).   Note that the double quote is invalid  as  a  string 
  303. delimiter,  and is considered to be a character just like K,  a,  &, etc. (See 
  304. the  discussion  of  the  .BYTE directive for additional  use  of  the  quoted 
  305. string.)
  306.  
  307. Some examples:
  308.  
  309.      1233      Decimal, no radix specifier
  310.      $4ACF     Hexadecimal, leading radix specifier
  311.      4ACFH     Hexadecimal, trailing specifier
  312.      @377      Octal, leading specifier
  313.      377Q      Octal, trailing specifier
  314.      %10110    Binary
  315.      10100110B Binary
  316.      'A'       Single character quoted string
  317.      'CQ'      Two character quoted string
  318.  
  319. Expressions
  320.  
  321. An expression is a symbol,  constant,  or combination of symbols and constants 
  322. connected  by  arithmetic and/or logical operators such that the value of  the 
  323. expression does not exceed 16 bits, or 65,535.  The arithmetic operators are:
  324.  
  325.      +         Addition
  326.      -         Subtraction
  327.      *         Multiplication
  328.      /         Division
  329.      <         Extraction of low 8 bits
  330.      >         Extraction of high 8 bits
  331.  
  332. Arithmetic Operators
  333.  
  334. The four arithmetic operators (+, -, *, and /) apply to addition, subtraction, 
  335. multiplication,   and   division,   respectively,   and  warrant  no   further 
  336. explanation.   The byte extraction operators extract either the low 8 bits  or 
  337. high 8 bits from a 16-bit argument.  This is best illustrated by examples:
  338.  
  339.      LOW8 = <$1234       ; The value of LOW8 is $34
  340.      HIGH8 = >$1234      ; The value of HIGH8 is $12
  341.  
  342. The logical operators are:
  343.  
  344.      AND       Logical AND of the arguments
  345.      OR        Logical OR
  346.      NOT       Complement of the argument
  347.      XOR       Exclusive OR of the arguments
  348.      MOD       Remainder
  349.      SHL n     Shift left n bits
  350.      SHR n     Shift right n bits
  351.  
  352. Logical Operators
  353.  
  354. All logical operations assume 16-bit arguments.  Leading bits not contributing 
  355. to the value of the operation are either 0 or 1, as appropriate.  For example, 
  356. NOT 0 has a value of $FFFF, while $1234 AND $34 has a value of $0034.  Results 
  357. of a shift operation (SHL n or SHR n) do not wrap around,  ie.,  a bit shifted 
  358. right out of bit 0 or shifted left out of bit 15 is lost.
  359.  
  360. Evaluation of expressions is from left to right only.   There is no hierarchy, 
  361. and  parenthesis are not allowed.   Examples of all of the above may be had by 
  362. assembling the TEST02.ASM file.
  363.  
  364. ADDRESSING MODE SYNTAX
  365.  
  366. The  generation  of the appropriate opcode by SVASM02 is totally dependent  on 
  367. the addressing mode used.   The syntax of the instruction and its argument (if 
  368. any)  determines  the  addressing  mode,  and therefore what  opcode  will  be 
  369. generated.  The 6502 uses thirteen addressing modes, and the 65C02 uses all of 
  370. these with two additional.  The following descriptions of each addressing mode 
  371. give an example illustrating the syntax of each:
  372.  
  373. 6502 Addressing Modes:
  374.  
  375.   Zero Page - LDA $20
  376.  
  377.      Only the low eight bits are specified and refer to an address of $00FF or 
  378.      less.  The high eight bits of the address are assumed to be 0.  This is a 
  379.      very efficient addressing mode for the 6502/65C02.
  380.  
  381.   Absolute - LDA $125F
  382.  
  383.      The  second and third bytes of the instruction contain a 16-bit  address.
  384.      Any address within the 6502 64K address space may be specified.
  385.  
  386.   Immediate - LDA #$FF
  387.  
  388.      The  second byte of the instruction contains immediate data requiring  no 
  389.      further addressing.  The # symbol signifies immediate data.  The value of 
  390.      the data is limited to 8 bits.
  391.  
  392.   Indexed Zero Page - LDA $20,X or LDA $20,Y
  393.  
  394.      The  second byte of the instruction contains the value of a base  address 
  395.      on page zero to which is added the contents of the X or Y register.   The 
  396.      result  is  the  effective  page zero address and  must  not  exceed  255 
  397.      (decimal).
  398.   Indexed Absolute - LDA $453D,X or LDA $453D,Y
  399.  
  400.      The second and third bytes of the instruction contain the value of a base 
  401.      address  to  which  is added the contents of the X or  Y  register.   The 
  402.      result is a 16-bit value which is the effective address.   The value must 
  403.      not exceed 65,535 (decimal).
  404.  
  405.   Zero Page Indexed Indirect - LDA ($20,X)
  406.  
  407.      The  second  byte of the instruction is added to the contents  of  the  X 
  408.      register,  with any carry discarded.   The result points to a location on 
  409.      page  zero  which contains the low eight bits of the  effective  address. 
  410.      The  next  higher page zero address contains the high eight bits  of  the 
  411.      effective  address.   CAUTION  - Both  memory  locations  containing  the 
  412.      effective address must be on page zero.   SVASM02 has no way of  checking 
  413.      this  at  assembly  time,  so the programmer is cautioned  to  heed  this 
  414.      warning.
  415.  
  416.   Indirect Indexed - LDA ($20),Y
  417.  
  418.      The second byte of the instruction points to a page zero  location.   The 
  419.      contents  of  this location is added to the contents of the  Y  register, 
  420.      producing a result which is the low 8 bits of the effective address.  Any 
  421.      carry  resulting  from the addition is added to the contents of the  next 
  422.      page  zero  address,  the result being the high 8 bits of  the  effective 
  423.      address.  See the CAUTION in the preceeding paragraph.
  424.  
  425.   Absolute Indirect - JMP ($122F)
  426.  
  427.      The  second and third bytes of the instruction contain a 16-bit  address. 
  428.      The  contents  of that address contain the low 8 bits  of  the  effective 
  429.      address,  and the next higher memory location contains the high 8 bits of 
  430.      the  effective  address.   This addressing mode applies only to  the  JMP 
  431.      instruction.
  432.  
  433.   Implied - TSX
  434.  
  435.      The addressing is implied by the instruction,  and no further address  is 
  436.      required.
  437.  
  438.   Acumulator -  LSR A
  439.  
  440.      This  addressing mode is but a single byte,  which specifies an operation 
  441.      to  be  performed on the accumulator.   The argument must be  the  single 
  442.      letter A.
  443.  
  444.   Relative - BEQ *+5
  445.  
  446.      The  second  byte  of the instruction contains an 8-bit offset  which  is 
  447.      added to the program counter value of the next instruction.   The  result 
  448.      is the new value of the program counter.   The assembler uses the present 
  449.      value  of the program counter to make the calculation.   When writing the 
  450.      code,  use  the  value  of the program counter at the  beginning  of  the 
  451.      present line.   The assembler takes this into account when computing  the 
  452.      offset,  and  the proper offset to the target is produced.   This  avoids 
  453.      undetected errors in the offset. For example,
  454.      .
  455.      .
  456.      12      1000   F003               BEQ *+5
  457.      13      1002   200041             JSR FIX3     ; A subroutine at $4100
  458.      14      1005   4C0010     TARGET  JMP $1000
  459.      .
  460.      .
  461.  
  462.      Line 12 (program counter = address 1000) specifies a branch to the target 
  463.      at  5  bytes  beyond the present program counter to  address  1005.   The 
  464.      assembled  offset  is 03,  which is the target relative  to  the  program 
  465.      counter  at line 13.   This 2 byte difference is due to the way in  which 
  466.      the 6502/65C02 handles the program counter and relative addressing.
  467.  
  468.      The permissible range of the offset is -128 to +127 bytes relative to the 
  469.      next instruction, or -126 to +129 relative to the present instruction. 
  470.  
  471. 65C02 Additional Addressing Modes:
  472.  
  473.   Zero Page Indirect - LDA ($20)
  474.  
  475.      The  second  byte of the instruction contains a page zero  address  whose 
  476.      contents is the low 8 bits of the effective address.   The high 8 bits of 
  477.      the effective address is in the next highest page zero location.  See the 
  478.      CAUTION under Zero Page Indexed Indirect above.
  479.  
  480.   Indexed Absolute Indirect - JMP ($203B,X)
  481.  
  482.      The second and third bytes of the insruction contain a base address.  The 
  483.      contents  of  the X register is added to it,  and the result points to  a 
  484.      memory location containing the low 8 bits of the effective address.   The 
  485.      high 8 bits are loaded from the next highest memory location. 
  486.  
  487. In  the above examples numeric constants were used as arguments to  illustrate 
  488. the magnitude of the argument (8 or 16 bits).  In actual use, the argument may 
  489. be expressed symbolically as well.
  490.  
  491. Symbolic  zero page (8 bit) arguments must be defined prior to their use in an 
  492. expression.   While it would be correct to use a 16 bit value with the high  8 
  493. bits set to zero, to do so is not good programming practice and is not allowed 
  494. by SVASM02.  For example:
  495.  
  496.      STA TEMP2
  497. ;
  498.      TEMP2 = $12
  499.  
  500. This will generate a "Forward Reference to Page Zero" error.  If the order was 
  501. reversed,
  502.  
  503.      TEMP2 = $12
  504. ;
  505.      STA TEMP2
  506.  
  507. no  error  would be generated.   There are instructions where  this  does  not 
  508. apply,  however.   Those  instructions that have no zero page mode may use  an 
  509. absolute argument with a value anywhere in the range of 0 to 65,535.
  510.  
  511.  
  512. ASSEMBLER DIRECTIVES (Pseudo-ops)
  513.  
  514. SVASM02 utilizes several directives,  or pseudo-operators,  for directing  the 
  515. assembly.  These include directives for page length and width control, printer 
  516. control,   listing  control,  conditional  assembly,  CMOS  (65C02)  assembly, 
  517. inclusion  of source code from an alternate file,  and definition of byte  and 
  518. word storage.  All pseudo-ops must begin with a period.  The pseudo-ops are as 
  519. follows:
  520.  
  521.      .BYTE          ; Defines initialized byte storage
  522.      .WORD          ; Defines initialized word (two bytes in low/high format)
  523.      .CMOS          : Allows assembly of 65C02 instructions
  524.      .END           ; Defines the physical end of the source code
  525.      .LIST          ; Turns on listing if it had been off
  526.      .NOLIST        ; Turns off assembler listing
  527.      .INCLUDE       ; Reads source code from an alternate disk file
  528.      .PAGE          ; Controls page length
  529.      .WIDTH         ; Controls page width
  530.      .PRINTC        ; Outputs printer control characters
  531.      .IF            ; Assembles following statements if argument is non-zero
  532.      .ELSE          ; Alternate assembly if .IF argument is zero
  533.      .ENDIF         ; Terminates conditional assembly
  534.      .LISTF         ; List but do not assemble false conditionals
  535.  
  536. A detailed description of each pseudo-op follows.
  537.  
  538.  .BYTE
  539.  
  540. The  .BYTE pseudo-op is perhaps the most used.   It initializes storage of its 
  541. arguments  in the code at the address of the value of the program  counter  at 
  542. the  beginning  of  the  line.   The  arguments  may  be  constants,  symbols, 
  543. expressions,  or  quoted strings.   Each individual argument must be separated 
  544. from the next by a comma.   The magnitude of each evaluated argument must  not 
  545. exceed 8 bits.   In the case of quoted string arguments, the only limit is the 
  546. length  of the line.   The delimiter for the quoted string is the single quote 
  547. character.   A  double  quote  has  no meaning in  SVASM02  other  than  as  a 
  548. character.   To include a single quote character as part of the quoted string, 
  549. use two single quotes together.  Examples:
  550.  
  551.      .BYTE $45,$77,$FF,0,3              ; Constants
  552.      .BYTE SHELL + 4                    ; Expression (value of 8 bits or less)
  553.      .BYTE 'This Can''t be'             ; Quoted string with embedded
  554.                                         ; single quote
  555.  
  556.  .WORD
  557.  
  558. Similar to .BYTE,  the .WORD pseudo-op assembles 16-bit values at the  address 
  559. of  the value of the program counter at the beginning of the line.   Since the 
  560. 6502/65C02  handles  16-bit values (addresses) in low  byte/high  byte  order, 
  561. the  .WORD directive assembles the 16-bit values of its arguments in  low/high 
  562. order.   The arguments to .WORD follow the same rules as for .BYTE, except the 
  563. value of each argument may be within the range of 0 to 65,535.  Examples:
  564.  
  565.      .WORD START         ; The 16-bit value of START is placed in the code
  566.      .WORD ASSEM+9       ; 9 is added to the value of ASSEM, and the result
  567.                          ; is placed in the code
  568.  
  569.  .CMOS
  570.  
  571. Directs  SVASM02  to  assemble 65C02 instructions in addition  to  6502.   The 
  572. default is off (do not assemble 65C02).   If assembly of 65C02 instructions or 
  573. address  modes  is attempted without first invoking .CMOS,  an error  will  be 
  574. generated.  The .CMOS directive has no arguments.
  575.  
  576.  .END
  577.  
  578. This directive causes assembly to stop, and must be used as the last statement 
  579. in the source code.   No further assembly occurs following the .END directive. 
  580. The .END directive has no arguments,  and its omission causes an error.   .END 
  581. must be used in .INCLUDE files as well.   The .END in an .INCLUDE file  causes 
  582. termination of assembly of the .INCLUDED source statements and a return to the 
  583. primary source file.
  584.  
  585.  .LIST
  586.  
  587. This  directive,  together  with its complementary .NOLIST,  may  be  used  to 
  588. selectively list the assembled source code in the output file.  If no LST file 
  589. or  device is selected at program invocation,  the .LIST directive is ignored. 
  590. The default is on (list assembler output).  There are no arguments.
  591.  
  592.  .NOLIST
  593.  
  594. Turns off assembler output listing.   Source code lines following the  .NOLIST 
  595. are  counted  and assembled,  but generate no LST output.   If no LST file  or 
  596. device  is selected at program invocation,  the .NOLIST directive is  ignored. 
  597. The default is .LIST, and there are no arguments.
  598.  
  599.  .INCLUDE
  600.  
  601. This directive causes SVASM02 to read source code input from the file named as 
  602. the  argument.   The  filename must be valid,  and may include  a  disk  drive 
  603. specifier.  Omission of a drive specifier causes the default drive to be used. 
  604. A pathname may not be used.  The source code in the INCLUDEd file must contain 
  605. the  .END directive.   Its omission will cause an error.  INCLUDEs may not  be 
  606. nested (only a single open INCLUDE at a time is allowed).  Example:
  607.  
  608.      .INCLUDE DISTRIB.TAB     ; Source code is taken from the file named
  609.                               ; DISTRIB.TAB on the default logged disk.
  610.  
  611.  .PAGE
  612.  
  613. This directive controls the length of the LST output page and causes a  header 
  614. to be printed on the top of each new page.   The header includes the assembler 
  615. name and version number,  the name of the file being assembled,  the date  and 
  616. time  at which assembly was started,  and the page number.   Four blank  lines 
  617. separate  the header from the output.   The default is no paging.
  618.  
  619. The  .PAGE  directive  may or may not have an argument.   If  no  argument  is 
  620. specified,  paging  is initiated at the default 58 output lines per page or at 
  621. the previous number of lines per page if a previous .PAGE n had been used.  If 
  622. a .PAGE 0 is specified,  paging is turned off if it had been on.  .PAGE n will 
  623. initiate paging at n lines per page.   The maximum lines per page is  255.   A 
  624. PAGE  may be used to cause a page eject.   The .PAGE directive is not printed, 
  625. and has no line number assigned.  Examples:
  626.  
  627.      .PAGE          ; Initiate paging at 58 lines/page or the previous value
  628.      .PAGE 60       ; Use 60 lines/page
  629.      .PAGE 0        ; Turn off paging
  630.  
  631.  .WIDTH
  632.  
  633. This directive controls the number of character spaces on the LST output line. 
  634. The default is 76, and includes the neccessary fill spaces for tab characters.
  635. A tab character is assumed to be eight character spaces long,  and occur every 
  636. eight  character positions.   Beginning at position 1,  a tab can position the 
  637. print head at column 9,  17,  25,  33, etc.  If a tab character is encountered 
  638. between the tab settings,  blanks are added to position the print head at  the 
  639. next tab stop.  The .WIDTH directive must have an argument, and its value must 
  640. be  in  the range of 64 to 255.   Any input source code characters beyond  the 
  641. number  specified  in the argument are assembled,  but are ignored in the  LST 
  642. output.
  643.  
  644.  .PRINTC
  645.  
  646. Many printers use "escape codes" or other control characters to control pitch, 
  647. form  length,  page width,  etc.   The .PRINTC directive is intended  to  send 
  648. initializing  or control characters to the printer.   The argument contains  a 
  649. string  that is evaluated as binary bytes by SVASM02 and is written to the LST 
  650. output  device prior to any other output.   The bytes are not counted  against 
  651. line width,  the line is not counted and it does not appear in the LST output. 
  652. There  is no default.   When used,  the .PRINTC directive should be  the  very 
  653. first statement in the source code.  Example:
  654.  
  655.           .PRINTC '[x2,'      ; Causes the four byte string [x2, to be sent 
  656.                               ; to the LST output file or device.
  657.  
  658.  .IF, .ELSE, .ENDIF, .LISTF
  659.  
  660. These  pseudo-ops  will be discussed together,  since they are  the  so-called 
  661. conditional  assembly directives.
  662.  
  663. A  conditional  assembly sequence consists of the openning .IF statement  with 
  664. its  argument,  source statements,  and the closing .ENDIF statement.   If the 
  665. argument of the .IF evaluates non-zero (true),  the source statements  between 
  666. the .IF and .ENDIF are assembled.  If the argument evaluates zero (false), the 
  667. statements between the .IF and .ENDIF are not assembled.   Statements within a 
  668. false  conditional are not listed on the LST output unless .LISTF (list  false 
  669. conditionals) has been invoked.
  670.  
  671. The  .ELSE  directive is used between the .IF and .ENDIF to  permit  alternate 
  672. assembly or non-assembly of the code following,  depending on the value of the 
  673. IF argument.  This is best shown by illustration:
  674.      .IF arg
  675.         .                 If arg is non-zero, the statements up to the
  676.         .                 .ELSE are assembled and those between the .ELSE
  677.         .                 and the .ENDIF are not.
  678.         .
  679.      .ELSE
  680.         .                 If arg is zero, the statements between the .ELSE
  681.         .                 and the .ENDIF are assembled and those between the 
  682.         .                 .IF and .ELSE are not.
  683.         .
  684.      .ENDIF
  685.  
  686. The  argument to the .IF is required,  and may be  any  constant,  symbol,  or 
  687. expression.  .ELSE, .ENDIF, and .LISTF do not require arguments.  There are no 
  688. defaults to conditional assembly.  Conditionals may be nested up to 16 levels. 
  689. It  should  be  noted that this version of SVASM02 does not allow the  use  of 
  690. relational operators such as EQ, LT, GT, etc. in the argument to the .IF.
  691.  
  692.  
  693. ERRORS
  694.  
  695. Fatal Errors
  696.  
  697. There are three fatal errors possible in SVASM02.   Each causes the program to 
  698. stop and an error message to be displayed on the screen.   Control is returned 
  699. to DOS.
  700.  
  701.      1. Directory  full - An attempt was made to create a file entry in  a 
  702.         disk  directory  that contained no available  slots.   Reduce  the 
  703.         number of files on the disk or use another disk.
  704.  
  705.      2. Input  file read error - The source file is corrupted or otherwise 
  706.         not readable.  Try another copy of the file.
  707.  
  708.      3. Disk full - An attempt was made to write data on a full disk.  Use 
  709.         another disk or delete files to make room.
  710.  
  711.  
  712. Invocation errors
  713.  
  714. These errors are non-fatal, merely causing a reissuing of the prompt.
  715.  
  716.      1. Filename  error  - An  incorrect  syntax was  used  to  specify  a 
  717.         filename for the source, object, or list file.
  718.  
  719.      2. Invalid drive - The disk drive specified does not exist or is  not 
  720.         avaialable.
  721.  
  722.      3. File  not found - The source file could not be found on the  drive 
  723.         specified.
  724.  
  725. Assembler Errors
  726.  
  727. There  are  25  possible assembly time errors.   Each is  numbered,  and  when 
  728. encountered, is output to the screen along with the line containing the error. 
  729. For example,
  730.  
  731. 381    2079                     .PSGE 60          ; Use 60 lines/page
  732.                    *** 10 ***  Unidentified directive
  733.  
  734. The  first line is the assembler output of the line containing the error.   In 
  735. the  above  example,  381 is the line number and 2079 is the  program  counter 
  736. value.   The  remainder  of the line is as input.   The error  message  number 
  737. appears  before  the  description of the error and is  the  reference  to  the 
  738. detailed discussion of the error in this document.  If an output file is being 
  739. generated or there is output to a list device, the same error sequence appears 
  740. there.   Regardless of the output medium,  all errors are output to the screen 
  741. as shown above.   For errors occurring in lines containing instructions,  one, 
  742. two,  or  three  NOP's ($EA) are assembled depending on the  number  of  bytes 
  743. expected to be required for the instruction.
  744.  
  745. 1  Undefined  symbol  - A reference was made to a symbol that has  never  been 
  746.    defined.   This could be caused by a misspelling of a valid symbol or label 
  747.    name,  or  omission  of a line of code.   An improper numeric  argument  or 
  748.    directive name could also be considered a "symbol" and as such, could cause 
  749.    this error.
  750.  
  751. 2  Label  or  symbol previously defined - An attempt was made  to  redefine  a 
  752.    symbol or use a label more than once.  Once defined, SVASM02 does not allow 
  753.    a symbol to be redefined.
  754.  
  755. 3  Syntax  error  - The stucture of the line is  not  recognized.   Check  the 
  756.    statement for proper syntax, missing arguments, etc.
  757.  
  758. 4  Illegal  first character in label or symbol - Labels and symbols must begin 
  759.    with a letter.   Am improperly structured or used numeric argument may also 
  760.    cause this error.
  761.  
  762. 5  Forward  reference to page zero - All references to addresses on page  zero 
  763.    must  be  known before they are used.   See the discussion on page 6  under 
  764.    Addressing Modes.
  765.  
  766. 6  Label  or  symbol more than 6 characters - The present version  of  SVASM02 
  767.    limits the number of characters in a label or symbol to six.
  768.  
  769. 7  No  .END  directive  in INCLUDE file - The .END directive  is  required  to 
  770.    terminate  assembly.   An end of file was reached without finding the  .END 
  771.    directive.
  772.  
  773. 8  Forward  reference  in equate or origin - An expression contained a  symbol 
  774.    which was not defined prior to its use to define the program counter or  an 
  775.    equate.
  776.  
  777. 9  (Reserved)
  778.  
  779. 10 Unidentified directive - A directive or pseudo-op was found that is not  in 
  780.    the  list  of valid directives.   Check for a stray leading period  or  bad 
  781.    spelling.
  782.  
  783. 11 Invalid quoted string - An attempt was made to use a quoted string constant 
  784.    greater than two characters long, or there was a missing quote character.
  785.  
  786. 12 Branch  target  out of range - The target address of a  branch  instruction 
  787.    was  beyond the maximum allowed displacement from the  source  instruction. 
  788.    See the discussion on relative addressing.
  789.  
  790. 13 Invalid  addressing  mode - An attempt was made to use an  addressing  mode 
  791.    that  is  invalid  for  the instruction.   See the file  TEST02.ASM  for  a 
  792.    complete listing of all valid addressing modes for all instructions.
  793.  
  794. 14 Invalid numeric argument - A numeric argument contained a character invalid 
  795.    for the radix used.
  796.  
  797. 15 Arithmetic overflow - The result of an arithmetic operation exceeded 65,535 
  798.    (decimal).
  799.  
  800. 16 No  .END directive - The last statement in the source file was not an  .END 
  801.    directive.  .END must be encountered before the physical end of the file.
  802.  
  803. 17 Expression  value  >  8 bits - An arithmetic operation  produced  a  result 
  804.    greater  than 255 (decimal) for an instruction or addressing mode requiring 
  805.    a single byte value.
  806.  
  807. 18 Division  by zero - The divisor in a division operation had a value of zero 
  808.    when the operation was attempted.
  809.  
  810. 19 CMOS assembly not selected - An attempt was made to use a 65C02 instruction 
  811.    or addressing mode before invoking the .CMOS directive.
  812.  
  813. 20 Open  .IF  limit exceeded - The number of open  conditional  assembly  (.IF 
  814.    directive) exceeds the maximum of 16.
  815.  
  816. 21 Forward  reference  in  conditional - The value of the argument in  an  .IF 
  817.    directive was unknown at the time the .IF was encountered during the  first 
  818.    pass.  The argument value must be known before the .IF can be openned.
  819.  
  820. 22 No  open  .IF - An .ELSE or .ENDIF was encountered for which there  was  no 
  821.    corresponding .IF directive previously specified.
  822.  
  823. 23 .INCLUDE  file  already open - An attempt was made to .INCLUDE a file  that 
  824.    has already been openned (.INCLUDEd).
  825.  
  826. 24 INCLUDE filename error - A syntax error has occurred in the filename  given 
  827.    in an .INCLUDE directive.
  828.  
  829. 25 Invalid drive name - The disk drive specifier in a filename to be .INCLUDEd 
  830.    is invalid.
  831.  
  832. 26 INCLUDE file not found - The file specified in an .INCLUDE directive cannot 
  833.    be  found on the specified disk drive or currently logged disk if  no  disk 
  834.    specifier is used.
  835.                                   APPENDIX A
  836.  
  837.                      SVASM02 LST Output File Description
  838.  
  839.  
  840. The  output fragments which follow were extracted from the TEST02.LST file  to 
  841. illustrate  the  format of the assembler output.   In general,  the  first  33 
  842. spaces  on  a line are generated by SVASM02.   The remainder of the line is  a 
  843. copy of the input code.
  844.    .
  845.    .
  846.   18  = 0047                    QUOTE1='G'        ;SINGLE QUOTE
  847.    .
  848.    .
  849. Line 18 contains an equate.   The line number appears in the first four spaces 
  850. on the left.   The = signifies a valid equate, having the hexadecimal value of 
  851. 0047.   The  several  spaces between the value and QUOTE1  are  the  remaining 
  852. spaces  up  to column 32,  followed by tab expansion spaces up to the  QUOTE1. 
  853. The spaces between the 'G' and the ; are tab fill spaces such that the comment 
  854. delimiter (;) starts in a column which is a multiple of 8,  plus 1.  The input 
  855. source code contained tabs in these spaces.
  856.    .
  857.   52                        ;
  858.   53                        ;  BYTE AND WORD DIRECTIVES
  859.   54                        ;
  860.   55    1006  0D0A5356          .BYTE $0D,$0A,'SVENSON ELECTRONICS','$'
  861.         100A  454E534F
  862.         100E  4E20454C
  863.         1012  45435452
  864.    .
  865. Lines  52  through 55 are the output from commentary information and  a  .BYTE 
  866. directive.   The ; in lines 52-54 are in column 33, having been in column 1 in 
  867. the  input  file.   The  byte  output begins in line  55.   The  1006  is  the 
  868. hexadecimal address (program counter) at which the bytes were assembled.   The 
  869. eight  hexadecimal  characters which follow represent the value of  the  first 
  870. four bytes of the data assembled.  The remainder of the line is as input.  The 
  871. three  unumbered  lines following are the remaining output for the  directive. 
  872. For  .BYTE  and  .WORD  directives,  the line number  is  not  incremented  if 
  873. additional  lines  are  required to complete the output  of  the  data.   Line 
  874. numbering resumes at the next statement.
  875.    .
  876.   65    1024  AD0230            LDA PORT1
  877.   66    1027  29FF              AND #$FF
  878.   67    1029  8D0530            STA DAT1
  879.    .
  880. Lines  65-67  are typical instruction code output.   Note that  addresses  are 
  881. listed in lowbyte/high byte order exactly the way they appear in memory.
  882.    .
  883.   86    102F  EAEA              BRA *-126
  884.                           *** 19 *** CMOS Assembly not selected
  885.    .
  886. Line  86  contains an error,  with the error message on  the  following  line. 
  887. Since  the  branch  instruction is expected to generate two bytes  of  machine 
  888. code, two NOP's (EA) are inserted in place of the code that would be generated 
  889. had  there been no error.   In the error message line,  the 19 refers  to  the 
  890. error  number,  a discussion of which may be found in the  main  documentation 
  891. under ERRORS.
  892.    .
  893. END OF SVENSON ELECTRONICS 6502/65C02 ASSEMBLER - VERSION 1.0
  894.  
  895. BYTES ASSEMBLED:    510         NO. OF ERRORS:   46
  896.  
  897. SYMBOL TABLE:
  898.  
  899.                   LINE
  900. SYMBOL    VALUE   DEFINED             CROSS REFERENCES
  901.  
  902. BIAS      0007      48   
  903. BVAL1     009D      34       47
  904. BVAL2     009D      35       51
  905. CHECKP    2091     381   
  906.  
  907. The  above output fragment appears at the end of the code output.   The number 
  908. of  bytes  asembled  is  given,  and represents  the  actual  count  of  bytes 
  909. assembled.    Gaps  in  the  address  space  of  the  program,   such  as  for 
  910. uninitialized storage, are not counted.  The number of errors is also stated.
  911.  
  912. The  alphabetically  sorted  symbol table  follows,  with  appropriate  column 
  913. headings for the symbol name,  its hexadecimal value,  the decimal line number 
  914. in which it was defined,  and decimal listing of cross-reference line numbers. 
  915. The above example shows only a single reference for two symbols,  but multiple 
  916. references  are  listed  on the same line up to the maximum number  of  spaces 
  917. allowed by the WIDTH directive.   Any additional references are listed on  the 
  918. following lines.
  919.                                   APPENDIX B
  920.  
  921.                           SVASM02 Object File Format
  922.  
  923. The  object  file consists of records of ASCII hexadecimal characters  in  the 
  924. Intel format.  A typical record looks like this:
  925.  
  926.      :101006000D0A5356454E534F4E20454C45435452B8
  927.  
  928. Byte 0        A colon character, signifying the beginning of the record
  929.  
  930. Bytes 1-2     Hexadecimal value indicating the number of loadable bytes in the 
  931.               record.  The maximum is 10 (16 decimal).
  932.  
  933. Bytes 3-6     Hexadecimal  address  where  first byte of the  record  will  be 
  934.               loaded.
  935.  
  936. Bytes 7-9     Always 00.
  937.  
  938. Bytes 10-on   Hexadecimal characters representing the actual data bytes.
  939.  
  940. Last two      A  checksum.   The checksum is the two's complement of the 8-bit 
  941.               bytes  sum of the value of all bytes (not the ASCII) with  carry 
  942.               discarded.   It includes the byte count, load address bytes, and 
  943.               loadable data bytes.
  944.  
  945. The  last record contains values of zero for byte  count,  load  address,  and 
  946. checksum.  It effectively is :0000000000.
  947.