home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / bbcmicro / bbcasmdoc.txt < prev    next >
Text File  |  2020-01-01  |  143KB  |  5,082 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.                       USING THE 65C02 ASSEMBLER 
  14.                             (Version 1.50)
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25. This  guide  describes how to use the 65C02 Assembler produced by Alan
  26. Phillips of the Department of  Computing,  Lancaster  University.  The
  27. reader  is  assumed to be familiar with the concepts of programming at
  28. assembly level.
  29.  
  30.  
  31. The 65C02 Assembler is copyright (C) Alan Phillips  1986.  It  may  be
  32. passed  on by anyone, to anyone, and used for any peaceful purpose. No
  33. licensing or permission is needed. It may be distributed  in  any  way
  34. provided that it is not sold (apart from reasonable handling and media
  35. costs),  that  due  credit  is  made  for  authorship,  and  that this
  36. paragraph is brought to the attention of the recipient.
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.                                                            Edition 2.0
  52.                                                          November 1986
  53.                                                          Alan Phillips
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.                                    
  66.  
  67.  
  68.  
  69.                                CONTENTS
  70.  
  71.  
  72.  
  73.  
  74.  
  75.      1.  INTRODUCTION
  76.          1.1  Installing the Assembler
  77.               1.1  The Assembler's CLI mode
  78.          1.2  Creating source files
  79.          1.3  Starting an assembly
  80.               1.3.1  The command line options
  81.               1.3.2  Alternative syntax forms for the command line
  82.          1.4  Assembly on a second processor
  83.          1.5  The object code buffer
  84.          1.6  Returning to the calling language
  85.          1.7  Use of control keys during assembly
  86.      
  87.      2.  SOURCE PROGRAM FORMAT
  88.          2.1  Syntax of the line
  89.               2.1.1  The label field
  90.               2.1.2  The opcode field
  91.               2.1.3  The operand field
  92.               2.1.4  The comment field
  93.          2.2  The syntax of expressions
  94.               2.2.1  Numeric expressions
  95.               2.2.2  Strings
  96.               2.2.3  String expressions
  97.      
  98.      3.  THE OUTPUT LISTING
  99.          3.1  The source listing level
  100.          3.2  Source listing format
  101.               3.2.1  The code listing level
  102.          3.3  Symbol table listing format
  103.          3.4  Error reports
  104.          3.5  Output page control
  105.               3.5.1  Setting page dimensions
  106.               3.5.2  Setting the page title
  107.               3.5.3  Setting the timestamp
  108.               3.5.4  Control of output layout
  109.          3.6  Controlling the output destination
  110.      
  111.      4.  DIRECTIVES DEFINING DATA AND CONSTANTS
  112.          4.1  Defining constants
  113.          4.2  Byte and word directives
  114.               4.2.1  Byte directives
  115.               4.2.2  Word directives
  116.               4.2.3  Using repeat counts
  117.          4.3  Character string directives
  118.               4.3.1  The ASC and STR directives
  119.               4.3.2  The CASC and CSTR directives
  120.               4.3.3  Planting special characters
  121.          4.4  The HEX directive
  122.          4.5  The CODE directive
  123.  
  124.  
  125.      
  126.  
  127.  
  128.  
  129.  
  130.  
  131.      
  132.  
  133.  
  134.  
  135.      
  136.      5.  OBJECT FILE CONTROL DIRECTIVES
  137.          5.1  Defining the current address
  138.          5.2  Using dummy sections
  139.               5.2.1  The DS directive
  140.               5.2.2  Reading the current address
  141.          5.3  Defining object load and execution addresses
  142.               5.3.1  Specify the low bytes of the addresses
  143.               5.3.2  Specifying the processor
  144.      
  145.      6.  SOURCE FILE CONTROL DIRECTIVES
  146.          6.1  Chaining source files
  147.          6.2  Including one file into another
  148.      
  149.      7.  CONDITIONAL ASSEMBLY
  150.          7.1  Assembly conditional on expressions
  151.          7.2  Assembly conditional on the existence of symbols
  152.          7.3  Nesting conditionals
  153.          7.4  Listing conditionals
  154.      
  155.      8.  PROGRESS REPORTING DIRECTIVES
  156.          8.1  The DISP, DISP1 and DISP2 directives
  157.          8.2  The WAIT, WAIT1 and WAIT2 directives
  158.          8.3  The QUERY directive
  159.          8.4  The STOP directive
  160.      
  161.      9.  WRITING SIMPLE MACROS
  162.          9.1  Using macro parameters
  163.          9.2  Specifying macro parameters
  164.          9.3  Nesting macros
  165.          9.4  Redefining opcodes and directives
  166.          9.5  Labels within macros
  167.      
  168.      10. THE MACRO PROGRAMMING LANGUAGE
  169.          10.1 Sequence Symbols
  170.          10.2 Assembly Time Variables
  171.               10.2.1 Creating Assembly Time Variables
  172.                      10.2.1.1 Local and global ATVs
  173.                      10.2.1.2 String and numeric values
  174.                      10.2.1.3 Efficient use of memory
  175.               10.2.2 Simple substitution of Assembly Time Variables
  176.          10.3 Writing complex macros
  177.               10.3.1 Programming macro loops
  178.                      10.3.1.1 Loops controlled by counter
  179.                      10.3.1.2 Loops accessing macro parameters
  180.               10.3.2 Changing macro parameters
  181.               10.3.3 Listing control for macros
  182.               10.3.4 Exiting a macro prematurely
  183.          10.4 System ATVs
  184.      
  185.      
  186.      
  187.  
  188.  
  189.  
  190.  
  191.      
  192.  
  193.  
  194.  
  195.  
  196.  
  197.      
  198.  
  199.  
  200.  
  201.      Appendices
  202.      
  203.      
  204.      
  205.      A1. Opcodes and addressing modes
  206.      A2. Assembler directives
  207.      A3. Differences from the ADE Assembler
  208.      
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.                            Acknowledgements 
  240.  
  241. Thanks are due to Dave Morriss, Neil Mercer, Alan Baker,  Peter  Vince
  242. and  Mike  Tubby  for many helpful suggestions and comments during the
  243. development of this release of the Assembler.
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.                       USING THE 65C02 ASSEMBLER 
  264.  
  265.  
  266.  
  267. 1. INTRODUCTION
  268.  
  269.  
  270.    The 65C02 Assembler runs in sideways RAM or as a  sideways  ROM  on
  271. the  BBC  Models  B, B+, B+128, Master 128 and Master Compact, with or
  272. without a 6502 Second Processor. It supports all the  opcodes  of  the
  273. 6502  and  65C02  processor  families,  and  contains a powerful Macro
  274. Programming Language.
  275.  
  276.    The Assembler is a disc-oriented system. Source files must be  held
  277. on  disc,  and the object code will be written to disc. It can be used
  278. with the Acorn DFS, ADFS, NFS and any other Acorn-compatible  disc  or
  279. network filing system, but not on cassette-only machines.
  280.  
  281.    There  are no source editing facilities contained in the Assembler.
  282. However, it is able to accept source produced by any  text  editor  or
  283. word-processor program.
  284.  
  285.  
  286. 1.1 Installing the Assembler
  287.  
  288.  
  289.    The  65C02  Assembler code is completely unprotected. If you have a
  290. machine with sideways RAM, you will be able to load it to a  RAM  bank
  291. and run it; if not, you will need to program it into a 27128 EPROM and
  292. fit it into a sideways ROM socket.
  293.  
  294.      1.1.1 The Assembler's CLI mode
  295.      
  296.      If  you  have  the Assembler fitted into the highest priority ROM
  297.      slot of your machine, pressing CONTROL-BREAK or powering on  will
  298.      enter  it  as the current language. In this case the Assembler is
  299.      said to be in "CLI (Command Language Interpreter) mode". You will
  300.      see a "*" prompting you for input, and any lines you type will be
  301.      sent to the BBC Operating System as MOS commands.  In  this  mode
  302.      there is no need to type a "*" yourself in front of the commands,
  303.      although it won't matter if you do.
  304.      
  305.      From  CLI  mode  you  can  of  course  start an assembly with the
  306.      *ASSEMBLE command described below. Alternatively, you could enter
  307.      another language by typing, say,
  308.      
  309.                                 *BASIC
  310.      
  311.      or
  312.      
  313.                               *WORDWISE
  314.      
  315.      
  316.      Naturally, you are able to issue DFS commands in CLI mode, or you
  317.      could *TYPE files, and so on. You can't use the  BASIC  statement
  318.      MODE to change screen mode, though, since the current language is
  319.      not BASIC. However, for convenience the Assembler will respond to
  320.      a command *MODE, so you could type
  321.  
  322.  
  323.                                   1
  324.  
  325.  
  326.  
  327.  
  328.  
  329.                       USING THE 65C02 ASSEMBLER 
  330.  
  331.  
  332.  
  333.      
  334.                                *MODE 3
  335.      
  336.      to  set  mode  3  if you wished. This command is available either
  337.      from the Assembler's CLI mode or from any other language.
  338.      
  339.      
  340. 1.2 Creating source files
  341.  
  342.    Though the Assembler does not contain any  editing  facilities,  it
  343. will  accept files produced on just about any word processor or source
  344. editor.  The  source  you  create  should   contain   only   printable
  345. characters, spaces and TAB characters, and each line should end with a
  346. carriage  return byte (with optionally a line feed character before or
  347. after it).
  348.  
  349.    You can create suitable files easily with WordWise or View:
  350.  
  351.  
  352.   a. Using WordWise
  353.      
  354.      Files saved by menu option 1 can be used directly as input to the
  355.      Assembler, provided that  you  have  not  included  any  embedded
  356.      commands.  The  WordWise  TAB  character,  which  appears  on the
  357.      editing screen as a right-pointing arrow, will be accepted  as  a
  358.      TAB by the Assembler. Remember to press RETURN at the end of each
  359.      source line.
  360.      
  361.      Alternatively,  you  can  spool the file to disc first using menu
  362.      option 8 - but this will create a bigger  file,  that  will  take
  363.      longer to assemble.
  364.      
  365.      
  366.   b. Using View
  367.      
  368.      A  file  created  by the View SAVE, WRITE or EDIT commands can be
  369.      directly input to the Assembler. You should not  include  rulers,
  370.      stored  commands  or  highlight  codes  in  this file. You should
  371.      always remember to press RETURN at the end of every source  line:
  372.      it  will  be necessary to turn off the Format and Justify options
  373.      when typing the source, otherwise View will interfere with this.
  374.      
  375.      
  376. 1.3 Starting an assembly
  377.  
  378.  
  379.    The Assembler is  started  with  the  *ASSEMBLE  command.  This  is
  380. followed by a number of "option flags" that tell the Assembler exactly
  381. how you wish it to operate.
  382.  
  383.    The simplest use of the command would be, for example:
  384.  
  385.                            *ASSEMBLE SOURCE
  386.  
  387.  
  388.  
  389.                                   2
  390.  
  391.  
  392.  
  393.  
  394.  
  395.                       USING THE 65C02 ASSEMBLER 
  396.  
  397.  
  398.  
  399. where  the  source file name is SOURCE. This format performs a "syntax
  400. check run" - no object code  is  produced.  This  will  give  you  the
  401. fastest  possibly  assembly, and it can be very useful when checking a
  402. large program for errors. To produce  an  output  file,  you  need  to
  403. specify a "-O" option:
  404.  
  405.                       *ASSEMBLE SOURCE -OPROGRAM
  406.  
  407. where  the "-O" is followed by the name of the object file you wish to
  408. produce.
  409.  
  410.    After assembly, the Assembler will return you to the  language  you
  411. were  running  when  you  issued  the *ASSEMBLE command. If you have a
  412. machine  with   shadow   screen   capability,   the   Assembler   will
  413. automatically turn it on to give you the maximum space for symbols. It
  414. will  return  the shadow screen to its initial state when it finishes,
  415. and since this involves clearing the screen in a mode change, it  will
  416. pause for you to press a key before it does so.
  417.  
  418.  
  419.  
  420.      1.3.1 The command line options
  421.      
  422.      
  423.      The  various  options  you  can specify to the command are listed
  424.      below. Each option flag begins with a "-" character; some options
  425.      must be followed immediately by numbers or  filenames.  You  must
  426.      separate one option from another by spaces.
  427.      
  428.      Options can be given in any order, but the first parameter to the
  429.      command  must  always  be  the name of the first (or only) source
  430.      file.
  431.      
  432.      
  433.            -A  You must specify this option to assemble the source for
  434.                BBC  KERMIT,  and  it  is   recommended   for   sources
  435.                originally  written for the ADE Assembler. It makes the
  436.                syntax of labels ADE-compatible, and  treats  only  the
  437.                first  6 characters of each as significant. This option
  438.                implies a -R.
  439.                
  440.            -B  Specifies that a memory buffer is to be used for object
  441.                code. This must be followed by a number  in  the  range
  442.                1..16 (see section 1.5)
  443.                
  444.            -C  Specifies  the default code listing level (see the CLST
  445.                directive). This must be followed by 0,  1  or  2.  the
  446.                default value is 1.
  447.                
  448.            -G  Specifies  that the Assembler is to restart the calling
  449.                language immediately the assembly is over. (See section
  450.                1.6)
  451.                
  452.            -L  Specifies the default source listing level (see the LST
  453.  
  454.  
  455.                                   3
  456.  
  457.  
  458.  
  459.  
  460.  
  461.                       USING THE 65C02 ASSEMBLER 
  462.  
  463.  
  464.  
  465.                directive). This must be followed by 0, 1, 2 or 3.  The
  466.                default value is 0. You can also control the list level
  467.                during  the  actual assembly with function keys 0, 1, 2
  468.                and 3.
  469.                
  470.            -M  Instructs the Assembler to change screen mode before it
  471.                starts to process the source. The number  of  the  mode
  472.                you wish to use should follow the letter M, and must be
  473.                in the range 0..7.
  474.                
  475.            -O  Specifies  the  name  of  the  object  file, which must
  476.                follow the option flag. If you omit this, the Assembler
  477.                performs a syntax check only and does  not  produce  an
  478.                object file.
  479.                
  480.            -P  Specifies that the listing is to be sent to the printer
  481.                only.  If  you omit it, the listing is sent only to the
  482.                screen. You can change the destination of  the  listing
  483.                at any time during assembly by pressing CONTROL-P.
  484.                
  485.            -R  If  this  is  specified,  65C02  opcodes and addressing
  486.                modes are rejected. If you omit it, all 65C02 codes are
  487.                assembled.
  488.                
  489.            -S  Specifies that lines skipped in  conditionals  are  not
  490.                listed (see the SFCOND and LFCOND directives)
  491.                
  492.            -W  Specifies   that   the   Assembler  should  wait  after
  493.                displaying a line containing an error, so you can  note
  494.                down  the  details.  To resume assembly, press any key.
  495.                This option has no effect if you are sending output  to
  496.                a printer. You can change the setting of this option at
  497.                any time during assembly by pressing CONTROL-W.
  498.                
  499.                
  500.      As an example, the line:
  501.      
  502.                   *ASSEMBLE SOURCE -OPROG -P -L2 -B8
  503.      
  504.      will assemble from file SOURCE, putting the object code into file
  505.      PROG.  The  default listing level used will be 2, and the listing
  506.      will be sent to the printer only. An 8 kilobyte memory buffer  is
  507.      to be used for the object code to speed up assembly.
  508.      
  509.      The  Assembler  will  leave  the screen in whatever mode you have
  510.      selected, so that for large assemblies you may need to change  to
  511.      mode  7  to  provide  room in memory for the symbol table. Shadow
  512.      mode will automatically be selected if it is available,  so  that
  513.      on  the  B+,  B+128  and  Master  series you will always have the
  514.      maximum space available.
  515.      
  516.      
  517.      
  518.      
  519.  
  520.  
  521.                                   4
  522.  
  523.  
  524.  
  525.  
  526.  
  527.                       USING THE 65C02 ASSEMBLER 
  528.  
  529.  
  530.  
  531.      1.3.2 Alternative syntax forms for the command line
  532.      
  533.      The example given  above,  and  the  output  the  Assembler  will
  534.      produce if you type
  535.      
  536.                            *HELP ASSEMBLER
  537.      
  538.      detail  the  full  form  of  the command line syntax. As you gain
  539.      experience in using the Assembler, however,  you  might  wish  to
  540.      take  advantage  of  various  ways of specifying the options in a
  541.      more compact form.
  542.      
  543.      Firstly, the Assembler allows you to specify the options  all  at
  544.      once,  without  the need to put the "-" flag before each of them.
  545.      Thus, you could type either
  546.      
  547.                      *ASSEMBLE SOURCE -M3 -W -L2
  548.      
  549.      or the shorter, but less readable
  550.      
  551.                        *ASSEMBLE SOURCE -M3WL2
  552.      
  553.      Secondly, the "-O" flag to specify an object  file  is  optional.
  554.      The Assembler will take the second parameter of the command as an
  555.      object file name, unless it starts with a "-" character. Thus
  556.      
  557.                        *ASSEMBLE SOURCE -OPROG
  558.      
  559.      and
  560.      
  561.                         *ASSEMBLE SOURCE PROG
  562.      
  563.      are  identical  in  effect.  If you should ever need to start the
  564.      object file with a "-" character (e.g.  if  you  wish  to  use  a
  565.      temporary  file  system on a Master 128) you will have to specify
  566.      the "-O" flag explicitely.
  567.      
  568.      
  569. 1.4 Assembly on a second processor
  570.  
  571.    The 65C02 Assembler is  compatible  with  both  the  external  6502
  572. second  processor,  and  with  the  Master  Turbo-Card. Using a second
  573. processor will give a faster assembly due to the higher clock rate  of
  574. the  processor,  and  will  also  give  you more memory for the symbol
  575. table.
  576.  
  577.    A second processor allows you to organise your source files to take
  578. advantage of a source file memory buffer. Any source file that is less
  579. than 14 kilobytes in size is *LOADed into memory  and  assembled  from
  580. there:  since  the Assembler does not then need to wait for data to be
  581. fetched from disc, assembly will speed up  dramatically.  It  is  well
  582. worth arranging your program so each of its source files will fit into
  583. this buffer area.
  584.  
  585.  
  586.  
  587.                                   5
  588.  
  589.  
  590.  
  591.  
  592.  
  593.                       USING THE 65C02 ASSEMBLER 
  594.  
  595.  
  596.  
  597.    The  source  buffer  is  automatically  switched  on  when a second
  598. processor is in use.
  599.  
  600.  
  601. 1.5 The object code buffer
  602.  
  603.    The Assembler allows you to select an object code buffer in memory.
  604. Code bytes generated from the source are  written  into  this  buffer,
  605. rather  than  being sent directly to the object file, and this gives a
  606. substantial increase in speed of  assembly.  Whenever  the  buffer  is
  607. full,  the assembly will pause in reading source to write the contents
  608. to the object file. It then resumes assembly until  the  buffer  again
  609. fills, and so on.
  610.  
  611.    You  can  specify the buffer size with the "-B" option. The flag is
  612. followed by a number between 1 and  16,  giving  the  buffer  size  in
  613. kilobytes.   Note   that   using   a   buffer   means  that  there  is
  614. correspondingly less space available for the symbol table.
  615.  
  616.    The fastest assembly will be achieved when  the  object  code  fits
  617. entirely into the buffer. In this case, the Assembler will produce the
  618. object  file  with  *SAVE,  which  is  substantially  faster even than
  619. writing it in large blocks.
  620.  
  621.  
  622. 1.6 Returning to the calling language
  623.  
  624.    When an assembly finishes, the Assembler will  always  restart  the
  625. language ROM that was in use when you issued the *ASSEMBLE command. If
  626. this language was BASIC or the Assembler's own CLI mode, there will be
  627. no  difficulty:  however,  some  languages  such  as  WordWise or View
  628. immediately clear the screen when they start, so you may not have time
  629. to read the final lines that the Assembler displayed on the screen.
  630.  
  631.    To overcome this, the Assembler is able to pause when it ends until
  632. you press a key. It will do this whenever the previous language is not
  633. BASIC or the Assembler's CLI mode.
  634.  
  635.    If you don't wish it to pause (you may for example not want to read
  636. the final screen, or the language may not clear  the  screen),  simply
  637. specify  a  "-G"  option  in  the command line. Now the Assembler will
  638. immediately restart the previous language without a pause.
  639.  
  640.    There  are  two  cases  where  the  Assembler   will always   pause
  641. regardless of the "-G" option or the previous language. These are:
  642.  
  643.   - When an error is detected in the *ASSEMBLE command you typed
  644.     
  645.     or
  646.     
  647.   - On  a  machine  with  a shadow screen that was turned off when you
  648.     began assembly. The Assembler  will  turn  the  shadow  screen  on
  649.     automatically,  and  will  always  turn it off at the end: as this
  650.     requires a mode change which will clear the screen, it will always
  651.  
  652.  
  653.                                   6
  654.  
  655.  
  656.  
  657.  
  658.  
  659.                       USING THE 65C02 ASSEMBLER 
  660.  
  661.  
  662.  
  663.     pause.
  664.     
  665.     
  666. 1.7 Use of control keys during assembly
  667.  
  668.    During an assembly you can use various control  keys  to  check  on
  669. progress or give commands to the Assembler.
  670.  
  671.  
  672.   - Function keys f0, f1, f2 and f3 will force the Assembler to change
  673.     the  source  listing  level to 0, 1, 2 or 3 respectively. Once you
  674.     have pressed one of these keys the level you set  is  locked:  the
  675.     Assembler  will process LST directives in the source, but will not
  676.     implement them. This lets you, for example, change the list  level
  677.     during  an assembly to check on what's happening, or to suppress a
  678.     listing you decide you don't want. To cancel the  locking  of  the
  679.     list  level  and  return  to  that  set  by the last LST directive
  680.     processed, simply press CONTROL-L.
  681.     
  682.   - CONTROL-H displays some help information to remind you  about  the
  683.     use of control keys. The Assembler will pause after displaying the
  684.     information: to resume simply press any key.
  685.     
  686.   - CONTROL-N   and CONTROL-O  turn the BBC Computer's paged scrolling
  687.     mode on and off  respectively.  You  could  use  these  keys,  for
  688.     example, to pause a listing on the screen after every screenful at
  689.     some point during an assembly.
  690.     
  691.   - CONTROL-P  controls  whether  the  Assembler  sends  output to the
  692.     printer. If it is printing, pressing CONTROL-P will stop it: if it
  693.     is not printing, CONTROL-P will start it  sending  output  to  the
  694.     printer.
  695.     
  696.   - CONTROL-Q  lets you find out where the Assembler is in the current
  697.     file. It will tell you whether it is on pass 1 or 2, then give you
  698.     the number of the line it is about to process. If  the  number  is
  699.     followed  by  "(M)",  the  source  line  is  a  macro call and the
  700.     Assembler is currently expanding that macro.
  701.     
  702.   - CONTROL-W reverses the current "wait after error"  action  set  by
  703.     the command line's "-W" option.
  704.     
  705.   - SPACE  pauses  the assembly. You can use this to examine a listing
  706.     on screen at your leisure. To resume assembly,  simply  press  any
  707.     key.
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.                                   7
  720.  
  721.  
  722.  
  723.  
  724.  
  725.                       USING THE 65C02 ASSEMBLER 
  726.  
  727.  
  728.  
  729. 2. SOURCE PROGRAM FORMAT
  730.  
  731.  
  732.    The Assembler will read source from files produced by any editor or
  733. word-processor  program,  as  described  in section 1.2. The source is
  734. seen as a number of lines, each ending with  a  carriage  return  byte
  735. ($0D).  Line  feed  characters  are  ignored, as are all other control
  736. characters and any with the most significant  bit  (bit  7)  set.  The
  737. general format of a line is:
  738.  
  739.                    label  opcode  operand  ;comment
  740.  
  741.    Depending  on  circumstances,  the  label and operand fields may be
  742. optional or mandatory; or they may need to be omitted. All  lines  may
  743. have a comment field, which is begun with a ";" or a "\" character.
  744.  
  745.    If  you include a label field, it must begin in the first character
  746. of the line. You may separate the fields  from  each  other  with  any
  747. number  of spaces and/or TAB characters (code $09). No line may exceed
  748. 132 bytes in length; any that do will be truncated.
  749.  
  750.    Any line whose first non-space character is a "*", a ";" or  a  "\"
  751. is treated as comment.
  752.  
  753.  
  754. 2.1 Syntax of the line
  755.  
  756.  
  757.      2.1.1 The label field
  758.      
  759.      A  label  consists  of  a  string  of characters, starting with a
  760.      letter, and containing any combination of  letters,  numbers  and
  761.      the  characters  ".","$"  and  "_"  (underscore).  Any lower-case
  762.      letters are translated  to  upper-case.  Labels  may  be  of  any
  763.      length,  and  all  are  significant unless you have specified the
  764.      "-A" option in the command  line,  when  only  the  first  6  are
  765.      significant.
  766.      
  767.      A  label  may  be  terminated  with  a  ":" character that is not
  768.      considered part of the label.
  769.      
  770.      Examples of valid labels are:
  771.      
  772.                          OSWRCH
  773.                          osbyte
  774.                          Program.start
  775.                          ITEM_33:
  776.                          
  777.      A label may be written in a line on its own: the value it is  set
  778.      to will be the value of the current address.
  779.      
  780.      A  variant  of  the  label  is  the Sequence Symbol, described in
  781.      section 10.1. This has the same format as a  normal  label,  with
  782.      the exception that the first character must be a "%" character.
  783.  
  784.  
  785.                                   8
  786.  
  787.  
  788.  
  789.  
  790.  
  791.                       USING THE 65C02 ASSEMBLER 
  792.  
  793.  
  794.  
  795.      
  796.      Where  the label is a macro name (i.e. in the MACRO directive) it
  797.      may not exceed 8 characters in length.
  798.      
  799.      
  800.      2.1.2 The opcode field
  801.      
  802.      The opcode field, if present, is separated from the label by  one
  803.      or  more  spaces or TABs. If there is no label, the field must be
  804.      preceded by at least one space or TAB.
  805.      
  806.      The opcode field can contain  either  a  normal  opcode  mnemonic
  807.      (such  as  LDA),  an  Assembler  directive  or pseudo-op (such as
  808.      SFCOND) or the name of a macro that you have defined previously.
  809.      
  810.      
  811.      2.1.3 The operand field
  812.      
  813.      For some opcodes and directives an operand field may be supplied.
  814.      This will consist of one or more elements,  separated  by  commas
  815.      and  optional  spaces.  Except  within  strings  delimited by the
  816.      single- or double-quote characters, spaces are not significant in
  817.      the operand field. Thus you can use them to make complex  numeric
  818.      expressions more readable: for example you could write
  819.      
  820.                     LDA   TABLE+(1+FRED/3*(BERT+$1E))
  821.      
  822.      as
  823.      
  824.                     LDA   TABLE + (1 + FRED/3 * (BERT + $1E) )
  825.      
  826.      if you wished.
  827.      
  828.      
  829.      2.1.4 The comment field
  830.      
  831.      The  comment  field can be used to annotate the line. It is begun
  832.      with a  ";"  or  a  "\"  character:  anything  following  is  not
  833.      processed by the Assembler.
  834.      
  835.      
  836. 2.2 The syntax of expressions
  837.  
  838.    Throughout this guide you will see references to "expressions", for
  839. example  in  the  definitions of directives. The syntax of these is as
  840. follows:
  841.  
  842.  
  843.      2.2.1 Numeric expressions
  844.      
  845.      These are indicated in definitions as "<expr>",  and  consist  of
  846.      terms  separated  by  arithmetic  operators. For example, a valid
  847.      expression might be
  848.      
  849.  
  850.  
  851.                                   9
  852.  
  853.  
  854.  
  855.  
  856.  
  857.                       USING THE 65C02 ASSEMBLER 
  858.  
  859.  
  860.  
  861.                             FRED*(2+BERT)
  862.      
  863.      The Assembler performs all calculations using 16-bit  arithmetic.
  864.      Any   results  or  intermediate  values  that  overflow  will  be
  865.      truncated, and no warning will be given.
  866.      
  867.      The various elements that you can use in numeric expressions  are
  868.      these:
  869.      
  870.      a. Symbols
  871.         
  872.         These  are  the  labels that you define in the label fields of
  873.         lines, and in  the  evaluation  of  the  expression  they  are
  874.         replaced by the value of the label.
  875.         
  876.      b. Decimal constants
  877.         
  878.         These are numbers, composed of the characters '0'..'9'.
  879.         
  880.         For example,
  881.         
  882.                                  123
  883.         
  884.      c. Hexadecimal constants
  885.         
  886.         These are numbers, composed of hexadecimal digits '0'..'9' and
  887.         'A'..'F', preceded by a "$" or a "&" character.
  888.         
  889.         For example,
  890.         
  891.                                 $AF34
  892.         
  893.      d. Binary constants
  894.         
  895.         These  are  numbers  composed  of  binary  digits '0' and '1',
  896.         preceded by a "%" character.
  897.         
  898.         For example,
  899.         
  900.                               %10100111
  901.         
  902.         
  903.      e. Character constants
  904.         
  905.         These are single characters, enclosed  in  single-quotes.  The
  906.         Assembler will use the ASCII code of the particular character.
  907.         
  908.         You  can specify that a character value is to be used with bit
  909.         7 set by preceding the character with a "^", and can specify a
  910.         control character by preceding it with a "|".  Thus  the  code
  911.         for  an "A" with bit 7 set is represented as '^A' and that for
  912.         CONTROL-A as '|A'.
  913.         
  914.         The character codes for "^" and "|" are  obtained  by  writing
  915.  
  916.  
  917.                                  10
  918.  
  919.  
  920.  
  921.  
  922.  
  923.                      |USING THE 65C02 ASSEMBLER|
  924.  
  925.  
  926.  
  927.         the characters twice (i.e. as '^^' and '||').
  928.         
  929.         Note that you must always include the final quote character.
  930.         
  931.         For example,
  932.         
  933.                                  'X'
  934.         
  935.      f. Operators
  936.         
  937.         A  number  of arithmetic operators can be used in expressions.
  938.         They are divided into groups of varying  priority,  which,  in
  939.         decreasing order are:
  940.                     
  941.                     () Parentheses
  942.                     
  943.                     -  Unary minus
  944.                     ~  Unary 1's complement (NOT)
  945.                     
  946.                     &  Bitwise AND
  947.                     !  Bitwise OR
  948.                     
  949.                     =  Equality
  950.                     #  Inequality
  951.                     >  Greater than
  952.                     <  Less than
  953.                     
  954.                     *  Multiplication
  955.                     /  Integer division
  956.                     
  957.                     +  Addition
  958.                     -  Subtraction
  959.                     
  960.         The  "="  and "#" operators return values of -1 and 0 for TRUE
  961.         and FALSE respectively.
  962.         
  963.         Additionally, expressions  may  be  prefixed  with  two  unary
  964.         operators  > and <, which select the low-byte and high-byte of
  965.         the result  respectively.  These  operators  have  the  lowest
  966.         priority of all.
  967.         
  968.         
  969.      g. Current address
  970.         
  971.         The current value of the address counter may be represented in
  972.         expressions by the "*" character.
  973.         
  974.         For example:
  975.         
  976.                                  *-3
  977.         
  978.         
  979.      2.2.2 Strings
  980.      
  981.  
  982.  
  983.                                  11
  984.  
  985.  
  986.  
  987.  
  988.  
  989.                       USING THE 65C02 ASSEMBLER 
  990.  
  991.  
  992.  
  993.      These  are  indicated  in definitions as <string>, and consist of
  994.      one or more ASCII characters, enclosed in  delimiters.  Only  the
  995.      single-  and  double-quote  characters  ('  and ") can be used as
  996.      delimiters, and the start and end delimiter must be the same.
  997.      
  998.      For example:
  999.      
  1000.                           'This is a string'
  1001.                       "And so, you see, is this"
  1002.      
  1003.      To include the ' or " character in a string, use the other as the
  1004.      delimiter.
  1005.      
  1006.      
  1007.      2.2.2 String expressions
  1008.      
  1009.      These are indicated  in  definitions  as  <stringexpr>,  and  all
  1010.      involve comparisons between strings. The general format is
  1011.      
  1012.                         <string> <op> <string>
  1013.      
  1014.      where <op> is one of the operators
  1015.      
  1016.                          =  Equality
  1017.                          #  Inequality
  1018.                          >  Greater than
  1019.                          <  Less than
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025.  
  1026.  
  1027.  
  1028.  
  1029.  
  1030.  
  1031.  
  1032.  
  1033.  
  1034.  
  1035.  
  1036.  
  1037.  
  1038.  
  1039.  
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049.                                  12
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  
  1055.                       USING THE 65C02 ASSEMBLER 
  1056.  
  1057.  
  1058.  
  1059. 3. THE OUTPUT LISTING
  1060.  
  1061.  
  1062.    The assembly listing is produced in pass 2. You can control whether
  1063. it  appears  or  not,  whether  it  goes to screen or printer, and the
  1064. amount of detail it contains.
  1065.  
  1066.  
  1067. 3.1 The source listing level
  1068.  
  1069.  
  1070.    The main control you have over the listing is through  the  "source
  1071. listing  level".  This  is  a value in the range 0..3 that you can set
  1072. either with the LST directive, the -L command  line  option,  or  with
  1073. function keys 0 to 3 during the course of an assembly.
  1074.  
  1075.    The listing levels have the following meaning:
  1076.  
  1077.   0  This level suppresses all listing except the reporting of errors.
  1078.      
  1079.   1  This  level  will  list all source lines that originate in source
  1080.      files, but not the expansions of macros.
  1081.      
  1082.   2  This  level  lists  all  lines  from  source  files   and   macro
  1083.      expansions, but not Macro Programming Language statements such as
  1084.      AIF.
  1085.      
  1086.   3  This level lists all source lines.
  1087.      
  1088.    By  default,  the Assembler sets the source list level to 0, so all
  1089. you will see will be error reports. You can change the default setting
  1090. in the *ASSEMBLE command by using the "-L" option: thus
  1091.  
  1092.                          *ASSEMBLE SOURCE -L2
  1093.  
  1094. would cause the Assembler to start with a default listing level of 2.
  1095.  
  1096.    Within the source, you can control the  list  level  with  the  LST
  1097. directive. Thus:
  1098.  
  1099.                                 LST  1
  1100.  
  1101. would set the list level to 1.
  1102.  
  1103.    Simply writing
  1104.  
  1105.                                  LST
  1106.  
  1107. with no operand field will reset the value to the default, without you
  1108. needing to build this value into the actual source.
  1109.  
  1110.    Additionally,  you  can  override  the  list  level in use while an
  1111. assembly is in progress. Pressing one of function keys  0  to  3  will
  1112. force  the  corresponding  list  level  to  be  adopted,  so that, for
  1113.  
  1114.  
  1115.                                  13
  1116.  
  1117.  
  1118.  
  1119.  
  1120.  
  1121.                       USING THE 65C02 ASSEMBLER 
  1122.  
  1123.  
  1124.  
  1125. example, you could force  the  Assembler  to  show  you  parts  of  an
  1126. assembly  to  monitor  what was being done. Pressing one of these keys
  1127. will "lock" the list level to that selected, so that LST directives in
  1128. the source will not be  able  to  turn  the  listing  off  again.  The
  1129. directives are noted, though, and you can return listing level control
  1130. to them at any time by pressing CONTROL-L.        
  1131.  
  1132.  
  1133. 3.2 Source listing format
  1134.  
  1135.    The  listing begins with the source lines, including any code bytes
  1136. they have generated.
  1137.  
  1138.    The first character on the line indicates where the line  was  read
  1139. from.  If  it  came from an INCLUDE file the character will be "I"; if
  1140. the line is from a macro it will be "M". Otherwise, the character is a
  1141. space.
  1142.  
  1143.    The next element is the line number, reset to 1  at  the  start  of
  1144. each source file.
  1145.  
  1146.    Next  comes  the  address  field.  This  will  normally contain the
  1147. current value of the address counter; in some directives, though, such
  1148. as LST, it contains the value of the operand expression.
  1149.  
  1150.    Then comes a hexadecimal representation of the first 3 object bytes
  1151. generated by the line; this is followed by the source line itself.  By
  1152. default,  if the source line generated more than 3 object bytes, these
  1153. will be listed on subsequent lines.
  1154.  
  1155.    For example, a listing line might show:
  1156.  
  1157.                    I   23 AB34:C9 0A      CMP  #10
  1158.  
  1159. where the source line is the 23rd line in an INCLUDE  file  and  reads
  1160. "CMP  #10".  The  code  bytes  generated are $C9 and $0A, and they are
  1161. planted starting at address $AB34.
  1162.  
  1163.  
  1164.      3.2.1 The code listing level
  1165.      
  1166.      
  1167.      As mentioned above, the first three code  bytes  generated  by  a
  1168.      source  line  are listed on that line, and any others will appear
  1169.      on  subsequent  lines.  This  may  produce  a  lot   of   output,
  1170.      particularly  if  you  define  lots  of strings, so the Assembler
  1171.      gives you control on how much it lists.
  1172.      
  1173.      The amount is controlled by the "code listing level". This  is  a
  1174.      value  in  the  range  0..3 that you can set either with the CLST
  1175.      directive or the -C command line option.
  1176.      
  1177.      
  1178.  
  1179.  
  1180.  
  1181.                                  14
  1182.  
  1183.  
  1184.  
  1185.  
  1186.  
  1187.                       USING THE 65C02 ASSEMBLER 
  1188.  
  1189.  
  1190.  
  1191.      The code listing levels have the following meaning:
  1192.      
  1193.        0  Only the first 3 bytes generated by a line are listed.
  1194.           
  1195.        1  All  bytes  are  listed  from  all  lines  except  the  CODE
  1196.           directive.
  1197.           
  1198.        2  All bytes are listed, however they are generated.
  1199.           
  1200.           
  1201.      By  default, the Assembler sets the code list level to 1. You can
  1202.      change the default setting in the *ASSEMBLE command by using  the
  1203.      "-L" option: thus
  1204.      
  1205.                          *ASSEMBLE SOURCE -C0
  1206.      
  1207.      would  cause  the  Assembler to start with a default code listing
  1208.      level of 0.
  1209.      
  1210.      Within the source, you can control the code  listing  level  with
  1211.      the CLST directive. Thus:
  1212.      
  1213.                                CLST  2
  1214.      
  1215.      would set the list level to 2.
  1216.      
  1217.      Simply writing
  1218.      
  1219.                                  CLST
  1220.      
  1221.      with  no  operand  field  will  reset  the  value to the default,
  1222.      without you needing to build this value into the actual source.
  1223.      
  1224.      
  1225. 3.3 Symbol table listing format
  1226.  
  1227.    If the source listing level is not zero at the end of the assembly,
  1228. the Assembler will list the symbol table, showing you the value of all
  1229. the symbols defined in the source.
  1230.  
  1231.    The symbols are listed in alphabetical order, and only the first 13
  1232. characters of each will be shown. The value of each symbol is shown in
  1233. hexadecimal.
  1234.  
  1235.    If the value is shown as "????", the symbol was used  but  was  not
  1236. defined.  If  the  value  is  "****", the symbol was defined more than
  1237. once. A "-" character after the value indicates that  the  symbol  was
  1238. defined, but was not used anywhere else in the source.
  1239.  
  1240.  
  1241. 3.4 Error reports
  1242.  
  1243.    The  Assembler will list all lines that generate errors, regardless
  1244. of the listing level. The errors are  reported  with  self-explanatory
  1245.  
  1246.  
  1247.                                  15
  1248.  
  1249.  
  1250.  
  1251.  
  1252.  
  1253.                       USING THE 65C02 ASSEMBLER 
  1254.  
  1255.  
  1256.  
  1257. text messages following the line.
  1258.  
  1259.    Where  appropriate, the Assembler will attempt to indicate where on
  1260. the line the  error  occured.  The  text  you  might  see  would  look
  1261. something like:
  1262.  
  1263.          ****** Err : Undeclared symbol at about character 19
  1264.  
  1265.    This  indicates  that  the  erroneous  symbol  is at about the 19th
  1266. character in the line, which starts at character 1. Remember,  though,
  1267. that  the  number refers to the source line: the listing line may have
  1268. expanded any TAB characters you used, and the  number  will  then  not
  1269. correspond to what you see on the page.
  1270.  
  1271.  
  1272.  
  1273. 3.5 Output page control
  1274.  
  1275.  
  1276.    The  Assembler  provides a number of directives that you can use to
  1277. specify the exact format of the output page, and to let you tailor the
  1278. listing to your exact needs.
  1279.  
  1280.  
  1281.      3.5.1 Setting page dimensions
  1282.      
  1283.      The PAGE directive defines the size of the page you are using. It
  1284.      takes two parameters, which are the total depth of  the  page  in
  1285.      lines, and the width in characters you wish printed.
  1286.      
  1287.      Thus,
  1288.      
  1289.                             PAGE   66,132
  1290.      
  1291.      tells  the Assembler that the page is 66 lines deep, and that you
  1292.      wish lines to contain a maximum of 132 characters. The  Assembler
  1293.      will always allow a small gap at the end of the page to avoid the
  1294.      perforations, and will truncate any lines longer than the maximum
  1295.      width you specify.
  1296.      
  1297.      The  value of the width you define with PAGE becomes effective at
  1298.      once. The depth, though, is not used until the next  page  throw,
  1299.      so  you would normally follow the directive with a TTL or a SKP H
  1300.      directive.
  1301.      
  1302.      By default, the Assembler will print lines of  80  characters  on
  1303.      paper that is 66 lines deep. It moves to the top of a new page by
  1304.      sending a Form Feed ($0C) character to the printer.
  1305.      
  1306.      
  1307.      3.5.2 Setting the page title
  1308.      
  1309.      
  1310.      The TTL directive lets you set up a page title that is printed on
  1311.  
  1312.  
  1313.                                  16
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319.                       USING THE 65C02 ASSEMBLER 
  1320.  
  1321.  
  1322.  
  1323.      the  top  of  every  listing  page.  The  title  can  be up to 20
  1324.      characters long, and can contain any printable text.
  1325.      
  1326.      For example,
  1327.      
  1328.                          TTL  'Screen Dumper'
  1329.      
  1330.      will print "Screen Dumper" at the top of each page.
  1331.      
  1332.      The TTL directive will cause a page throw to  occur  immediately,
  1333.      and the next page output will use the title it defines.
  1334.      
  1335.      
  1336.      3.5.3 Setting the timestamp
  1337.      
  1338.      
  1339.      If  you  are using a Master 128, the Assembler will automatically
  1340.      print the current date and time at the top of each  output  page,
  1341.      taking  the  values  from the built-in real-time clock. The other
  1342.      BBC models do not contain clocks, so the TIME directive lets  you
  1343.      simulate the effect by defining the string used.
  1344.      
  1345.      The  TIME  directive  allows  you  to define a string of up to 25
  1346.      characters that will appear in the page header.  The  string  can
  1347.      contain  any  printable characters: it is not constrained to be a
  1348.      date and time value, so you can use it  as  a  sub-title  if  you
  1349.      wish.
  1350.      
  1351.      For example, you could use
  1352.      
  1353.                         TIME  'Friday at 1030'
  1354.      
  1355.      or
  1356.      
  1357.                          TIME  'First Module'
  1358.      
  1359.      
  1360.      The  directive is ignored on a Master 128, so there is no need to
  1361.      change a source that is being assembled on both a model B  and  a
  1362.      Master 128.
  1363.      
  1364.      
  1365.      3.5.4 Control of output layout
  1366.      
  1367.      
  1368.      There are a number of directives that let you lay the output page
  1369.      out  in  more  detail,  so you can delimit sections of source for
  1370.      easier inspection.
  1371.      
  1372.      The  REP  directive  provides  a  convenient  way  of  separating
  1373.      sections of code in the listing. For example,
  1374.      
  1375.                                REP  80
  1376.      
  1377.  
  1378.  
  1379.                                  17
  1380.  
  1381.  
  1382.  
  1383.  
  1384.  
  1385.                       USING THE 65C02 ASSEMBLER 
  1386.  
  1387.  
  1388.  
  1389.      will  print  a line of "*" characters in the listing for you (and
  1390.      takes much less space in the source file than  that  line  itself
  1391.      would).
  1392.      
  1393.       The CHR directive lets you change the character used to make the
  1394.      line,  so  that,  for  eaxmple  you  could  select  lines  of "-"
  1395.      characters with
  1396.      
  1397.                                 REP  -
  1398.      
  1399.      
  1400.      The SKP directive lets  you  break  the  listing  up  for  easier
  1401.      reading. For example,
  1402.      
  1403.                                 SKP  5
  1404.      
  1405.      would leave a 5 line space on the page. The format
  1406.      
  1407.                                 SKP  H
  1408.      
  1409.      causes  the  Assembler  to  start  a  new page. Note that the SKP
  1410.      directive itself will never  be  listed  unless  it  contains  an
  1411.      error.
  1412.      
  1413.      
  1414. 3.6 Controlling the output destination
  1415.  
  1416.  
  1417.    By  default,  the Assembler sends the output listing to the screen,
  1418. in whatever mode you have selected. If you wish, you can direct output
  1419. to the cuurently-selected printer by specifying the "-P" option in the
  1420. command line. Thus, for example,
  1421.  
  1422.                        *ASSEMBLE SOURCE -L2 -P
  1423.  
  1424. would assemble from source  file  SOURCE  and  send  the  listing,  at
  1425. listing level 2, to the printer only.
  1426.  
  1427.    At  any  time  during  an  assembly,  you  can  change  the  output
  1428. destination  by  pressing  CONTROL-P.  This  will  switch  the  output
  1429. destination  between  printer  and screen: you can do this as often as
  1430. you wish.
  1431.  
  1432.  
  1433.  
  1434.  
  1435.  
  1436.  
  1437.  
  1438.  
  1439.  
  1440.  
  1441.  
  1442.  
  1443.  
  1444.  
  1445.                                  18
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.                       USING THE 65C02 ASSEMBLER 
  1452.  
  1453.  
  1454.  
  1455. 4. DIRECTIVES DEFINING DATA AND CONSTANTS
  1456.  
  1457.  
  1458.    The Assembler contains a number of directives  that  allow  you  to
  1459. define  values  in  the  object  file.  You  can  specify byte values,
  1460. two-byte or word values,  and  character  strings,  and  also  set  up
  1461. symbols to hold constants.
  1462.  
  1463.  
  1464. 4.1 Defining constants
  1465.  
  1466. Assigning symbols to various constant values is a considerable help in
  1467. writing assembly-level programs, both in terms of making a source more
  1468. readable and also in helping when you need to change it.
  1469.  
  1470. For example, you could refer to an Operating System routine by writing
  1471. its  address $FFEE every time, or you could declare a symbol OSWRCH to
  1472. stand for that name.
  1473.  
  1474. You can declare symbols to use as constants with the EQU directive. In
  1475. the example above, you would write
  1476.  
  1477.                          OSWRCH  EQU   $FFEE
  1478.  
  1479. and then call the routine as, say
  1480.  
  1481.                              JSR   OSWRCH
  1482.  
  1483. You can write any numeric expression in the operand field of  the  EQU
  1484. directive, but the expression must not contain any forward references.
  1485.  
  1486.  
  1487.  
  1488. 4.2 Byte and word directives
  1489.  
  1490. There  are  6  directives  that plant byte and word values. DFB plants
  1491. bytes, and DFW and  DFDB  plant  word  values.  For  convenience,  and
  1492. compatibility with other asemblers, the directives can also be written
  1493. as DB, DW and DDB respectively.
  1494.  
  1495. All the directives can be given one or more expressions in the operand
  1496. field,  separated  by commas, and these expressions give the values of
  1497. the bytes or words to be planted. If you specify a label in the  label
  1498. filed  of  the line, it is set to the address of the first byte of the
  1499. first value planted.
  1500.  
  1501.  
  1502.  
  1503.      4.2.1 Byte directives
  1504.      
  1505.      
  1506.      The directive DFB (or its equivalent DB)  allows  you  to  define
  1507.      single-byte  values  which  are  written directly into the object
  1508.      file. The operand field is one or more expressions, each of which
  1509.  
  1510.  
  1511.                                  19
  1512.  
  1513.  
  1514.  
  1515.  
  1516.  
  1517.                       USING THE 65C02 ASSEMBLER 
  1518.  
  1519.  
  1520.  
  1521.      should lie in the range 0..255 .
  1522.      
  1523.      For example,
  1524.      
  1525.                          DFB  1,2,$FF,FRED+1
  1526.      
  1527.      will write 4 bytes to the object file: the values will be  1,  2,
  1528.      255 and the value of FRED+1.
  1529.      
  1530.      
  1531.      4.2.2 Word directives
  1532.      
  1533.      
  1534.      The  directives  DFW  (or  its  equivalent  DW)  and DFDB (or its
  1535.      equivalent DDB)  allow you to  define  two-byte  or  word  values
  1536.      which  are  written  directly  into  the object file. The operand
  1537.      field of each is a list of one or more expressions, each of which
  1538.      should lie in the range 0..65535.
  1539.      
  1540.      The difference between the directives lies in the order in  which
  1541.      the  two  bytes are written to the object file. The DFW directive
  1542.      writes the bytes in low-byte, high-byte order; the DFDB directive
  1543.      writes them in high-byte, low byte order.
  1544.      
  1545.      Thus, for example,
  1546.      
  1547.                           DFW   $1234,$ABCD
  1548.      
  1549.      will output the bytes $34, $12, $CD, $AB to the  object  file  in
  1550.      that order, but
  1551.      
  1552.                           DFDB  $1234,$ABCD
  1553.      
  1554.      will output the bytes $12, $34, $AB, $CD.
  1555.      
  1556.      
  1557.      4.2.3 Using repeat counts
  1558.      
  1559.      
  1560.      Occasionally, you will need to use the byte or word directives to
  1561.      plant  a  number of bytes or words containing the same value. For
  1562.      example, you might need to write
  1563.      
  1564.                           DFB  5,5,5,5,5,5,5
  1565.      
  1566.      to plant 7 bytes containing the value 5.
  1567.      
  1568.      For small numbers of repeats, this is no problem, but it  can  be
  1569.      onerous if, say, you needed 49 bytes containing 5.
  1570.      
  1571.      The  Assembler  gives  you  a  very  convenient  shorthand way of
  1572.      repeating values in all  the  byte  and  word  directives.  Every
  1573.      expression  you  use can be prefixed with a "repeat count", which
  1574.      tells the Assembler to plant the value itself more than once. The
  1575.  
  1576.  
  1577.                                  20
  1578.  
  1579.  
  1580.  
  1581.  
  1582.  
  1583.                       USING THE 65C02 ASSEMBLER 
  1584.  
  1585.  
  1586.  
  1587.      repeat count is specified in "[]" brackets: thus, to plant the 49
  1588.      bytes mentioned above, you could simply write
  1589.      
  1590.                              DFB   [49]5
  1591.      
  1592.      Like the value itself, the repeat count can  be  any  expression,
  1593.      but it must not contain forward references. Thus you could write
  1594.      
  1595.                         DFB  [(COUNT+27)/2]$FF
  1596.      
  1597.      You  can  freely mix values with and without repeat counts in any
  1598.      of the byte and word directives.
  1599.      
  1600.      
  1601. 4.3 Character string directives
  1602.  
  1603.  
  1604. The four directives ASC,  CASC,  STR  and  CSTR  allow  you  to  plant
  1605. character string values into the object file.
  1606.  
  1607. All the directives require you to specify a character string, enclosed
  1608. in  single-  or  double-quotes, in the operand field. If you include a
  1609. label in the label field of the line, it is given  the  value  of  the
  1610. address of the first byte planted.
  1611.  
  1612.  
  1613.      4.3.1 The ASC and STR directives
  1614.      
  1615.      These  directives  plant  simple  strings in the object file. ASC
  1616.      plants the string exactly as  you  specify  it;  STR  plants  the
  1617.      string,  and  then  automatically  plants  a carriage-return byte
  1618.      (code $0D) immediately after it.
  1619.      
  1620.      Thus
  1621.      
  1622.                               ASC  'ABC'
  1623.      
  1624.      plants the bytes $41, $42, $43 in the obect file, and
  1625.      
  1626.                               STR  'ABC'
  1627.      
  1628.      plants the bytes $41, $42, $43, $0D.
  1629.      
  1630.      
  1631.      4.3.2 The CASC and CSTR directives
  1632.      
  1633.      
  1634.      These directives plant "counted strings" in  the  operand  field.
  1635.      They  are  similar  to ASC and STR, except that the bytes planted
  1636.      are preceded by a single byte giving the length of the string. 
  1637.      
  1638.      Thus, to use the same examples as above,
  1639.      
  1640.                              CASC  'ABC'
  1641.  
  1642.  
  1643.                                  21
  1644.  
  1645.  
  1646.  
  1647.  
  1648.  
  1649.                       USING THE 65C02 ASSEMBLER 
  1650.  
  1651.  
  1652.  
  1653.      
  1654.      plants the bytes $03, $41, $42, $43 in the object file, and
  1655.      
  1656.                              CSTR  'ABC'
  1657.      
  1658.      plants the bytes $04, $41, $42, $43, $0D.
  1659.      
  1660.      Note that the count byte planted by CSTR includes  the  $0D  byte
  1661.      that the directive adds itself.
  1662.      
  1663.      
  1664.      4.3.3 Planting special characters
  1665.      
  1666.      
  1667.      The  strings  you give as the operands to ASC, CASC, STR and CSTR
  1668.      must of course be made up of printable characters in  the  source
  1669.      file,  but  the  Assembler allows you a way of specifying control
  1670.      characters and characters with the most-significan-bit set to 1.
  1671.      
  1672.      To specify a control character, you should precede the  character
  1673.      itself with a "|" character. Thus, if you wish to plant the value
  1674.      of  CONTROL-A,  the  string  should  contain "|A". This method is
  1675.      identical to the way in which you specify control  characters  in
  1676.      Operating System commands such as *KEY.
  1677.      
  1678.      To specify a character with bit 7 (the most significant bit) set,
  1679.      precede it with a "^" character: thus, to plant an "A" with bit 7
  1680.      set, specify it in the string as "^A".
  1681.      
  1682.      For example,
  1683.      
  1684.                             ASC  'A|AB^B'
  1685.      
  1686.      plants the bytes $41, $01, $42, $C2 in the object file.
  1687.      
  1688.      Should  you need to specify the "|" or "^" characters, you should
  1689.      double them in the string (i.e. write them as "||" and "^^")
  1690.      
  1691.      
  1692. 4.4 The HEX directive
  1693.  
  1694.  
  1695.    This directive is rather a hybrid of the DFB and ASC directives. It
  1696. plants a series of byte values into the object file, but  you  specify
  1697. the values as a string of hexadecimal digits.
  1698.  
  1699.    For example,
  1700.  
  1701.                            HEX  '1234ABCD'
  1702.  
  1703. plants the byte values $12, $34, $AB, $CD into the object file.
  1704.  
  1705.    The  string  you supply must contain valid hexadecimal digits (i.e.
  1706. '0'..'9' and 'A'..'F'). You can give the letters in either  upper-  or
  1707.  
  1708.  
  1709.                                  22
  1710.  
  1711.  
  1712.  
  1713.  
  1714.  
  1715.                       USING THE 65C02 ASSEMBLER 
  1716.  
  1717.  
  1718.  
  1719. lower-case.  If  the  string contains an odd number of characters, the
  1720. Assembler will automatically add a '0' to make the  final  hexadecimal
  1721. value complete.
  1722.  
  1723.  
  1724.  
  1725. 4.5 The CODE directive
  1726.  
  1727.  
  1728.    The  code  directive gives you a convenient way of including things
  1729. like screen dumps or already-compiled  relocatable  subroutines,  into
  1730. your programs.
  1731.  
  1732.    Suppose,  for  example,  you had prepared a mode 7 screen dump with
  1733. some Teletext editor system, and wanted to use this as a  banner  page
  1734. when  your  program  started.  One way of including this into the code
  1735. would be to examine the dump and convert it into the  appropriate  DFB
  1736. directives,  planting  each  byte  explicitely  by hand. However, this
  1737. might be a very time-consuming process, and would be very error-prone.
  1738.  
  1739.    Using CODE, though, removes the need to translate the dump into DFB
  1740. or similar directives. If, for example, the dump was in  file  BANNER,
  1741. writing
  1742.  
  1743.                              CODE  BANNER
  1744.  
  1745. would cause the Assembler to read it in and copy the bytes directly to
  1746. the object file, without processing them in any way.
  1747.  
  1748.    By  default,  the listing will show only the first 3 bytes included
  1749. from the CODE file, since otherwise a  considerable  amount  of  paper
  1750. might be used. If you do want to see all the bytes in the listing, use
  1751. the CLST directive to set the code listing level to 2 before using the
  1752. CODE directive itself.
  1753.  
  1754.  
  1755.  
  1756.  
  1757.  
  1758.  
  1759.  
  1760.  
  1761.  
  1762.  
  1763.  
  1764.  
  1765.  
  1766.  
  1767.  
  1768.  
  1769.  
  1770.  
  1771.  
  1772.  
  1773.  
  1774.  
  1775.                                  23
  1776.  
  1777.  
  1778.  
  1779.  
  1780.  
  1781.                       USING THE 65C02 ASSEMBLER 
  1782.  
  1783.  
  1784.  
  1785. 5. OBJECT FILE CONTROL DIRECTIVES
  1786.  
  1787.  
  1788.    The  Assembler  contains  a  number  of directives that control the
  1789. object file. They let you define the  actual  address  that  the  code
  1790. generated  will run at, map symbol definitions into workspace, and set
  1791. the load and execution addresses for the final result.
  1792.  
  1793.  
  1794. 5.1 Defining the current address
  1795.  
  1796.    In almost all programs you assemble, you  will  need  to  tell  the
  1797. Assembler the actual address at which the resulting code is to run. It
  1798. will then be able to assign the correct address values to labels.
  1799.  
  1800.    You define the current address with the ORG directive. For example,
  1801. you could write
  1802.  
  1803.  
  1804.                          ORG    $1900
  1805.                          
  1806. before  the  first code line in the source. This would set the address
  1807. value to $1900, and the Assembler would produce  code  based  on  that
  1808. address.
  1809.  
  1810.    You  can  specify  the  address  in  the  operand  field of the ORG
  1811. directive as any expression you like:  however,  since  the  Assembler
  1812. must  know  the  value to use on pass 1, the expression cannot contain
  1813. forward references.
  1814.  
  1815.    You can use as many ORG directives as you wish within your  program
  1816. source,  and  you  can  move the current address value to anywhere you
  1817. wish. However, you should remember  that  the  ORG  directive  has  no
  1818. effect on where in the object file bytes are written. Thus, the source
  1819. lines
  1820.  
  1821.  
  1822.                          ORG   $1900
  1823.                          LDA   #1
  1824.                          ORG   $3000
  1825.                          LDA   #2
  1826.                          
  1827. would  set  the  address to $1900, and write the two bytes for the LDA
  1828. instruction to the object file. It then sets the address to $3000  and
  1829. writes  the  bytes  for  the second LDA instruction: however, the four
  1830. bytes will be contiguous in the object file - the Assembler  will  not
  1831. generate  a  gap. You could use this effect, for instance, to write an
  1832. object file containing many sections of overlay code  -  each  section
  1833. would  be assembled to run at the same address, but they would lie one
  1834. after the other in the object file.
  1835.  
  1836. If you do require to leave a gap in the object file, you can  use  the
  1837. DS  directive to generate the required gap yourself (see section 5.2).
  1838. There is no way of making the Assembler move backwards in  the  object
  1839.  
  1840.  
  1841.                                  24
  1842.  
  1843.  
  1844.  
  1845.  
  1846.  
  1847.                       USING THE 65C02 ASSEMBLER 
  1848.  
  1849.  
  1850.  
  1851. file.
  1852.  
  1853.  
  1854.  
  1855. 5.2 Using dummy sections
  1856.  
  1857.  
  1858.    A  "dummy section" is a convenient way of laying out symbols within
  1859. the workspace that your  program  needs.  For  example,  suppose  your
  1860. program  needed  some  page zero workspace. You could build the actual
  1861. numeric addresses into the source, but it's  much  better  programming
  1862. practice to define some symbols to identify the locations.
  1863.  
  1864.    One  way  of  doing  this  would be to use the EQU directive, which
  1865. simply sets up a symbol and gives it a value. Thus you could write
  1866.  
  1867.  
  1868.                          WORK0  EQU   $00
  1869.                          WORK1  EQU   $01
  1870.                          WORK2  EQU   $02
  1871.                          
  1872. to set up three symbols. This is a perfectly adequate  technique,  but
  1873. suffers  from  the disadvantage that you would have to change a lot of
  1874. the source if, say, you ever wanted the page zero workspace  to  start
  1875. at some place other than address $00.
  1876.  
  1877.    A better technique is to define workspace in a dummy section, which
  1878. is  a  region  of  the source between DSECT and DEND directives. DSECT
  1879. instructs the Assembler that  a  layout  is  being  defined:  it  will
  1880. process  anything  that follows it, but it won't generate any code for
  1881. the object file. All it will do is work out what addresses any  labels
  1882. will take.
  1883.  
  1884.    Thus, you could write the above example as
  1885.  
  1886.                                 DSECT
  1887.                          WORK0  DFB   0
  1888.                          WORK1  DFB   0
  1889.                          WORK2  DFB   0
  1890.                                 DEND
  1891.                          
  1892.    Here  each  of the workspace locations has been defined as one byte
  1893. long with a DFB directive.  Since  the  Assembler  generates  no  code
  1894. within  a  DSECT,  the  actual value you place in the operand field is
  1895. quite arbitrary. This technique also lets you see clearly that  you've
  1896. set  the  locations up as one-byte values. If you wished, say, to make
  1897. them two-byte values, you could change the DFB directives to  DW.  The
  1898. Assembler  would  then  allow  two bytes to each label, and the source
  1899. would show this clearly.
  1900.  
  1901.    In the example above, we have implicitely taken  advantage  of  how
  1902. the  Assembler  handles  the address value within a DSECT..DEND block.
  1903. When it meets the first DSECT in a source, the Assembler makes a  note
  1904. of  the  address  value it is using in the code, and resets it to zero
  1905.  
  1906.  
  1907.                                  25
  1908.  
  1909.  
  1910.  
  1911.  
  1912.  
  1913.                       USING THE 65C02 ASSEMBLER 
  1914.  
  1915.  
  1916.  
  1917. for the DSECT..DEND block. When it meets the DEND,  it  resumes  using
  1918. the address it saved at the start.
  1919.  
  1920.    On  the second occurence of a DSECT, the effect is the same, except
  1921. that now the address within the DSECT..DEND block resumes at the value
  1922. it reached in the last block.
  1923.  
  1924.    If you don't wish to operate in this way, you can set  the  address
  1925. value  with  the  DSECT..DEND  block  yourself with the ORG directive.
  1926. Thus, if you wanted your page zero workspace to begin  at  some  other
  1927. location, you could write the source as
  1928.  
  1929.                                 DSECT
  1930.                                 ORG   $70
  1931.                          WORK0  DFB   0
  1932.                          WORK1  DFB   0
  1933.                          WORK2  DFB   0
  1934.                                 DEND
  1935.                          
  1936.  
  1937.  
  1938.      5.2.1 The DS directive
  1939.      
  1940.      
  1941.      Quite  often  you  will  need to define a large area of workspace
  1942.      within a DSECT..DEND block, for example as a  source  line  input
  1943.      buffer.  The  DFB and DW directives are convenient ways of laying
  1944.      out byte and word values, but there are no built-in directives to
  1945.      lay out, say, a 256-byte buffer.
  1946.      
  1947.      To do this, you can use the DS directive, which lets you lay  out
  1948.      any  number  of  bytes. For example, to lay out a 256-byte buffer
  1949.      you could write
  1950.      
  1951.                                 DSECT
  1952.                                 ORG    $A00
  1953.                          BUFFER DS     256
  1954.                                 DEND
  1955.                          
  1956.      The operand field of the DS directive  tells  the  Assembler  how
  1957.      much space you wish to lay out.
  1958.      
  1959.      Normally  the DS directive is used in DSECT..DEND blocks, but you
  1960.      can also use it in the code area of a program as  well.  In  this
  1961.      case,  the  Assembler  will write the appropriate number of bytes
  1962.      containing the value zero to the object file.
  1963.      
  1964.      
  1965.      5.2.2 Reading the current address
  1966.      
  1967.      
  1968.      You can use the value  of  the  current  address  counter  within
  1969.      expressions  by referring to it with the special symbol "*". This
  1970.      can be used exactly as any other symbol in expressions, so  that,
  1971.  
  1972.  
  1973.                                  26
  1974.  
  1975.  
  1976.  
  1977.  
  1978.  
  1979.                       USING THE 65C02 ASSEMBLER 
  1980.  
  1981.  
  1982.  
  1983.      say, you could work out the size of a data table with
  1984.      
  1985.                          TABLE   DFB   1
  1986.                                  DFB   2
  1987.                                  DFB   3
  1988.                          T.SIZE  EQU   *-TABLE-1
  1989.                          
  1990.      where  T.SIZE  will  be set to the number of bytes defined in the
  1991.      preceding table.
  1992.      
  1993.      
  1994. 5.3 Defining object load and execution addresses
  1995.  
  1996.  
  1997.    Every machine-code program on a BBC Computer needs to have  a  load
  1998. address  and an execution address associated with it. These values are
  1999. stored in the file's catalogue entry: when you then *RUN the file, the
  2000. filing system will load it to memory starting at the load address, and
  2001. will enter it with a JSR instruction going to the execution address.
  2002.  
  2003.    The addresses also tell the filing system whether the program is to
  2004. be run on a second processor, or  on  the  BBC  Computer  itself.  The
  2005. filing  system regards load and execution addresses as 4 byte (32 bit)
  2006. values. The lower two bytes or  word  of  each  address  represent  an
  2007. actual  address in memory and the top two bytes or word of the address
  2008. is a value that indicates which processor the file is to be loaded on.
  2009. The Assembler can handle only two-byte values in its arithmetic, so it
  2010. is necessary to set the two parts of each address separately.
  2011.  
  2012.  
  2013.  
  2014.      5.3.1 Specifying the low word of the addresses
  2015.      
  2016.      
  2017.       There are two ways of setting up the low words of the  addresses
  2018.      when  you  assemble  programs. By default, the Assembler will set
  2019.      the low words of both the load and the execution addresses to  be
  2020.      the  value  set by the first ORG directive that is not in a dummy
  2021.      section, and in many cases this is all you need do.
  2022.      
  2023.       If, though, you require something else, you can use the LOAD and
  2024.      EXEC directives to set the low word of  the  load  and  execution
  2025.      addresses respectively. Thus, for example,
  2026.      
  2027.      
  2028.                              LOAD  $1900
  2029.                              EXEC  START
  2030.      
  2031.      would  set  the low word of the load address to be $1900, and the
  2032.      low word of the execution address  to  be  whatever  address  the
  2033.      label START is defined as.
  2034.      
  2035.      
  2036.      5.3.2 Specifying the processor
  2037.  
  2038.  
  2039.                                  27
  2040.  
  2041.  
  2042.  
  2043.  
  2044.  
  2045.  
  2046.                       USING THE 65C02 ASSEMBLER 
  2047.  
  2048.  
  2049.  
  2050.      
  2051.      
  2052.      If  the top word of the load address is $FFFF, the file is loaded
  2053.      into the BBC Computer's own memory, whether or not you are  using
  2054.      a  second  processor. If the top word is 0, though, the file will
  2055.      be loaded into the second processor if you are using one.
  2056.      
  2057.      By default, the Assembler produces object files with the top word
  2058.      of the addresses set to $FFFF, so the files will load to the  BBC
  2059.      Computer's  memory.  The  MSW  directive, though, lets you change
  2060.      this value: thus
  2061.      
  2062.                                MSW   0
  2063.      
  2064.      lets you change the address to 0. You should always include  this
  2065.      directive if you write programs to run on a second processor.
  2066.  
  2067.  
  2068.  
  2069.  
  2070.  
  2071.  
  2072.  
  2073.  
  2074.  
  2075.  
  2076.  
  2077.  
  2078.  
  2079.  
  2080.  
  2081.  
  2082.  
  2083.  
  2084.  
  2085.  
  2086.  
  2087.  
  2088.  
  2089.  
  2090.  
  2091.  
  2092.  
  2093.  
  2094.  
  2095.  
  2096.  
  2097.  
  2098.  
  2099.  
  2100.  
  2101.  
  2102.  
  2103.  
  2104.  
  2105.  
  2106.                                  28
  2107.  
  2108.  
  2109.  
  2110.  
  2111.  
  2112.                       USING THE 65C02 ASSEMBLER 
  2113.  
  2114.  
  2115.  
  2116. 6. SOURCE FILE CONTROL DIRECTIVES
  2117.  
  2118.  
  2119.    The  Assembler  provides  a  number of directives that allow you to
  2120. control the source files which you are assembling. This lets you split
  2121. your source up into more than one file.
  2122.  
  2123.  
  2124. 6.1 Chaining source files
  2125.  
  2126.  
  2127.    If you are writing a large program, you will find it convenient  to
  2128. split  the source into a number of small files, rather than keeping it
  2129. in one large one. This approach not only  makes  editing  easier,  but
  2130. also helps you structure the source to reflect the organisation of the
  2131. program.  Additionally, if you have a second processor, keeping source
  2132. files to less than 14 kilobytes in size will give a very  considerable
  2133. increase in assembly speed (see section 1.4).
  2134.  
  2135.    You  can instruct the Assembler to assemble multiple files with the
  2136. CHN directive. This tells it to close the current source file and open
  2137. the one specified in the operand field.
  2138.  
  2139.    Thus, you could write
  2140.  
  2141.                               CHN  FILE2
  2142.  
  2143. as the last line  in  FILE1.  The  Assembler  will  close  FILE1,  and
  2144. continue  assembly  with  FILE2. Note that if the CHN directive is not
  2145. the last line a file, anything following it will be ignored.
  2146.  
  2147.    You can use CHN as many times as you wish in an assembly.
  2148.  
  2149.  
  2150. 6.2 Including one file into another
  2151.  
  2152.  
  2153.    A different way of using  multiple  source  files  is  to  use  the
  2154. INCLUDE  directive.  This  tells  the  Assembler  to  start assembling
  2155. another source file;  unlike  CHN,  however,  the  first  file  is not
  2156. closed.  When  the Assembler comes to the end of the included file, it
  2157. resumes in the original file at the line after the INCLUDE directive.
  2158.  
  2159.    One use of this directive might be to include a  file  of  standard
  2160. definitions or routines into a source. You might then write
  2161.  
  2162.                            INCLUDE  STDSUBS
  2163.  
  2164. to assemble the source of some standard routines.
  2165.  
  2166.    Lines  that  result  from assembling an included file are marked in
  2167. the listing by having an 'I' in the first column.
  2168.  
  2169.    Note that you cannot use an INCLUDE directive inside  a  file  that
  2170.  
  2171.  
  2172.                                  29
  2173.  
  2174.  
  2175.  
  2176.  
  2177.  
  2178.                       USING THE 65C02 ASSEMBLER 
  2179.  
  2180.  
  2181.  
  2182. you  are  including  already.  Nor  can  you  use  the  CHN  and  CODE
  2183. directives.
  2184.  
  2185.  
  2186.  
  2187.  
  2188.  
  2189.  
  2190.  
  2191.  
  2192.  
  2193.  
  2194.  
  2195.  
  2196.  
  2197.  
  2198.  
  2199.  
  2200.  
  2201.  
  2202.  
  2203.  
  2204.  
  2205.  
  2206.  
  2207.  
  2208.  
  2209.  
  2210.  
  2211.  
  2212.  
  2213.  
  2214.  
  2215.  
  2216.  
  2217.  
  2218.  
  2219.  
  2220.  
  2221.  
  2222.  
  2223.  
  2224.  
  2225.  
  2226.  
  2227.  
  2228.  
  2229.  
  2230.  
  2231.  
  2232.  
  2233.  
  2234.  
  2235.  
  2236.  
  2237.  
  2238.                                  30
  2239.  
  2240.  
  2241.  
  2242.  
  2243.  
  2244.                       USING THE 65C02 ASSEMBLER 
  2245.  
  2246.  
  2247.  
  2248. 7. CONDITIONAL ASSEMBLY
  2249.  
  2250.  
  2251.    The 65C02  Assembler  has  full  conditional  assembly  facilities,
  2252. allowing you easily to change the source being compiled.
  2253.  
  2254.  
  2255. 7.1 Assembly conditional on expressions
  2256.  
  2257.  
  2258.    Conditional  assembly that depends on the value of an expression is
  2259. achieved by using the IF, ELSE and FI  directives.  The  most  general
  2260. form of construction is this:
  2261.  
  2262.  
  2263.                     
  2264.                     IF   <expr>
  2265.                        .
  2266.                        TRUE block
  2267.                        .
  2268.                     ELSE
  2269.                        .
  2270.                        FALSE block
  2271.                        .
  2272.                     FI
  2273.                     
  2274.                     
  2275.    <expr>  can be any numeric expression, as described in section 2.2,
  2276. but it must not contain any forward references. If <expr> is non-zero,
  2277. the Assembler takes the condition as TRUE, and will assemble the lines
  2278. in the TRUE block. On coming to  the  ELSE  it  will  ignore  all  the
  2279. subsequent lines, until it reaches the FI; here assembly will continue
  2280. normally once more.
  2281.  
  2282.    If  <expr>  is  zero,  the  condition  is FALSE. The Assembler will
  2283. ignore the lines that follow until it reaches the ELSE; it  then  will
  2284. assemble the lines in the FALSE block.
  2285.  
  2286.    If  you wish, you can omit the ELSE and the FALSE block of code, to
  2287. form
  2288.  
  2289.                     
  2290.                     IF   <expr>
  2291.                        .
  2292.                        TRUE block
  2293.                        .
  2294.                     FI
  2295.                     
  2296.                     
  2297.    Here, if the condition is FALSE,  the  Assembler  will  ignore  all
  2298. lines up to the FI, so no code is assembled in this case.
  2299.  
  2300.  
  2301.  
  2302.  
  2303.  
  2304.                                  31
  2305.  
  2306.  
  2307.  
  2308.  
  2309.  
  2310.                       USING THE 65C02 ASSEMBLER 
  2311.  
  2312.  
  2313.  
  2314.  
  2315.    For example, you might have a symbol DEBUG.MODE defined at the very
  2316. start  of  the source to show if debug code is to be assembled or not.
  2317. This might be defined as
  2318.  
  2319.  
  2320.         DEBUG.MODE  EQU   -1    ;use -1 for TRUE, 0 for FALSE
  2321.         
  2322.         
  2323. Then, throughout the rest of the source, you can put the debug code in
  2324. an IF condition of the form
  2325.  
  2326.                     
  2327.                     IF   DEBUG.MODE
  2328.                        .
  2329.                        debug mode version
  2330.                        .
  2331.                     ELSE
  2332.                        .
  2333.                        non-debug mode version
  2334.                        .
  2335.                     FI
  2336.                     
  2337.    Depending on circumstances, you may wish to reverse  the  condition
  2338. tested to include some code if debug mode is not selected. You can use
  2339. the unary 1's complement or NOT operator here: thus
  2340.  
  2341.                     
  2342.                     IF   ~DEBUG.MODE
  2343.                        .
  2344.                        non-debug mode version
  2345.                        .
  2346.                     FI
  2347.                     
  2348. includes code if DEBUG.MODE is set to 0.
  2349.  
  2350.    The  IF..ELSE..FI  construction  can  also  be  written  using  the
  2351. directives DO..ELSE..FIN (or with any combination of them)
  2352.  
  2353.  
  2354. 7.2 Assembly conditional on the existence of symbols
  2355.  
  2356.  
  2357.    Two variants of the IF directive, IFDEF and IFNDEF,  allow  you  to
  2358. test  for  the existence or otherwise of symbols. IFDEF is TRUE if the
  2359. symbol in the operand field does exist; IFNDEF is TRUE if it does not.
  2360.  
  2361.    Thus the example above might have been written as
  2362.  
  2363.  
  2364.  
  2365.  
  2366.  
  2367.  
  2368.  
  2369.  
  2370.                                  32
  2371.  
  2372.  
  2373.  
  2374.  
  2375.  
  2376.                       USING THE 65C02 ASSEMBLER 
  2377.  
  2378.  
  2379.  
  2380.                     
  2381.                     IFDEF  DEBUG.MODE
  2382.                        .
  2383.                        debug mode version
  2384.                        .
  2385.                     ELSE
  2386.                        .
  2387.                        non-debug mode version
  2388.                        .
  2389.                     FI
  2390.                     
  2391. where the mere existence of the symbol  DEBUG.MODE  would  select  the
  2392. debug code, regardless of its value.
  2393.  
  2394.  
  2395. 7.3 Nesting conditionals
  2396.  
  2397.    The  Assembler  allows  you to "nest" conditionals. Within a nested
  2398. condition, an ELSE directive will be associated with  the  immediately
  2399. preceding IF, IFDEF or IFNDEF.
  2400.  
  2401.  
  2402. 7.4 Listing conditionals
  2403.  
  2404.    By  default, the Assembler will list all the lines that it skips in
  2405. a conditional, printing an "S" in the address field.
  2406.  
  2407.    To save paper, or  make  the  listing  clearer,  you  can  suppress
  2408. listing  of  skipped lines with the SFCOND directive, or by specifying
  2409. the "-S" option in the command line. you can re-instate the listing of
  2410. false conditional branches at any time with the LFCOND directive.
  2411.  
  2412.  
  2413.  
  2414.  
  2415.  
  2416.  
  2417.  
  2418.  
  2419.  
  2420.  
  2421.  
  2422.  
  2423.  
  2424.  
  2425.  
  2426.  
  2427.  
  2428.  
  2429.  
  2430.  
  2431.  
  2432.  
  2433.  
  2434.  
  2435.  
  2436.                                  33
  2437.  
  2438.  
  2439.  
  2440.  
  2441.  
  2442.                       USING THE 65C02 ASSEMBLER 
  2443.  
  2444.  
  2445.  
  2446. 8. PROGRESS REPORTING
  2447.  
  2448.  
  2449.    The Assembler supports several directives that allow you to  output
  2450. progress reports to the screen to show the course of an assembly.
  2451.  
  2452.  
  2453. 8.1 The DISP, DISP1 and DISP2 directives
  2454.  
  2455.    These  all  display a message on the screen. DISP displays the text
  2456. on both passes; DISP1 and DISP2 display the text on pass  1  only  and
  2457. pass  2  only, respectively. You can use INFO as a synonym of DISP2 is
  2458. you wish.
  2459.  
  2460.    The use of the directives is the same: for example, you might write
  2461.  
  2462.  
  2463.                     DISP  'Assembling debug code'
  2464.  
  2465.  
  2466. to display
  2467.  
  2468.  
  2469.                       ---- Assembling debug code
  2470.  
  2471.  
  2472. on the screen.
  2473.  
  2474.  
  2475.    The message you display can contain printable  text,  and  you  can
  2476. also include some control characters. You specify them in the same way
  2477. as  you  would  in  any  other  string,  by  preceding them with a "|"
  2478. character. The control characters you can use are:
  2479.  
  2480.  
  2481.                     |M and |J  - start a new line
  2482.                     |G         - make a beep sound
  2483.                     
  2484.    For example
  2485.  
  2486.                       DISP   'Line 1|MLine 2|G'
  2487.  
  2488. displays a 2 line message and rings the bell.
  2489.  
  2490.    Additionally, the text can contain  numeric  expressions  that  are
  2491. evaluated  as  the  message is output. For example, this would let you
  2492. output a message to report the size of a section of code.
  2493.  
  2494.    Within the text, you can specify an expression in one of two ways.
  2495.  
  2496.                               %D(<expr>)
  2497.  
  2498. will evaluate <expr> and display the result in decimal, and
  2499.  
  2500.  
  2501.  
  2502.                                  34
  2503.  
  2504.  
  2505.  
  2506.  
  2507.  
  2508.                       USING THE 65C02 ASSEMBLER 
  2509.  
  2510.  
  2511.  
  2512.                               %X(<expr>)
  2513.  
  2514. will display it in hexadecimal.
  2515.  
  2516.    You  can  write  any  numeric  expression  you  wish   within   the
  2517. parentheses, but it must not contain forward references.
  2518.  
  2519.    For example, to report the size of a section of code between labels
  2520. START.CODE and END.CODE, use:
  2521.  
  2522.  
  2523.         DISP2  'Size of code is %X(END.CODE-START.CODE) bytes'
  2524.  
  2525.  
  2526.  
  2527. 8.2 The WAIT, WAIT1 and WAIT2 directives
  2528.  
  2529.  
  2530.    These output messages in the same way as DISP, DISP1 and DISP2, but
  2531. then suspend the assembly until you press a key on the keyboard.
  2532.  
  2533.    You  could thus use these directives to enable you to change source
  2534. discs during an assembly.
  2535.  
  2536.  
  2537. 8.3 The QUERY directive
  2538.  
  2539.  
  2540.    This  offers  a  convenient  way  of  setting  up  conditions   for
  2541. conditional assembly.
  2542.  
  2543.    QUERY  operates  only  on  pass  1  of  the assembly. It displays a
  2544. message on the screen in the same way as the  directives  above,  then
  2545. waits  for  you  to  type  in a line. The line is treated as a numeric
  2546. expression and evaluated, the result being set as  the  value  of  the
  2547. symbol  specified  in  the  line's  label  field. If the expression is
  2548. invalid, or  contains  a  forward  reference,  the  question  will  be
  2549. repeated.
  2550.  
  2551.    For example, suppose that your source contains optional debug code,
  2552. and you select this with IF conditions of the form
  2553.  
  2554.                     IF    DEBUG.MODE
  2555.                        .
  2556.                        debug code
  2557.                        .
  2558.                     FI
  2559.                     
  2560.  
  2561.    The  value of DEBUG.MODE would normally be -1 to select debug code,
  2562. or 0 if it were not needed.
  2563.  
  2564.  
  2565.  
  2566.  
  2567.  
  2568.                                  35
  2569.  
  2570.  
  2571.  
  2572.  
  2573.  
  2574.                       USING THE 65C02 ASSEMBLER 
  2575.  
  2576.  
  2577.  
  2578.    Rather than define DEBUG.MODE in the source, and thus have to  edit
  2579. the  source  every  time  you  wished  to  change it, you can make the
  2580. Assembler ask for the value at the start of an assembly. A  line  such
  2581. as:
  2582.  
  2583.                  DEBUG.MODE  QUERY  'Use debug mode'
  2584.  
  2585. will output the question
  2586.  
  2587.                          ---- Use debug mode?
  2588.  
  2589. on pass 1. You can now type in
  2590.  
  2591.                                   -1
  2592.  
  2593. to select debug code, or
  2594.  
  2595.                                   0
  2596.  
  2597. to suppress it.
  2598.  
  2599.  
  2600.    Since  the line you type is an expression, and can contain symbols,
  2601. you can make this more friendly by changing the source to include
  2602.  
  2603.                     YES   EQU   -1
  2604.                     NO    EQU   0
  2605.                     
  2606. before the QUERY directive. Now you can reply either "YES" or "NO"  to
  2607. the  question: the Assembler will evaluate the line and take the value
  2608. of the symbol you type.
  2609.  
  2610.  
  2611.  
  2612. 8.4 The STOP directive
  2613.  
  2614.  
  2615.    STOP provides a useful  way  of  abandoning  an  assembly  part-way
  2616. through.  It  operates  on  pass 1, and like DISP1, it displays a text
  2617. message. Afterwards, though, it aborts the  assembly  with  the  error
  2618. message "Stopped"
  2619.  
  2620.  
  2621.  
  2622.  
  2623.  
  2624.  
  2625.  
  2626.  
  2627.  
  2628.  
  2629.  
  2630.  
  2631.  
  2632.  
  2633.  
  2634.                                  36
  2635.  
  2636.  
  2637.  
  2638.  
  2639.  
  2640.                       USING THE 65C02 ASSEMBLER 
  2641.  
  2642.  
  2643.  
  2644. 9. WRITING SIMPLE MACROS
  2645.  
  2646.  
  2647.    The  Assembler  contains a powerful macro facility, allowing you to
  2648. write very complex and sophisticated macros. In this chapter, we shall
  2649. examine the simpler aspects of macros.
  2650.  
  2651.    A macro is a way of producing a number of  Assembler  source  lines
  2652. merely  by  specifying  its  name  in  the opcode field of a line. For
  2653. example, your source might contain many occurences of the lines:
  2654.  
  2655.                        LDA   VAR
  2656.                        CLC
  2657.                        ADC   #2
  2658.                        STA   VAR
  2659.                        
  2660.    You could shorten the source, and make  it  easier  to  follow,  by
  2661. replacing  each  occurence  with  a  macro  call:  you  might set up a
  2662. suitable macro with the statements
  2663.  
  2664.                ADDTWO  MACRO
  2665.                        LDA   VAR
  2666.                        CLC
  2667.                        ADC   #2
  2668.                        STA   VAR
  2669.                        ENDM
  2670.                
  2671.                
  2672.    Then, instead of writing the four lines of code, simply  write  one
  2673. line
  2674.  
  2675.                        ADDTWO
  2676.  
  2677.    The   Assembler   will   expand  the  macro  definition,  and  will
  2678. automatically generate the four lines for you.
  2679.  
  2680.  
  2681. 9.1 Using macro parameters
  2682.  
  2683.  
  2684.    Although this is useful in itself, the  macro  as  shown  above  is
  2685. rather  limited.  It  couldn't,  for instance, be used to add 2 to the
  2686. variable COUNT instead of VAR.
  2687.  
  2688.    In order  to  provide  this  sort  of  flexibility,  you  can  pass
  2689. information  to  macros  as "parameters". You could re-write the macro
  2690. above to read
  2691.  
  2692.  
  2693.  
  2694.  
  2695.  
  2696.  
  2697.  
  2698.  
  2699.  
  2700.                                  37
  2701.  
  2702.  
  2703.  
  2704.  
  2705.  
  2706.                       USING THE 65C02 ASSEMBLER 
  2707.  
  2708.  
  2709.  
  2710.                ADDTWO  MACRO
  2711.                        LDA   @P1
  2712.                        CLC
  2713.                        ADC   #2
  2714.                        STA   @P1
  2715.                        ENDM
  2716.                
  2717.    Here we have replaced the occurrences of VAR by the  string  "@P1".
  2718. Now,  when  the  Assembler  expands  the  macro,  it  will replace all
  2719. occurrences of "@P1" with parameter number 1 of the macro call. To add
  2720. 1 to VAR, you would then write
  2721.  
  2722.                        ADDTWO  VAR
  2723.  
  2724. and to add 1 to COUNT, you would write
  2725.  
  2726.                        ADDTWO  COUNT
  2727.  
  2728.  
  2729.    You can supply up to 9 parameters when you call a macro,  and  they
  2730. are  indicated  in  the  body of the macro by @P1, @P2, @P3 and so on.
  2731. (Note that you can also specify the parameters as @1, @2,  @3  and  so
  2732. on, omitting the "P". This is adequate for existing code; however, for
  2733. new  programs you should use the "@P1" form, as this is necessary when
  2734. you come to use the Macro Programming Language)
  2735.  
  2736.  
  2737. 9.2 Specifying macro parameters
  2738.  
  2739.  
  2740.    You can specify anything you want as parameters to macros. A  macro
  2741. can have up to 9 parameters, separated by a comma and optional spaces.
  2742.  
  2743.    A macro with 3 parameters could be called with lines like
  2744.  
  2745.                        CHECK  1,FRED,27
  2746.                        CHECK  1 ,  FRED  , 27
  2747.  
  2748. and so on.
  2749.  
  2750.    Normally,  the  Assembler  will  remove leading and trailing spaces
  2751. from each parameter. If you require leading or trailing spaces, or  if
  2752. the parameter has to include a comma, you will need to specify it as a
  2753. string, delimited by single- or double-quote characters. Thus, a macro
  2754. call might look like
  2755.  
  2756.                        THING  'Here, is a comma'
  2757.  
  2758. and "@P1" will be replaced in the macro body with the characters
  2759.  
  2760.                            Here, is a comma
  2761.  
  2762.    Note  that  the  string  delimiters  are  not  taken as part of the
  2763. parameter proper.
  2764.  
  2765.  
  2766.                                  38
  2767.  
  2768.  
  2769.  
  2770.  
  2771.  
  2772.                       USING THE 65C02 ASSEMBLER 
  2773.  
  2774.  
  2775.  
  2776.  
  2777.  
  2778.  
  2779. 9.3 Nesting macros
  2780.  
  2781.    You can call macros from within macros, up to a depth of 5. If  you
  2782. attempt to nest deeper than that the Assembler will flag an error.
  2783.  
  2784.  
  2785.  
  2786. 9.4 Redefining opcodes and directives
  2787.  
  2788.    The Assembler allows you to set up macros to redefine any opcode or
  2789. directive.   For   example,   you  might  want  to  redefine  the  JSR
  2790. (Jump-to-Subroutine) opcode to automatically save the registers before
  2791. entering the subroutine. You could do this by declaring a macro called
  2792. JSR thus:
  2793.  
  2794.                     JSR   MACRO
  2795.                           PHA
  2796.                           TXA
  2797.                           PHA
  2798.                           TYA
  2799.                           PHA
  2800.                           JSR   @P1
  2801.                           ENDM
  2802.                     
  2803.    Now, whenever the Assembler comes across a line  with  JSR  in  the
  2804. opcode  field,  it  will  expand the macro JSR rather than obeying the
  2805. opcode. It will plant the code to save the registers,  and  then  will
  2806. come to the line
  2807.  
  2808.                           JSR  @P1
  2809.  
  2810. in the macro.
  2811.  
  2812.    Here,  because it is already in a macro, the Assembler will not use
  2813. the macro JSR. Instead it will assemble the opcode JSR,  planting  the
  2814. code to enter the subroutine.
  2815.  
  2816.  
  2817. 9.5 Labels within macros
  2818.  
  2819.  
  2820.    Suppose  you  wish  to write a macro that includes a branch of some
  2821. sort. You might write the macro definition as:
  2822.  
  2823.  
  2824.  
  2825.  
  2826.  
  2827.  
  2828.  
  2829.  
  2830.  
  2831.  
  2832.                                  39
  2833.  
  2834.  
  2835.  
  2836.  
  2837.  
  2838.                       USING THE 65C02 ASSEMBLER 
  2839.  
  2840.  
  2841.  
  2842.                     THING  MACRO
  2843.                            LDA    @P1
  2844.                            BEQ    ZERO
  2845.                            EOR    #$FF
  2846.                     ZERO   STA    @P2
  2847.                            ENDM
  2848.                     
  2849.    The first time the macro is called, it plants the code  bytes,  and
  2850. defines the label ZERO as the destination of the BEQ instruction. On a
  2851. subsequent  call,  though,  the  macro will produce the same code, and
  2852. will attempt to define the value of ZERO again. This  of  course  will
  2853. fail, since it already exists from the first macro call.
  2854.  
  2855.    The  Assembler  provides  a way round this problem, by giving you a
  2856. way of generating unique labels. Every time a  macro  is  called,  the
  2857. Assembler  sets  up what you can regard as a special parameter on your
  2858. behalf, which contains a string that  is  different  for  every  macro
  2859. call.  This  string  is  substituted,  in  the  same  way  as ordinary
  2860. parameters, by writing "@$MC" in the line.
  2861.  
  2862.    Thus, the above macro could be changed to be:
  2863.  
  2864.                     THING     MACRO
  2865.                               LDA    @P1
  2866.                               BEQ    ZERO@$MC
  2867.                               EOR    #$FF
  2868.                     ZERO@$MC  STA    @P1
  2869.                               ENDM
  2870.                     
  2871.    Then, on the first macro call, every occurrence of  ZERO@$MC  might
  2872. be  changed to ZERO1X1. On the next call, they become ZERO2X1, so that
  2873. there is no clash between the macros.
  2874.  
  2875.  
  2876.  
  2877.  
  2878.  
  2879.  
  2880.  
  2881.  
  2882.  
  2883.  
  2884.  
  2885.  
  2886.  
  2887.  
  2888.  
  2889.  
  2890.  
  2891.  
  2892.  
  2893.  
  2894.  
  2895.  
  2896.  
  2897.  
  2898.                                  40
  2899.  
  2900.  
  2901.  
  2902.  
  2903.  
  2904.                       USING THE 65C02 ASSEMBLER 
  2905.  
  2906.  
  2907.  
  2908. 10. THE MACRO PROGRAMMING LANGUAGE
  2909.  
  2910.  
  2911.  
  2912.    A very powerful feature of the Assembler is its  Macro  Programming
  2913. Language.  This  allows  you  considerable  control  in how macros are
  2914. expanded - you can construct loops, manipulate  macro  parameters  and
  2915. perform  several  other  functions  that  allow you to build macros of
  2916. great power.
  2917.  
  2918.    Although this facility is mostly intended for  use  within  macros,
  2919. many  of  its  facilities  can  also  be  used outside macros to great
  2920. effect, as this section will explain.
  2921.  
  2922.    The Macro Programming Languages's facilities build  on  two  source
  2923. language  features  known  as  Assembly  Time  Variables  and Sequence
  2924. Symbols.
  2925.  
  2926.  
  2927. 10.1 Sequence Symbols
  2928.  
  2929.  
  2930.    These are "place markers" within your source files or within macros
  2931. that the Macro Programming Language uses in  loops.  Using  directives
  2932. such as AGO and AIF, you can make the Assembler move up or down within
  2933. a  file  or a macro, letting you repeatedly assemble some parts of the
  2934. source or totally omit others.
  2935.  
  2936.    Sequence Symbols are very similar to the labels that  are  part  of
  2937. the  source  proper,  and  they  can  contain  the same characters. To
  2938. distinguish them, Sequence Symbols always begin within a "%"  sign  in
  2939. the  first  character  of  the line. The Sequence Symbol should be the
  2940. only thing on  the  line:  if  you do  put  anything  else  there  the
  2941. Assembler will ignore it.
  2942.  
  2943.    To  take  an example of how Sequence Symbols could be used, suppose
  2944. your source file contained the lines
  2945.  
  2946.  
  2947.                           AGO    %SKIP
  2948.                           ASC    'These lines will never '
  2949.                           ASC    'get assembled'
  2950.                     %SKIP
  2951.                           ASC    'But this one will'
  2952.                     
  2953.                     
  2954.    The Assembler will encounter  the  AGO  directive,  and  will  then
  2955. ignore  everything  in  the  source  file  until it finds the Sequence
  2956. Symbol %SKIP. It will then resume its normal processing.
  2957.  
  2958.    Although this example  will  actually  work,  the  technique  isn't
  2959. greatly  useful,  as  ignoring source lines can be done just as easily
  2960. with the IF..ELSE..FI construction.  However,  AGO  (and  the  various
  2961. conditional  skips such as AIF) also allows you to go backwards in the
  2962.  
  2963.  
  2964.                                  41
  2965.  
  2966.  
  2967.  
  2968.  
  2969.  
  2970.                       USING THE 65C02 ASSEMBLER 
  2971.  
  2972.  
  2973.  
  2974. source or macro - there is no other way of achieving this.
  2975.  
  2976.    The  Sequence  Symbols  used  in  any  file  or  macro  are   quite
  2977. independent of those in any other; thus you can safely use ones of the
  2978. same name in every file and macro, if you wish.
  2979.  
  2980.  
  2981. 10.2 Assembly Time Variables
  2982.  
  2983.  
  2984.    Assembly  Time  Variables,  or  ATVs, are string variables that the
  2985. Assembler itself uses while assembling your source files. As it  reads
  2986. the  program  source  (either  from a file or from the definition of a
  2987. macro) the Assembler continually looks for references to  ATVs.  These
  2988. are replaced - before the line is assembled - with the contents of the
  2989. ATV, thus allowing you to vary the source that is actually processed.
  2990.  
  2991.    You  can  use  ATVs  in many ways. For example, the first line of a
  2992. source might set an ATV string to  hold  the  version  number  of  the
  2993. program  you  are  assembling;  the  Assembler will then automatically
  2994. replace every reference to that name with the string.  Some  ATVs  are
  2995. created  by  the Assembler itself, and let you incorporate such things
  2996. as the name of the source file into the source itself.
  2997.  
  2998.    The main use, though, is in controlling  loops  within  macros  and
  2999. within source files.
  3000.  
  3001.  
  3002. 10.2.1 Creating Assembly Time Variables
  3003.  
  3004.  
  3005.    ATVs  have  names  similar  to  the variables that form part of the
  3006. source proper, and you can manipulate them with various directives.
  3007.  
  3008.  
  3009.      10.2.1.1 Local and Global ATVs
  3010.      
  3011.      There are two types of ATV: local and global ones. 
  3012.      
  3013.        a. Global ATVs exist for the whole of the assembly, and can  be
  3014.           used  anywhere.  They  are  created and manipulated with the
  3015.           ASTR, ASET, ASTRIP and ALEN directives, which  you  can  use
  3016.           even  inside  macros - the ATVs will continue to exist after
  3017.           the macro finishes.
  3018.           
  3019.        b. Local ATVs are created and manipulated by  the  MSTR,  MSET,
  3020.           MSTRIP  and  MLEN  directives. These can only be used inside
  3021.           macros, and the ATVs can be used only  within  the  macro  -
  3022.           they  cease  to exist at the end of the macro expansion. You
  3023.           would use these, for example, in controlling loops within  a
  3024.           macro.
  3025.           
  3026.           In  fact, you have already seen local ATVs in use in section
  3027.           6.1 on "Simple Macros". Whenever you  invoke  a  macro,  the
  3028.  
  3029.  
  3030.                                  42
  3031.  
  3032.  
  3033.  
  3034.  
  3035.  
  3036.                       USING THE 65C02 ASSEMBLER 
  3037.  
  3038.  
  3039.  
  3040.           Assembler  creates  local  ATVs with names P1, P2, P3 and so
  3041.           on, each holding one of the parameters you supplied  on  the
  3042.           macro call.
  3043.           
  3044.           For example, the source line
  3045.           
  3046.                          NAME  ASET  'OSWRCH'
  3047.           
  3048.           will  set  up  an  ATV  called  NAME, whose contents are the
  3049.           string 'OSWRCH'. Since the ASET directive has been used, the
  3050.           ATV is global, and can be used anywhere in the assembly.
  3051.           
  3052.           
  3053.           You can create local and global ATVs of the same name if you
  3054.           wish. However, if you wish to refer to the  local  ATV,  you
  3055.           should  be  careful  to always  use  the  "M"  form  of  the
  3056.           directives. The "A" forms will always  create  global  ATVs,
  3057.           even if local ones of the same name already exist.
  3058.           
  3059.           
  3060.      10.2.1.2 String and Numeric Values
  3061.      
  3062.      
  3063.      All  ATVs  are  stored  by  the  Assembler as printable character
  3064.      strings. However, in many cases you will find  you  use  them  as
  3065.      counters  for controlling loops: to make this easy, the Assembler
  3066.      will automatically convert ATVs from numbers to strings  whenever
  3067.      necessary.
  3068.      
  3069.      The  rule  used  is  quite  simple.  When processing ASET or MSET
  3070.      directives the Assembler examines  the  first  character  of  the
  3071.      operand  field. If it is a string delimiter, the operand is taken
  3072.      as a string. If it is any other character, the  Assembler  treats
  3073.      the  operand  as a numeric expression, evaluates it, and converts
  3074.      the result into a string for storage.
  3075.      
  3076.      Thus, the line
  3077.      
  3078.                          COUNT  ASET  15+3  
  3079.      
  3080.      will set up the ATV COUNT, containing the string "18", but
  3081.      
  3082.                          COUNT  ASET  '15+3'
  3083.      
  3084.      sets up the string "15+3".
  3085.      
  3086.      The operand can be any expression, provided it does  not  contain
  3087.      any forward references: thus
  3088.      
  3089.                        COUNT  ASET  ADDRESS+10
  3090.      
  3091.      sets  COUNT to hold the string form of the result of adding 10 to
  3092.      the address label ADDRESS.
  3093.      
  3094.  
  3095.  
  3096.                                  43
  3097.  
  3098.  
  3099.  
  3100.  
  3101.  
  3102.  
  3103.                       USING THE 65C02 ASSEMBLER 
  3104.  
  3105.  
  3106.  
  3107.      
  3108.      The ALEN and MLEN directives similarly  convert  from  number  to
  3109.      string for you. Here the operand must be a string: for example,
  3110.      
  3111.                      SIZE  ALEN  'A short string'
  3112.      
  3113.      sets  SIZE  to  hold  the string "14" - the length of the operand
  3114.      string, converted from a number into a string.
  3115.      
  3116.      
  3117.      10.2.1.3 String slicing
  3118.      
  3119.      The ASET and  MSET  directives  also  allow  to  you  to  "slice"
  3120.      strings, or extract characters from inside them. You perform this
  3121.      by adding some parameters in the operand field: for example
  3122.      
  3123.                     SLICE  ASET   'abcdefghij',3,2
  3124.      
  3125.      will  set  SLICE  to  hold  the  string  "cd". The second operand
  3126.      parameter specifies the position of the  first  character  to  be
  3127.      sliced  out  (the  string  starts  at character 1), and the third
  3128.      parameter specifies the number of characters to be sliced.
  3129.      
  3130.      Occasionally, string manipulations such as slicing may result  in
  3131.      strings  that have leading or trailing spaces, and you may not be
  3132.      able  to  tell  beforehand  how  many.  The  ASTRIP  and   MSTRIP
  3133.      directives remove all leading and trailing spaces, so that
  3134.      
  3135.                      NEW   ASTRIP   '  abcd    '
  3136.      
  3137.      would set the string NEW to be "abcd".
  3138.      
  3139.      
  3140.      10.2.1.4 Efficient use of memory
  3141.      
  3142.      The  strings  contained  by ATVs are held by the Assembler in the
  3143.      symbol table, and so compete for memory with other  symbols.  You
  3144.      can change the contents of an ATV to a string of different length
  3145.      as  often  as  you  wish:  however, every time the string becomes
  3146.      longer the Assembler will allocate a new block of memory for  it.
  3147.      The   previous   block  cannot  be  used  again,  so  continually
  3148.      increasing the size of  an  ATV  can  be  extremely  wasteful  of
  3149.      memory.
  3150.      
  3151.      To   overcome   this,  the  ASTR  and  MSTR  directives  let  you
  3152.      pre-declare a block of memory big enough to hold the maximum size
  3153.      string you will use. For example,
  3154.      
  3155.                             NAME  ASTR  50
  3156.      
  3157.      sets up a block long enough to hold a 50-byte string without  the
  3158.      need to get more memory.
  3159.      
  3160.      The minimum  amount  of  memory  the Assembler will allocate is 5
  3161.  
  3162.  
  3163.                                  44
  3164.  
  3165.  
  3166.  
  3167.  
  3168.  
  3169.                       USING THE 65C02 ASSEMBLER 
  3170.  
  3171.  
  3172.  
  3173.      bytes: this is enough to hold the largest possible numeric value,
  3174.      so that loop counters will not  cause  memory  wastage  as  their
  3175.      values grow - you need not use ASTR and MSTR for them.
  3176.      
  3177.      
  3178. 10.2.2 Simple Substitution of Assembly Time Variables
  3179.  
  3180.  
  3181.    Once  you  have  set  up  ATVs, you can use them to create variable
  3182. source lines. We have already come across this concept in section  6.1
  3183. on "Simple Macros", in the discussion of macro parameter substitution.
  3184. There, we saw that if the source of the macro contained the line
  3185.  
  3186.  
  3187.                               LDA  #@P1
  3188.  
  3189.  
  3190. the  Assembler  would replace "@P1" with whatever you had specified as
  3191. the first parameter of the macro when you called it.
  3192.  
  3193.    ATVs are substituted into source lines in exactly the same way, and
  3194. as we saw, macro parameters are in fact local ATVs.
  3195.  
  3196.    The rule the Assembler uses is quite simple: whenever it detects an
  3197. "@" sign in the source (other than in a comment line)  it  expects  an
  3198. ATV  name  to  follow. The "@" and the name itself are replaced by the
  3199. contents of the ATV before the line is assembled.
  3200.  
  3201.    For example, suppose you set an ATV with the statement
  3202.  
  3203.                          NAME  ASET  'OSWRCH'
  3204.  
  3205.  
  3206. The Assembler will then replace "@NAME"  anywhere  in  the  source  by
  3207. "OSWRCH". You might then have a line that in the source read
  3208.  
  3209.  
  3210.                               JSR  @NAME
  3211.  
  3212.  
  3213. This would be changed by the Assembler into
  3214.  
  3215.  
  3216.                              JSR  OSWRCH
  3217.  
  3218. before assembly, and you will see this second line in the listing.
  3219.  
  3220.  
  3221.    There  are some more complex uses of ATV substitution, and we shall
  3222. discuss these later in section 7.3 on "Writing Complex Macros".
  3223.  
  3224.  
  3225.    Some useful points to note on substition are:
  3226.  
  3227.  
  3228.  
  3229.                                  45
  3230.  
  3231.  
  3232.  
  3233.  
  3234.  
  3235.                       USING THE 65C02 ASSEMBLER 
  3236.  
  3237.  
  3238.  
  3239.   a. If you want the "@" character to appear in the line the Assembler
  3240.      processes, your source must contain two of  them.  Thus,  if  the
  3241.      line you really want to assemble is
  3242.      
  3243.                           ASC  'VAT @ 15%' 
  3244.      
  3245.      write it in the source file  as
  3246.      
  3247.                           ASC  'VAT @@ 15%'
  3248.      
  3249.      
  3250.   b. Once  the  Assembler  finds  an  "@"  character in the source, it
  3251.      assumes that what follows is an ATV name. The end of this name is
  3252.      assumed to be the first non-alphanumeric character that it meets,
  3253.      or the end of the line. In almost all cases, this will  cause  no
  3254.      difficulty, but occasionally will, usually in complex macros.
  3255.      
  3256.      As  an  example,  suppose  you  had  declared at ATV called EXPR,
  3257.      holding the string "10+". A subsequent  source  line  might  then
  3258.      read
  3259.      
  3260.                              LDA  #@EXPR3
  3261.      
  3262.      and the intention is for this to be transformed into
  3263.      
  3264.                               LDA  #10+3
  3265.      
  3266.      In  this  case,  though,  the  substitution  will  fail,  as  the
  3267.      Assembler will look for an ATV called EXPR3. To force it to do as
  3268.      you want, write the source line as
  3269.      
  3270.                             LDA  #@EXPR/3
  3271.      
  3272.      The "/" character enables the Assembler to detect the end of  the
  3273.      ATV  name, so it will look for EXPR as it should. The "/" will be
  3274.      discarded, so that the resulting line will be
  3275.      
  3276.                               LDA  #10+3
  3277.      
  3278.      as intended. If you need a "/" character in the  resulting  line,
  3279.      write it as "//".
  3280.      
  3281.      There   are   two   other  techniques  you  might  use  in  these
  3282.      circumstances.  The  Assembler  does   not   regard   spaces   as
  3283.      significant in numeric expressions, so that you could write
  3284.      
  3285.                            LDA  #@EXPR / 3
  3286.      
  3287.      to  achieve  the  same  result. Also, you could adopt a technique
  3288.      normally  used  in  more  complex  cases  (described  in  section
  3289.      10.1.3.2) and write the line as
  3290.      
  3291.                            LDA  #@(EXPR)/3
  3292.      
  3293.  
  3294.  
  3295.                                  46
  3296.  
  3297.  
  3298.  
  3299.  
  3300.  
  3301.                       USING THE 65C02 ASSEMBLER 
  3302.  
  3303.  
  3304.  
  3305.      
  3306.   c. No  ATV  substitution  is  performed  in  comment lines, in lines
  3307.      containing Sequence Symbols, or in the definition of macros (i.e.
  3308.      between the MACRO and ENDM directives). Apart from these, though,
  3309.      substitutions can be made at any  place  in  a  line  -  you  can
  3310.      substitute for labels, opcodes, operands or any parts of them.
  3311.  
  3312.  
  3313.  
  3314. 10.3 Writing Complex Macros
  3315.  
  3316.  
  3317. 10.3.1 Programming macro loops
  3318.  
  3319.    Mostly,  you  will  use  the  Macro Programming Language to program
  3320. macro loops, controlled by various conditions.
  3321.  
  3322.      10.3.1.1 Simple loops controlled by counter
  3323.      
  3324.      
  3325.      The simplest form of loop is one which is executed a fixed number
  3326.      of times, and needs only a counter to control it.
  3327.      
  3328.      As an example, suppose that we need a macro to plant a number  of
  3329.      bytes  containing  $FF  with  the DFB directive, the number being
  3330.      specified by the first parameter. (There are much easier ways  of
  3331.      doing  this  than  with  a  macro,  of course - this only shows a
  3332.      general technique).
  3333.      
  3334.      The macro definition might then be:
  3335.      
  3336.                     PLANT  MACRO
  3337.                     COUNT  MSET    0
  3338.                     %LOOP
  3339.                            DFB     $FF
  3340.                     COUNT  MSET    @COUNT+1
  3341.                            AIF     @COUNT<@P1,%LOOP
  3342.                            ENDM
  3343.                     
  3344.      To see how this works, we can examine each line in turn, assuming
  3345.      that the macro was called with a line
  3346.      
  3347.                                PLANT  7
  3348.      
  3349.      
  3350.      Line 1 : This is the macro definition line.
  3351.               
  3352.      Line 2 : This line sets up a local ATV called COUNT, and gives it
  3353.               a string value of "0".
  3354.               
  3355.      Line 3 : This is a Sequence Symbol marking the top of  the  loop.
  3356.               Note that there is nothing else on the line with it.
  3357.               
  3358.      Line 4 : This is the DFB line that plants the $FF byte required.
  3359.  
  3360.  
  3361.                                  47
  3362.  
  3363.  
  3364.  
  3365.  
  3366.  
  3367.                       USING THE 65C02 ASSEMBLER 
  3368.  
  3369.  
  3370.  
  3371.               
  3372.      Line 5 : This   line  increments  the  value  of  COUNT.  As  the
  3373.               Assembler reads the line, it encounters "@COUNT",  which
  3374.               it  replaces  with  the current string value of the ATV.
  3375.               Thus the  first  time  this  line  is  encountered,  the
  3376.               Assembler will generate
  3377.               
  3378.                            COUNT  MSET  0+1
  3379.               
  3380.               The second time, it generates
  3381.               
  3382.                            COUNT  MSET  1+1
  3383.               
  3384.               and so on.
  3385.               
  3386.      Line 5 : This  tests  whether the Assembler is to loop round once
  3387.               more.  As  with  line  4,  the  Assembler  will  replace
  3388.               "@COUNT" with the current value of the ATV. "@P1" is, of
  3389.               course,  replaced  by  the first parameter of the macro.
  3390.               The first time round, the line processed is
  3391.               
  3392.                            AIF   0<7,%LOOP
  3393.               
  3394.               which is true, so the Assembler skips backwards  in  the
  3395.               macro to line 4 and resumes processing from there.
  3396.               
  3397.               
  3398.               
  3399.      
  3400.      10.3.1.2 Loops accessing macro parameters
  3401.      
  3402.      
  3403.      Another  frequently-needed  form  of loop is one in which all the
  3404.      parameters of the  macro  are  accessed  in  turn.  Suppose,  for
  3405.      example,  you  need to write a macro THINGS, whose parameters are
  3406.      all numbers. Each number is to be planted in a byte in the object
  3407.      file with a DFB directive: to make THINGS interesting, the number
  3408.      of parameters must be variable.
  3409.      
  3410.      Such a  macro  is  fairly  simple  to  write,  but  uses  an  ATV
  3411.      substitution  technique  that  can,  at  first sight, be somewhat
  3412.      daunting. If the job were simply to plant the value of  parameter
  3413.      1, the line in the macro that does it would simply be
  3414.      
  3415.                               DFB   @P1
  3416.      
  3417.      However,  we need to access each parameter in turn: the Assembler
  3418.      must somehow be made to see "@P1" the first time round the  loop,
  3419.      "@P2"  in  the  second,  and  so on. Effectively, then, we need a
  3420.      substitution technique that lets us  have  a variable  ATV  name:
  3421.      i.e.  one  that first  substitutes the number ("1", "2", "3" etc)
  3422.      then substitutes for the ATV name so formed.
  3423.      
  3424.      The Assembler can do this easily, since ATV substitution operates
  3425.  
  3426.  
  3427.                                  48
  3428.  
  3429.  
  3430.  
  3431.  
  3432.  
  3433.                       USING THE 65C02 ASSEMBLER 
  3434.  
  3435.  
  3436.  
  3437.      in a hierarchic fashion. For example, suppose that a source  line
  3438.      contains
  3439.      
  3440.                               @(P@COUNT)
  3441.      
  3442.      somewhere.
  3443.      
  3444.      On  seeing  the  first  "@"  character, the Assembler prepares to
  3445.      substitute an ATV. It finds, though, that the next character is a
  3446.      "(", so that it now expects a bracketed expression rather than an
  3447.      ATV name. It notes where it has got to in the  source  line,  and
  3448.      explores within the brackets.
  3449.      
  3450.      Now,  though,  it  stores  the  characters  it finds (rather than
  3451.      passing them on to be assembled), and expects to end  up  with  a
  3452.      valid ATV name by the time it gets to the ")" character. It notes
  3453.      the  "P",  then  finds the second "@". This makes it try again to
  3454.      substitute an ATV, and this time  it  finds  a  real  ATV  called
  3455.      COUNT,  which  we  shall  suppose  contains the string "1". After
  3456.      "COUNT" it finds the ")" ending the bracketed  expression;  thus,
  3457.      within the brackets the string it has built is now "P1".
  3458.      
  3459.      Having ended the bracketed expression, the Assembler goes back to
  3460.      where  it  was.The  "(P@COUNT)" has provided the string "P1", and
  3461.      this now is a valid ATV name. So it proceeds  to  substitute  the
  3462.      value of ATV P1, the first macro parameter, as we intended.
  3463.      
  3464.      
  3465.      To  see  how  we  might  use  this  technique,  we can consider a
  3466.      definition of THINGS:
  3467.      
  3468.      
  3469.                     THINGS  MACRO
  3470.                     COUNT  MSET    1
  3471.                     %LOOP
  3472.                            AIF     '@(P@COUNT)'='',%ALL.DONE
  3473.                            DFB     @(P@COUNT)
  3474.                     COUNT  MSET    @COUNT+1
  3475.                            AIF     @COUNT<10,%LOOP
  3476.                     %ALL.DONE
  3477.                            ENDM
  3478.                     
  3479.      To see how this works, we can examine each line in turn.
  3480.      
  3481.      Line 1 : This is the macro definition line.
  3482.               
  3483.      Line 2 : This line sets up a local ATV called COUNT, and gives it
  3484.               a string value of "1".
  3485.               
  3486.      Line 3 : This is a Sequence Symbol marking the top of the loop.
  3487.               
  3488.      Line 4 : Since the number of paameters must be variable, we  need
  3489.               to  test  whether  we've processed them all. You can see
  3490.               the substitution technique discussed above in  use  here
  3491.  
  3492.  
  3493.                                  49
  3494.  
  3495.  
  3496.  
  3497.  
  3498.  
  3499.                       USING THE 65C02 ASSEMBLER 
  3500.  
  3501.  
  3502.  
  3503.               to  check if the next parameter is null - any parameters
  3504.               that you don't supply in a macro  call  are  strings  of
  3505.               zero size. If the parameter is null, the Assembler skips
  3506.               forwards  in  the  macro  until  it gets to the Sequence
  3507.               Symbol %ALL.DONE.
  3508.               
  3509.      Line 5 : This is the DFB  line  that  plants  the  current  macro
  3510.               parameter as a byte.
  3511.               
  3512.      Line 6 : This  line  increments  the  value  of  COUNT, as in the
  3513.               previous example.
  3514.               
  3515.      Line 7 : This tests whether the Assembler is to loop  round  once
  3516.               more.  The  final  macro  parameter is P9, so once COUNT
  3517.               reaches 10 the macro is finished.
  3518.               
  3519.      Line 8 : This is the Sequence Symbol that line 4 skips to  if  it
  3520.               finds a null parameter.
  3521.               
  3522.      Thus, if the macro was called with a line
  3523.      
  3524.                          THINGS  1,$FE,FRED-1
  3525.      
  3526.      the  loop  would be traversed three times, and the lines actually
  3527.      assembled would be
  3528.      
  3529.                            DFB     1
  3530.                            DFB     $FE
  3531.                            DFB     FRED-1
  3532.                     
  3533.                     
  3534.                     
  3535.      The technique of hierarchical  substitution,  though  most  often
  3536.      used  to  access  macro  parameters  in turn, can be used in many
  3537.      other applications: you can nest substitutions to as deep as  you
  3538.      are  likely  to  need,  so  that  you  might  write  something as
  3539.      horrendous looking as
  3540.      
  3541.                       LDA   #@(XX@(COUNT@PTR)B)
  3542.      
  3543.      if you really needed to.
  3544.      
  3545.      
  3546.      
  3547. 10.3.2 Changing macro parameters
  3548.  
  3549.  
  3550.    Macro parameters are in fact local ATVs with names P1, P2,  P3  and
  3551. so on. This means that you can change them within a macro as you wish.
  3552.  
  3553.    One  example  of  this  might  be to allow the use of default macro
  3554. parameters (although section 10.3.3 below shows a n automatic  way  to
  3555. do  this).  Suppose  that  a macro parameter should be a number, whose
  3556. default value is 1. You could define it as:
  3557.  
  3558.  
  3559.                                  50
  3560.  
  3561.  
  3562.  
  3563.  
  3564.  
  3565.                       USING THE 65C02 ASSEMBLER 
  3566.  
  3567.  
  3568.  
  3569.  
  3570.  
  3571.                     TEST  MACRO
  3572.                           AIF    '@P1'#'',%NEXT
  3573.                     P1    MSET   1
  3574.                     %NEXT
  3575.                           LDA    #@P1
  3576.                           ENDM
  3577.                     
  3578. Within this example, we have:
  3579.  
  3580. Line 1 : The macro definition line.
  3581.          
  3582. Line 2 : This tests if parameter 1 has been supplied. If so,  it  will
  3583.          not be a null string, so the Assembler skips to %NEXT.
  3584.          
  3585. Line 3 : This line sets parameter 1 to the default value.
  3586.          
  3587. Line 4 : This  is  the  Sequence Symbol skipped to if the parameter is
  3588.          not defaulted.
  3589.          
  3590. Line 5 : This line actually  uses  the  parameter.  It  will  assemble
  3591.          correctly  even if the parameter was not given, since in that
  3592.          case line 3 will have set it up to be the default value.
  3593.          
  3594.          
  3595. 10.3.3 Setting default macro parameters
  3596.  
  3597.  
  3598.    The example above showed one way of establishing a default value of
  3599. a macro parameter, but in fact the Assembler gives  you  an  automatic
  3600. and easy way of doing this with the DEFPARS directive.
  3601.  
  3602.    The  effect  of  this  directive,  which  you can issue at any time
  3603. inside a macro, is to set the values of any of  the  macro  parameters
  3604. P1, P2, P3 and so on, unless they are already defined.
  3605.  
  3606.    For example, you might call a macro with a line
  3607.  
  3608.                              FRED    1,,3
  3609.  
  3610. where you have defined parameters 1 and 3, but not parameter 2. If the
  3611. macro now excutes, say,
  3612.  
  3613.                          DEFPARS  100,200,300
  3614.  
  3615. the  Assembler  will  check the parameters in turn. Parameters 1 and 3
  3616. are already defined, so the "100"  and  "300"  values  are  not  used.
  3617. Parameter  2,  though,  is not yet defined, so it is set to "200" from
  3618. this point on.
  3619.  
  3620.    If you wished, say, to establish a default  for  only some  of  the
  3621. parameters  of  a  macro,  simply specify only thses parameters in the
  3622. DEFPARS directive and default the others. Thus
  3623.  
  3624.  
  3625.                                  51
  3626.  
  3627.  
  3628.  
  3629.  
  3630.  
  3631.                       USING THE 65C02 ASSEMBLER 
  3632.  
  3633.  
  3634.  
  3635.  
  3636.                             DEFPARS ,,,44
  3637.  
  3638. sets a default for parameter  4,  but  has  no  effect  whatsoever  on
  3639. parameters 1, 2, 3, 5, 6, 7, 8 and 10.
  3640.  
  3641.  
  3642.  
  3643. 10.3.4 Listing control for macros
  3644.  
  3645.  
  3646.    If  you write complex macros with lots of loops, you will find that
  3647. the Assembler actually executes a large  number  of  lines  that  just
  3648. contain the AIF, MSET directives, etc. This can swamp the listing, and
  3649. make  it hard to see the actual directives that plant data or code (as
  3650. well as using up a large amount of paper).
  3651.  
  3652.    To overcome this, list level 2 will not  list  directives  such  as
  3653. MSET,  AIF,  etc,  unless they contain errors. In order to see all the
  3654. lines of a macro expansion, use  list  level  3.  (Note  that  outside
  3655. macros, ASET and other similar directives will list at level 2).
  3656.  
  3657.  
  3658. 10.3.5 Exiting a macro prematurely
  3659.  
  3660.  
  3661.    You  may  sometimes  need  to  exit  a macro as a result of a test.
  3662. Depending on circumstances, you may be able to use AIF or AGO to  skip
  3663. to  the physical end of the macro; however, you can also use the MEXIT
  3664. directive. This exits the macro immediately,  wherever  in  the  macro
  3665. body it is encountered.
  3666.  
  3667.  
  3668.  
  3669.  
  3670.  
  3671.  
  3672.  
  3673.  
  3674.  
  3675.  
  3676.  
  3677.  
  3678.  
  3679.  
  3680.  
  3681.  
  3682.  
  3683.  
  3684.  
  3685.  
  3686.  
  3687.  
  3688.  
  3689.  
  3690.  
  3691.                                  52
  3692.  
  3693.  
  3694.  
  3695.  
  3696.  
  3697.                       USING THE 65C02 ASSEMBLER 
  3698.  
  3699.  
  3700.  
  3701. 10.4 System ATVs
  3702.  
  3703.  
  3704.    The  Assembler  provides  a  number  of read-only ATVs that you can
  3705. substitute.  They  provide  information  on  the  Assembler  and   the
  3706. environment that you can use to control assembly. Each system ATV name
  3707. starts with a "$" character: they are
  3708.  
  3709.  
  3710.                
  3711.       $CLST    The current code listing level.
  3712.                
  3713.       $DEFCLST The default code listing level.
  3714.                
  3715.       $DEFLST  The default listing level.
  3716.                
  3717.       $FLEVEL  "1"  if  the current file is an INCLUDE file; "0" if it
  3718.                is not.
  3719.                
  3720.       $FS      The number of the filing system in use, as returned  by
  3721.                OSARGS with A=0, Y=0. The Acorn DFS returns "4", Econet
  3722.                returns "5" and ADFS returns "8".
  3723.                
  3724.       $LINE    The number of the current source line.
  3725.                
  3726.       $LST     The current listing level.
  3727.                
  3728.       $MC      The  macro call counter, used to generate unique labels
  3729.                within macros (see section 9.5)
  3730.                
  3731.       $MLEVEL  The current macro nesting level. If not in a macro, the
  3732.                value is "0".
  3733.                
  3734.       $OBJECT  The name of the current object file, which may  include
  3735.                leading or trailing spaces.
  3736.                
  3737.       $OS      The  version  of  the MOS in use, as returned by OSBYTE
  3738.                with A=0.
  3739.                
  3740.       $OSHWM   The primary OSHWM value  of  the  machine  running  the
  3741.                Assembler.
  3742.                
  3743.       $SOURCE  The  name of the current source file, which may include
  3744.                leading or trailing spaces.
  3745.                
  3746.       $TIME    The currently-set timestamp string, which  may  include
  3747.                leading or trailing spaces.
  3748.                
  3749.       $TTL     The  currently-set page title string, which may include
  3750.                leading or trailing spaces.
  3751.                
  3752.       $VERSION The version of the Assembler in use. This  is  returned
  3753.                as  a  numeric  string,  so  that version 1.50 sets the
  3754.                string to be "150".
  3755.  
  3756.  
  3757.                                  53
  3758.  
  3759.  
  3760.  
  3761.  
  3762.  
  3763.                       USING THE 65C02 ASSEMBLER 
  3764.  
  3765.  
  3766.  
  3767.                
  3768.                
  3769.    For example, the line
  3770.  
  3771.                              ORG  @$OSHWM
  3772.  
  3773. could be used to set the base address of the code to the  OSHWM  value
  3774. of  the  machine  being used, without the need to know what that value
  3775. was.
  3776.  
  3777.  
  3778.  
  3779.  
  3780.  
  3781.  
  3782.  
  3783.  
  3784.  
  3785.  
  3786.  
  3787.  
  3788.  
  3789.  
  3790.  
  3791.  
  3792.  
  3793.  
  3794.  
  3795.  
  3796.  
  3797.  
  3798.  
  3799.  
  3800.  
  3801.  
  3802.  
  3803.  
  3804.  
  3805.  
  3806.  
  3807.  
  3808.  
  3809.  
  3810.  
  3811.  
  3812.  
  3813.  
  3814.  
  3815.  
  3816.  
  3817.  
  3818.  
  3819.  
  3820.  
  3821.  
  3822.  
  3823.                                  54
  3824.  
  3825.  
  3826.  
  3827.  
  3828.  
  3829.                            USING THE 65C02 ASSEMBLER 
  3830.  
  3831.  
  3832.  
  3833.      Appendix 1 : OPCODES AND ADDRESSING MODES
  3834.      
  3835.      
  3836.         The Assembler supports all  the  opcodes  of  the  6502  and  65C02
  3837.      processor  families, using standard MOSTEK mnemonics. For descriptions
  3838.      of the opcodes, see for example "The Advanced User Guide for  the  BBC
  3839.      Micro"  (for 6502-compatible opcodes) and the "Master Reference Manual
  3840.      Part  2"  (both  6502-  and  65C02-compatible  opcodes,  although   it
  3841.      describes  the  BBC  BASIC  Assembler syntax which cannot be used with
  3842.      this Assembler.)
  3843.      
  3844.         The 6502-compatible opcode mnemonics available are:
  3845.       
  3846.       ADC  AND  ASL  BCC  BCS  BEQ  BIT  BMI  BNE  BPL  BRK  BVC  BVS  CLC
  3847.       CLD  CLI  CLV  CMP  CPX  CPY  DEC  DEX  DEY  EOR  INC  INX  INY  JMP
  3848.       JSR  LDA  LDX  LDY  LSR  NOP  ORA  PHA  PHP  PLA  PLP  ROL  ROR  RTI
  3849.       RTS  SBC  SEC  SED  SEI  STA  STX  STY  TAX  TAY  TSX  TXS  TYA
  3850.       
  3851.         The 65C02-only mnemonics are:
  3852.      
  3853.       BRA  DEA  INA  PHX  PHY  PLX  PLY  STZ  TRB  TSB
  3854.       
  3855.         The opcode CLR can be used as a synonym for STZ.
  3856.       
  3857.         The addressing modes common to both the 6502 and  65C02  processors
  3858.      are:
  3859.      
  3860.                   Mode                            Syntax
  3861.                
  3862.                Implied                            op
  3863.                Accumulator                        op A  or  op
  3864.                Immediate                          op #expr8
  3865.                  Low byte                         op #>expr
  3866.                  High byte                        op #<expr
  3867.                Zero page                          op expr8
  3868.                  Indexed by X                     op expr8,X
  3869.                  Indexed by Y                     op expr8,Y
  3870.                Absolute                           op expr16
  3871.                  Indexed by X                     op expr16,X
  3872.                  Indexed by Y                     op expr16,Y
  3873.                Indirect pre-indexed               op (expr8,X)
  3874.                Indirect post-indexed              op (expr8),Y
  3875.                Absolute indirect                  op (expr)
  3876.                
  3877.                
  3878.         The addressing modes usable with the 65C02 processor only are:
  3879.      
  3880.                   Mode                            Syntax
  3881.                
  3882.                Zero-page indexed                  op (expr8)
  3883.                Absolute indirect pre-indexed      op (expr16,X)
  3884.                
  3885.                
  3886.         In  these definitions, "expr8" represents an 8 bit number; "expr16"
  3887.  
  3888.  
  3889.                                       55
  3890.  
  3891.  
  3892.  
  3893.  
  3894.  
  3895.                            USING THE 65C02 ASSEMBLER 
  3896.  
  3897.  
  3898.  
  3899.      a 16-bit number; and "expr" a value that is either 8 or 16 bits long.
  3900.      
  3901.  
  3902.  
  3903.  
  3904.  
  3905.  
  3906.  
  3907.  
  3908.  
  3909.  
  3910.  
  3911.  
  3912.  
  3913.  
  3914.  
  3915.  
  3916.  
  3917.  
  3918.  
  3919.  
  3920.  
  3921.  
  3922.  
  3923.  
  3924.  
  3925.  
  3926.  
  3927.  
  3928.  
  3929.  
  3930.  
  3931.  
  3932.  
  3933.  
  3934.  
  3935.  
  3936.  
  3937.  
  3938.  
  3939.  
  3940.  
  3941.  
  3942.  
  3943.  
  3944.  
  3945.  
  3946.  
  3947.  
  3948.  
  3949.  
  3950.  
  3951.  
  3952.  
  3953.  
  3954.  
  3955.                                       56
  3956.  
  3957.  
  3958.  
  3959.  
  3960.  
  3961.                            USING THE 65C02 ASSEMBLER 
  3962.  
  3963.  
  3964.  
  3965.      Appendix 2: ASSEMBLER DIRECTIVES
  3966.      
  3967.      
  3968.         The Assembler supports a large number of directives, or pseudo-ops.
  3969.      This  section  gives  a  detailed  definition  of  each,  arranged  in
  3970.      alphabetical order.
  3971.      
  3972.         Directives follow the normal syntax of opcodes. All can be followed
  3973.      by  comment  fields  started  with  a  ";" character; however, not all
  3974.      directives may have labels.
  3975.      
  3976.         In the specification, items enclosed in "[]" brackets are optional,
  3977.      and can be omitted.
  3978.      
  3979.  
  3980.  
  3981.  
  3982.  
  3983.  
  3984.  
  3985.  
  3986.  
  3987.  
  3988.  
  3989.  
  3990.  
  3991.  
  3992.  
  3993.  
  3994.  
  3995.  
  3996.  
  3997.  
  3998.  
  3999.  
  4000.  
  4001.  
  4002.  
  4003.  
  4004.  
  4005.  
  4006.  
  4007.  
  4008.  
  4009.  
  4010.  
  4011.  
  4012.  
  4013.  
  4014.  
  4015.  
  4016.  
  4017.  
  4018.  
  4019.  
  4020.  
  4021.                                       57
  4022.  
  4023.  
  4024.  
  4025.  
  4026.  
  4027.                            USING THE 65C02 ASSEMBLER 
  4028.  
  4029.  
  4030.  
  4031.      AGO     Skips to a Sequence Symbol.
  4032.              
  4033.              Syntax:
  4034.              
  4035.                                 AGO  <sequence>
  4036.              
  4037.              Example:
  4038.              
  4039.                                    AGO  %LOOP
  4040.              
  4041.              
  4042.      AIF     Skips to a Sequence Symbol if a condition is true.
  4043.              
  4044.              Syntax:
  4045.              
  4046.                           AIF  <expr>,<sequence>      
  4047.                 or
  4048.                           AIF  <stringexpr>,<sequence>
  4049.              
  4050.              If <condition> is false assembly continues in the next line.
  4051.              
  4052.              Example:
  4053.              
  4054.                            AIF  'FREDA'>'FRED',%LOOP
  4055.              
  4056.              
  4057.      AIFDEF  Skips to a Sequence Symbol if a symbol has been defined.
  4058.              
  4059.              Syntax:
  4060.              
  4061.                           AIFDEF  <symbol>,<sequence>
  4062.              
  4063.              Example:
  4064.              
  4065.                           AIFDEF  RAM.CODE,%DOING.RAM
  4066.              
  4067.              
  4068.      AIFNDEF Skips to a Sequence Symbol if a symbol has not  been  defined.
  4069.              The syntax is as for AIFDEF.
  4070.              
  4071.              
  4072.      ALEN    Sets a global ATV to the length of the operand string.
  4073.              
  4074.              Syntax:
  4075.              
  4076.                             <label>  ALEN  <string>
  4077.              
  4078.              Example:
  4079.              
  4080.                          SIZE  ALEN  'This is a string'
  4081.              
  4082.              
  4083.              
  4084.  
  4085.  
  4086.  
  4087.                                       58
  4088.  
  4089.  
  4090.  
  4091.  
  4092.  
  4093.  
  4094.                            USING THE 65C02 ASSEMBLER 
  4095.  
  4096.  
  4097.  
  4098.      ASC     Defines an ASCII string.
  4099.              
  4100.              Syntax:
  4101.              
  4102.                             [<label>]  ASC  <string>
  4103.              
  4104.              Within <string> you can use the techniques of section 4.3.3 to
  4105.              plant  control  characters  or characters with bit 7 set. If a
  4106.              label is specified, it is set to the address of the first byte
  4107.              of the string.
  4108.              
  4109.              Example:
  4110.              
  4111.                           TITLE  ASC  'Assembler 1.32'
  4112.              
  4113.              
  4114.      ASET    Sets a global ATV to contain a string.
  4115.              
  4116.              Syntax:
  4117.              
  4118.                   <label>  ASET  <string>[,<expr1>[,<expr2>]]
  4119.                 or
  4120.                   <label>  ASET  <expr>                      
  4121.              
  4122.              The final two parameters in the operand field allow the string
  4123.              parameter to be sliced. Both are  expressions  that  must  not
  4124.              involve  forward  references. <expr1> specifies the first byte
  4125.              to be sliced from the string (the first byte in the string  is
  4126.              byte  1).  <expr2>  defines the size of the slice; if omitted,
  4127.              one byte is extracted.
  4128.              
  4129.              Example:
  4130.              
  4131.                                 COUNT  ASET  100
  4132.              
  4133.              
  4134.      ASTR    Allocates space for a global ATV.
  4135.              
  4136.              Syntax:
  4137.              
  4138.                              <label>  ASTR  <expr>
  4139.              
  4140.              <expr>, which must not contain forward references, defines the
  4141.              space needed. The value can be up to 255 bytes.
  4142.              
  4143.              Example:
  4144.              
  4145.                                 NAME  ASTR  150
  4146.              
  4147.              
  4148.      ASTRIP  Sets a global ATV to a  string  value,  removing  leading  and
  4149.              trailing spaces in the process.
  4150.              
  4151.              
  4152.  
  4153.  
  4154.                                       59
  4155.  
  4156.  
  4157.  
  4158.  
  4159.  
  4160.                            USING THE 65C02 ASSEMBLER 
  4161.  
  4162.  
  4163.  
  4164.              Syntax:
  4165.              
  4166.                            <label>  ASTRIP  <string>
  4167.              
  4168.              Example:
  4169.              
  4170.                         MIDDLE  ASTRIP  '   aardvark   '
  4171.              
  4172.              
  4173.      CASC    This  is  similar  in  action  to  ASC,  but will plant a byte
  4174.              containing the number of characters within the  string  before
  4175.              the string itself.
  4176.              
  4177.              
  4178.              
  4179.      CHN     Closes the current source file and starts another.
  4180.              
  4181.              Syntax:
  4182.              
  4183.                            [<label>]  CHN  <filename>
  4184.              
  4185.              The directive is not allowed in an INCLUDE file.
  4186.              
  4187.              Example:
  4188.              
  4189.                                 CHN  :2.NEXTBIT
  4190.              
  4191.              
  4192.      CHR     Defines the character used by the REP directive.
  4193.              
  4194.              Syntax:
  4195.              
  4196.                            [<label>]  CHR  character
  4197.              
  4198.              The  character  is specified literally, and not as a character
  4199.              constant.
  4200.              
  4201.              Example:
  4202.              
  4203.                                      CHR  #
  4204.              
  4205.              
  4206.      CLST    Sets the code listing level.
  4207.              
  4208.              Syntax:
  4209.              
  4210.                            [<label>]  CLST  [<expr>]
  4211.              
  4212.              <expr>, which must not contain forward references,  gives  the
  4213.              new  listing  level.  If  omitted,  the  level is reset to the
  4214.              default from the command line. The values allowed are:
  4215.              
  4216.                           0 List only the first 3  bytes  produced  by  any
  4217.                             line.
  4218.  
  4219.  
  4220.                                       60
  4221.  
  4222.  
  4223.  
  4224.  
  4225.  
  4226.                            USING THE 65C02 ASSEMBLER 
  4227.  
  4228.  
  4229.  
  4230.                             
  4231.                           1 List all the bytes planted by any line except a
  4232.                             CODE directive.
  4233.                             
  4234.                           2 List all the bytes planted by all lines.
  4235.                             
  4236.              Example:
  4237.              
  4238.                                     CLST  2
  4239.              
  4240.              
  4241.      CODE    Includes  a  file  (such  as  a screen dump) directly into the
  4242.              object file.
  4243.              
  4244.              Syntax:
  4245.              
  4246.                           [<label>]  CODE  <filename>
  4247.              
  4248.              The specified file is copied, with no interpretation, directly
  4249.              to the object file. If <label> is  specified  it  is  set  the
  4250.              address  of  the  first  byte  copied.  The  address  count is
  4251.              increased by the size of the file.
  4252.              
  4253.              Example:
  4254.              
  4255.                                  CODE  SCRDUMP
  4256.              
  4257.              
  4258.      CSTR    Similar to STR, but this directive plants  a  byte  containing
  4259.              the  number  of  characters  in  the  string before the string
  4260.              itself. The count includes the $0D byte that is  automatically
  4261.              added at the end of the string.
  4262.              
  4263.              
  4264.      DB      This is identical to DFB.
  4265.              
  4266.      DDB     Defines a number of two-byte values, output in high-low order.
  4267.              
  4268.              Syntax:
  4269.              
  4270.                        [<label>]  DDB  <expr>[,<expr>...]
  4271.              
  4272.              Each  expression  in the operand field is evaluated and stored
  4273.              as a two-byte value. If <label> is present, it is set  to  the
  4274.              address of the high-order byte of the first expression.
  4275.              
  4276.              Each  expression can be preceded by a repeat count as decribed
  4277.              in section 4.2.3.
  4278.              
  4279.              Example:
  4280.              
  4281.                          TABLE  DDB  28,32105,[10]$FFFF
  4282.              
  4283.              
  4284.  
  4285.  
  4286.                                       61
  4287.  
  4288.  
  4289.  
  4290.  
  4291.  
  4292.                            USING THE 65C02 ASSEMBLER 
  4293.  
  4294.  
  4295.  
  4296.      DEFPARS Sets up default parameters for a macro. See section 9.3.3  for
  4297.              full details of this directive.
  4298.              
  4299.              
  4300.      DEND    Terminates a DSECT. 
  4301.              
  4302.              Syntax:
  4303.              
  4304.                                 [<label>]  DEND
  4305.              
  4306.              The  address  that  was  saved  when  the  DSECT directive was
  4307.              encountered is reset.
  4308.              
  4309.              Example:
  4310.              
  4311.                                       DEND
  4312.              
  4313.              
  4314.      DFB     Defines a number of single-byte values.
  4315.              
  4316.              Syntax:
  4317.              
  4318.                        [<label>]  DFB  <expr>[,<expr>...]
  4319.              
  4320.              Each expression in the operand field is evaluated  and  stored
  4321.              as  a  byte  value.  If  <label>  is present, it is set to the
  4322.              address of the first expression.
  4323.              
  4324.              Each expression can be preceded by a repeat count as  decribed
  4325.              in section 4.2.3.
  4326.              
  4327.              Example:
  4328.              
  4329.                            TABLE  DFB  0,[27]1,FRED+2
  4330.              
  4331.              
  4332.      DFDB    This is identical to DDB.
  4333.              
  4334.              
  4335.      DFS     This is identical to DS.
  4336.              
  4337.      DFW     This is identical to DW.
  4338.              
  4339.              
  4340.      DISP    Displays a message on both pass 1 and pass 2.
  4341.              
  4342.              Syntax:
  4343.              
  4344.                            [<label>]  DISP  <string>
  4345.              
  4346.              <string>  may contain references to variables: for details see
  4347.              section 7.1.
  4348.              
  4349.              Example:
  4350.  
  4351.  
  4352.                                       62
  4353.  
  4354.  
  4355.  
  4356.  
  4357.  
  4358.                            USING THE 65C02 ASSEMBLER 
  4359.  
  4360.  
  4361.  
  4362.              
  4363.                       DISP  'Program size is %D(*-$8000)'
  4364.              
  4365.              
  4366.      DISP1   As for DISP, except that the message is displayed only on pass
  4367.              1.
  4368.              
  4369.              
  4370.      DISP2   As for DISP, except that the mesage is displayed only on  pass
  4371.              2.
  4372.              
  4373.              
  4374.      DO      A synonym for IF.
  4375.              
  4376.              
  4377.      DS      Reserves  space  in  the  object  file,  setting  the bytes so
  4378.              affected to zero.
  4379.              
  4380.              Syntax:
  4381.              
  4382.                              [<label>]  DS  <expr>
  4383.              
  4384.              <expr>, which must not include forward references, defines the
  4385.              amount of space to be reserved. If <label> is  present  it  is
  4386.              set to the address of the first byte reserved.
  4387.              
  4388.              Example:
  4389.              
  4390.                            DS  $C000-PROG.TOP.ADDRESS
  4391.              
  4392.              
  4393.      DSECT   Opens  a  "dummy  section" that allows an area of memory to be
  4394.              defined without generating any object code.
  4395.              
  4396.              Syntax:
  4397.              
  4398.                                 [<label>]  DSECT
  4399.              
  4400.              When the DSECT directive is processed, the current address  is
  4401.              noted  by the Assembler, and the value is reset to that at the
  4402.              end of the previous dummy  section  (or  0,  if  this  is  the
  4403.              first).  An  ORG  directive can be used to change the value if
  4404.              required.
  4405.              
  4406.              When the dummy section is terminated by a DEND  directive  the
  4407.              old value of the address is restored.
  4408.              
  4409.              Example:
  4410.              
  4411.                                      DSECT
  4412.              
  4413.              
  4414.      DW      Defines a number of two-byte values output in low-high order.
  4415.              
  4416.  
  4417.  
  4418.                                       63
  4419.  
  4420.  
  4421.  
  4422.  
  4423.  
  4424.                            USING THE 65C02 ASSEMBLER 
  4425.  
  4426.  
  4427.  
  4428.              Syntax:
  4429.              
  4430.                        [<label>]  DW  <expr>[,<expr>...]
  4431.              
  4432.              Each  expression  in the operand field is evaluated and stored
  4433.              as a two-byte value. If <label> is present, it is set  to  the
  4434.              address of the low-order byte of the first exression.
  4435.              
  4436.              Each  expression can be preceded by a repeat count as decribed
  4437.              in section 4.2.3.
  4438.              
  4439.              Example:
  4440.              
  4441.                               TABLE  DW FRED,BERT
  4442.              
  4443.              
  4444.      ELSE    Marks the end of the TRUE branch  of  a  conditional  assembly
  4445.              block  begun  by IF, IFDEF and IFNDEF. For details see section
  4446.              7.
  4447.              
  4448.              
  4449.              
  4450.      ENDM    Terminates the definition  of  a  macro  begun  by  the  MACRO
  4451.              directive.
  4452.              
  4453.              Syntax:
  4454.              
  4455.                                       ENDM
  4456.              
  4457.              
  4458.      EQU     Assigns a value to a symbol.
  4459.              
  4460.              Syntax:
  4461.              
  4462.                               <label>  EQU  <expr>
  4463.              
  4464.              <expr> must not contain forward references.
  4465.              
  4466.              Example:
  4467.              
  4468.                                OSWRCH  EQU  $FFEE
  4469.              
  4470.              
  4471.      EXEC    Specifies  the  bottom 16 bits of the 32 bit execution address
  4472.              of the object code.
  4473.              
  4474.              Syntax:
  4475.              
  4476.                             [<label>]  EXEC  <expr>
  4477.              
  4478.              The catalogue entry of the object file will be updated to show
  4479.              the specified execution address. <expr> can only be  a  16-bit
  4480.              quantity:  the  value  of the two top bytes of the address are
  4481.              set by the MSW directive.
  4482.  
  4483.  
  4484.                                       64
  4485.  
  4486.  
  4487.  
  4488.  
  4489.  
  4490.                            USING THE 65C02 ASSEMBLER 
  4491.  
  4492.  
  4493.  
  4494.              
  4495.              If this directive is not used, the execution address is set to
  4496.              the address defined by the first ORG that is not  in  a  dummy
  4497.              section.
  4498.              
  4499.              Example:
  4500.              
  4501.                                  EXEC  START+3
  4502.              
  4503.              
  4504.      FI      Terminates  a conditional assembly block begun by IF, IFDEF or
  4505.              IFNDEF. For details, see section 7.
  4506.              
  4507.              
  4508.      FIN     This is identical to FI.
  4509.              
  4510.              
  4511.      HEX     Defines a series of bytes in the  object  program,  the  bytes
  4512.              being specified as a hexadecimal string.
  4513.              
  4514.              Syntax:
  4515.              
  4516.                             [<label>]  HEX  <string>
  4517.              
  4518.              <string>  must  contain  hexadecimal  digits (i.e. '0'..'9' or
  4519.              'A'..'F'), and each pair of digits is output as one byte.
  4520.              
  4521.              If <label> is present it is set to the address  of  the  first
  4522.              byte from the string.
  4523.              
  4524.              Example:
  4525.              
  4526.                           BYTE.LIST  HEX  'AB34FF2E7E'
  4527.              
  4528.              
  4529.      IF      Begins a conditional assembly block.
  4530.              
  4531.              Syntax:
  4532.              
  4533.                              [<label>]  IF  <expr>
  4534.              
  4535.              If   <expr>,  which  cannot  contain  forward  references,  is
  4536.              non-zero, the condition is TRUE, otherwise it  is  FALSE.  For
  4537.              details, see section 4.1.
  4538.              
  4539.              
  4540.      IFDEF   Begins a conditional assembly block.
  4541.              
  4542.              Syntax:
  4543.              
  4544.                            [<label>]  IFDEF  <symbol>
  4545.              
  4546.              If <symbol> has been defined, the condition is TRUE, otherwise
  4547.              it is FALSE. For details, see section 7.2
  4548.  
  4549.  
  4550.                                       65
  4551.  
  4552.  
  4553.  
  4554.  
  4555.  
  4556.                            USING THE 65C02 ASSEMBLER 
  4557.  
  4558.  
  4559.  
  4560.              
  4561.              
  4562.      IFNDEF  Begins a conditional assembly block.
  4563.              
  4564.              Syntax:
  4565.              
  4566.                           [<label>]  IFNDEF  <symbol>
  4567.              
  4568.              If  <symbol>  has  not  been  defined,  the condition is TRUE,
  4569.              otherwise it is FALSE. For details, see section 7.2.
  4570.              
  4571.              
  4572.      INCLUDE Begins assembly from a new source  file,  afterwards  resuming
  4573.              with the current file.
  4574.              
  4575.              Syntax:
  4576.              
  4577.                          [<label>]  INCLUDE  <filename>
  4578.              
  4579.              The  Assembler  will  process  lines  from the specified file.
  4580.              Lines in the listing file will begin with an "I"  to  indicate
  4581.              their  origin.  At  end-of-file,  it resumes after the INCLUDE
  4582.              directive.
  4583.              
  4584.              The directive may not be used within  an  INCLUDE  file  or  a
  4585.              macro.
  4586.              
  4587.              Example:
  4588.              
  4589.                               INCLUDE  :3.DEFINES
  4590.              
  4591.              
  4592.      INFO    This is identical to DISP2.
  4593.              
  4594.              
  4595.      LFCOND  Specifies  that  lines  skipped  in  a  conditional  are to be
  4596.              listed.
  4597.              
  4598.              Syntax:
  4599.              
  4600.                                [<label>]  LFCOND
  4601.              
  4602.              For details, see section 4.4.
  4603.              
  4604.              
  4605.      LOAD    Specifies the bottom 16 bits of the 32 bit load address of the
  4606.              object code.
  4607.              
  4608.              Syntax:
  4609.              
  4610.                             [<label>]  LOAD  <expr>
  4611.              
  4612.              The catalogue entry of the object file will be updated to show
  4613.              the specified load  address.  <expr>  can  only  be  a  16-bit
  4614.  
  4615.  
  4616.                                       66
  4617.  
  4618.  
  4619.  
  4620.  
  4621.  
  4622.                            USING THE 65C02 ASSEMBLER 
  4623.  
  4624.  
  4625.  
  4626.              quantity:  the  value  of the two top bytes of the address are
  4627.              set by the MSW directive.
  4628.              
  4629.              If this directive is not used, the load address is set to  the
  4630.              address  defined  by  the  first  ORG  that  is not in a dummy
  4631.              section.
  4632.              
  4633.              Example:
  4634.              
  4635.                                   LOAD  $1902
  4636.              
  4637.              
  4638.      LST     Sets the source listing level.
  4639.              
  4640.              Syntax:
  4641.              
  4642.                             [<label>]  LST  [<expr>]
  4643.              
  4644.              <expr>, which must not contain forward  references,  give  the
  4645.              new  level.  If  omitted,  the  level  is reset to the default
  4646.              specified in the command line.
  4647.              
  4648.              The allowed values are:
  4649.              
  4650.                     0 No lines are listed.
  4651.                       
  4652.                     1 List lines from files, but not from macros.
  4653.                       
  4654.                     2 List all lines, but not directives such as AIF within
  4655.                       macros.
  4656.                       
  4657.                     3 List all lines.
  4658.                       
  4659.              Lines containing errors are always listed.
  4660.              
  4661.              
  4662.      MACRO   Defines a macro.
  4663.              
  4664.              Syntax:
  4665.              
  4666.                                  <label>  MACRO
  4667.              
  4668.              The following lines are stored as the definition of the macro.
  4669.              No ATV substitution is performed on the lines. The  definition
  4670.              is terminated by an ENDM directive.
  4671.              
  4672.              The macro name may not be more than 8 characters long.
  4673.              
  4674.              The MACRO directive may not be used within a macro.
  4675.              
  4676.              Example:
  4677.              
  4678.                                   THING  MACRO
  4679.              
  4680.  
  4681.  
  4682.                                       67
  4683.  
  4684.  
  4685.  
  4686.  
  4687.  
  4688.                            USING THE 65C02 ASSEMBLER 
  4689.  
  4690.  
  4691.  
  4692.              
  4693.      MEXIT   Causes a macro to terminate immediately.
  4694.              
  4695.              Syntax:
  4696.              
  4697.                                      MEXIT
  4698.              
  4699.              
  4700.      MLEN    As  for  ALEN,  but  this  can be used only within a macro and
  4701.              creates a local ATV rather than a global one.
  4702.              
  4703.              
  4704.      MSET    As for ASET, but this can be used  only  within  a  macro  and
  4705.              creates a local ATV rather than a global one.
  4706.              
  4707.              
  4708.      MSTR    As  for  ASTR,  but  this  can be used only within a macro and
  4709.              creates a local ATV rather than a global one.
  4710.              
  4711.              
  4712.      MSTRIP  As for ASTRIP, but this can be used only within  a  macro  and
  4713.              creates a local ATV rather than a global one.
  4714.              
  4715.              
  4716.      MSW     Sets the two top bytes of the load and execution addresses.
  4717.              
  4718.              Syntax:
  4719.              
  4720.                              [<label>]  MSW  <expr>
  4721.              
  4722.              By default the bytes used are $FFFF, but if you are assembling
  4723.              code to run on a second processor you will need to change them
  4724.              to the appropriate value.
  4725.              
  4726.              Example:
  4727.              
  4728.                                      MSW  0
  4729.              
  4730.              
  4731.      ORG     Sets the value of the address counter.
  4732.              
  4733.              Syntax:
  4734.              
  4735.                              [<label>]  ORG  <expr>
  4736.              
  4737.              <expr>,  which  must not contain forward references, gives the
  4738.              new  value.  The  first  ORG  directive  that  is  not  in   a
  4739.              DSECT..DEND  block also defines the default load and execution
  4740.              addresses.
  4741.              
  4742.              The object file is not affected in any way; thus  if  you  use
  4743.              ORG to advance the address value, the Assembler will not plant
  4744.              any  bytes  in  the object file to fill the gap. To accomplish
  4745.              this effect, you can use the DS directive.
  4746.  
  4747.  
  4748.                                       68
  4749.  
  4750.  
  4751.  
  4752.  
  4753.  
  4754.                            USING THE 65C02 ASSEMBLER 
  4755.  
  4756.  
  4757.  
  4758.              
  4759.              Example:
  4760.              
  4761.                                    ORG  $1900
  4762.              
  4763.              
  4764.      PAGE    Defines the page length and width of the listing.
  4765.              
  4766.              Syntax:
  4767.              
  4768.                        [<label>]  PAGE  <expr1>[,<expr2>]
  4769.              
  4770.              <expr1> is the physical number of lines on the paper  (default
  4771.              66). The Assembler leaves a small gap at the end of each page,
  4772.              to avoid the perforations.
  4773.              
  4774.              <expr2>  is the number of characters to print on each line. If
  4775.              omitted, the value is set to 80.
  4776.              
  4777.              PAGE has no effect on the screen display.
  4778.              
  4779.              Example:
  4780.              
  4781.                                   PAGE  88,132
  4782.              
  4783.              
  4784.              
  4785.      QUERY   Displays a question and reads in a reply, which  is  evaluated
  4786.              as an expression and used to define a label.
  4787.              
  4788.              Syntax:
  4789.              
  4790.                             <label>  QUERY  <string>
  4791.              
  4792.              For details, see section 8.3
  4793.              
  4794.              
  4795.              
  4796.      REP     Outputs  a  comment  line  to  the  listing  to  mark a source
  4797.              division.
  4798.              
  4799.              Syntax:
  4800.              
  4801.                              [<label>]  REP  <expr>
  4802.              
  4803.              <expr> must not  exceed  132  and  must  not  contain  forward
  4804.              references.
  4805.              
  4806.              For details, see section 3.5.4
  4807.              
  4808.              
  4809.      SFCOND  Specifies  that  lines  skipped in a conditional should not be
  4810.              listed.
  4811.              
  4812.  
  4813.  
  4814.                                       69
  4815.  
  4816.  
  4817.  
  4818.  
  4819.  
  4820.                            USING THE 65C02 ASSEMBLER 
  4821.  
  4822.  
  4823.  
  4824.              Syntax:
  4825.              
  4826.                                [<label>]  SFCOND
  4827.              
  4828.              For details, see section 7.4
  4829.              
  4830.              
  4831.      SKP     Leaves a gap in the listing or starts a new page.
  4832.              
  4833.              Syntax:
  4834.              
  4835.                              [<label>]  SKP  <expr>
  4836.                 or
  4837.                              [<label>]  SKP  H     
  4838.              
  4839.              In the first form, <expr> gives the number of lines to be left
  4840.              blank. In the second, a new page is started.
  4841.              
  4842.              The SKP directive itself is not listed.
  4843.              
  4844.              Example:
  4845.              
  4846.                                      SKP  5
  4847.              
  4848.              
  4849.      STOP    Aborts the assembly on pass 1, outputting a message.
  4850.              
  4851.              Syntax:
  4852.              
  4853.                            [<label>]  STOP  <string>
  4854.              
  4855.              The Assembler will display <string>, then abort with the error
  4856.              message "Stopped".
  4857.              
  4858.              Example:
  4859.              
  4860.                          STOP  'Too much in page zero'
  4861.              
  4862.              
  4863.      STR     This is  similar  to  ASC,  except  that  the  Assembler  will
  4864.              automatically  add  a  $0D byte (Carriage Return) to the bytes
  4865.              generated.
  4866.              
  4867.              
  4868.      SYSCLI  Issues a MOS command, allowing you, for example, to change the
  4869.              default disc drive.
  4870.              
  4871.              Syntax:
  4872.              
  4873.                           [<label>]  SYSCLI  <string>
  4874.              
  4875.              You need not begin the string to be issued as  a  MOS  command
  4876.              with a "*", but it doesn't matter if you do. Note that care is
  4877.              needed  over  the  commands  you try to execute. Anything that
  4878.  
  4879.  
  4880.                                       70
  4881.  
  4882.  
  4883.  
  4884.  
  4885.  
  4886.                            USING THE 65C02 ASSEMBLER 
  4887.  
  4888.  
  4889.  
  4890.              uses memory will  almost  certainly  corrupt  the  Assembler's
  4891.              workspace and cause assembly to go horriby wrong.
  4892.              
  4893.              Example:
  4894.              
  4895.                                SYSCLI  'DRIVE 2'
  4896.              
  4897.              
  4898.      SYSFX   This directive has no effect.
  4899.              
  4900.              
  4901.      SYSVDU  Outputs one or more bytes to the screen.
  4902.              
  4903.              Syntax:
  4904.              
  4905.                      [<label>]  SYSVDU  <expr>[,<expr>...]
  4906.              
  4907.              The  directive  is  similar  to  the  BASIC  VDU  command. The
  4908.              low-byte of each <expr> is written with a call to OSWRCH. This
  4909.              gives you a means of sending control codes to a printer to set
  4910.              page formats, etc.
  4911.              
  4912.              Normally bytes are written to the screen only; to send them to
  4913.              a printer you need to output a code of "2" to turn the printer
  4914.              on, and, if you wish, to precede each value with a "1" byte to
  4915.              send it only to the printer. SYSVDU operates on both passes of
  4916.              the Assembler.
  4917.              
  4918.              Example:
  4919.              
  4920.                              SYSVDU  2,1,27,1,"E",3
  4921.              
  4922.              
  4923.      TTL     Defines the title string on the top of each listing page.
  4924.              
  4925.              Syntax:
  4926.              
  4927.                             [<label>]  TTL  <string>
  4928.              
  4929.              The Assembler uses the first 20 bytes of  the  string  as  the
  4930.              page title, and also starts a new page.
  4931.              
  4932.              Example:
  4933.              
  4934.                               TTL  'Screen Dumper'
  4935.              
  4936.              
  4937.      TIME    Defines the timestamp string output on each listing page.
  4938.              
  4939.              Syntax:
  4940.              
  4941.                            [<label>]  TIME  <string>
  4942.              
  4943.              The  Assembler  uses  the first 25 bytes of the string for the
  4944.  
  4945.  
  4946.                                       71
  4947.  
  4948.  
  4949.  
  4950.  
  4951.  
  4952.                            USING THE 65C02 ASSEMBLER 
  4953.  
  4954.  
  4955.  
  4956.              new timestamp. The value need not be a time; you can use it as
  4957.              a subsidiary page title.
  4958.              
  4959.              On a Master 128 the directive is ignored, as the timestamp  is
  4960.              read from the real-time clock.
  4961.              
  4962.              Example:
  4963.              
  4964.                           TIME  '25-August-1986 13:00'
  4965.              
  4966.              
  4967.      WAIT    This  displays  a  string  (see  under  DISP), then pauses the
  4968.              assembly until you press a key.
  4969.              
  4970.              
  4971.      WAIT1   As for WAIT, but operates only on pass 1.
  4972.              
  4973.              
  4974.      WAIT2   As for WAIT, but operates only on pass 2.
  4975.      
  4976.  
  4977.  
  4978.  
  4979.  
  4980.  
  4981.  
  4982.  
  4983.  
  4984.  
  4985.  
  4986.  
  4987.  
  4988.  
  4989.  
  4990.  
  4991.  
  4992.  
  4993.  
  4994.  
  4995.  
  4996.  
  4997.  
  4998.  
  4999.  
  5000.  
  5001.  
  5002.  
  5003.  
  5004.  
  5005.  
  5006.  
  5007.  
  5008.  
  5009.  
  5010.  
  5011.  
  5012.                                       72
  5013.  
  5014.  
  5015.  
  5016.  
  5017.  
  5018.                            USING THE 65C02 ASSEMBLER 
  5019.  
  5020.  
  5021.  
  5022.      Appendix 3. DIFFERENCES FROM THE ADE ASSEMBLER
  5023.      
  5024.         The 65C02 Assembler contains a number of similar directives to  the
  5025.      ADE Assembler, and in almost all cases it will be possible to assemble
  5026.      programs written for ADE with it.
  5027.      
  5028.         A  few  directives,  though, have some minor differences, and there
  5029.      are also some small points on source format that must be considered.
  5030.      
  5031.        - Only single- and double-quote characters may delimit strings.
  5032.          
  5033.        - The second delimiter must not be omitted from character constants.
  5034.          
  5035.        - Character constants obey the same rule as strings in the  ASC  and
  5036.          STR  directives  for  control characters and those with bit 7 set.
  5037.          Thus the "|" and "^" characters need to be  doubled  if  they  are
  5038.          being defined as constants.
  5039.          
  5040.        - Strings  containing  commas  or  leading  or  trailing  spaces are
  5041.          specified as macro  parameters  within  normal  string  delimiters
  5042.          rather than in [] brackets.
  5043.          
  5044.        - Macro parameters must always be separated by commas.
  5045.          
  5046.        - The  SYSFX directive is ignored: to achieve the desired effect you
  5047.          should use the SYSCLI directive to issue a *FX command.
  5048.          
  5049.        - Macro libraries are not implemented.
  5050.          
  5051.        - Local labels within macros are not implemented. The system ATV $MC
  5052.          should be used to construct unique labels as described in  section
  5053.          9.5.
  5054.          
  5055.        - Expressions   are   evaluated  fully  hierarchically  rather  than
  5056.          left-to-right.
  5057.          
  5058.        - The "#" arithmetic operator is used for "inequality", returning -1
  5059.          if unequal and 0 if equal, rather than "modulus".
  5060.          
  5061.        - The LST directive has a numeric operand rather  than  the  strings
  5062.          OFF,  ON  and  FULL. For ADE compatibility, define symbols OFF, ON
  5063.          and FULL with the EQU directive to have values 0, 1  and  2.  List
  5064.          level 3 has no equivalent in ADE.
  5065.          
  5066.        - The  load  and  execution  addresses  are  set  by  the  first ORG
  5067.          directive only. To set them to different values use the  LOAD  and
  5068.          EXEC directives.
  5069.          
  5070.  
  5071.  
  5072.  
  5073.  
  5074.  
  5075.  
  5076.  
  5077.  
  5078.                                       73
  5079.  
  5080.  
  5081.  
  5082.