home *** CD-ROM | disk | FTP | other *** search
/ ftp.uni-stuttgart.de/pub/systems/acorn/ / Acorn.tar / Acorn / 6502 / lang / assembler / a01asm.dc2 < prev    next >
Text File  |  1992-05-04  |  89KB  |  2,817 lines

  1.         You could shorten the source, and make  it  easier  to  follow,  by
  2.      replacing  each  occurrence  with  a  macro  call:  you might set up a
  3.      suitable macro with the statements
  4.      
  5.                     ADDTWO  MACRO
  6.                             LDA   VAR
  7.                             CLC
  8.                             ADC   #2
  9.                             STA   VAR
  10.                             ENDM
  11.                     
  12.                     
  13.         Then, instead of writing the four lines of code, simply  write  one
  14.      line
  15.      
  16.                             ADDTWO
  17.      
  18.         The   Assembler   will   expand  the  macro  definition,  and  will
  19.      automatically generate the four lines for you.
  20.      
  21.      
  22.      9.1 Using macro parameters
  23.      
  24.      
  25.         Although this is useful in itself, the  macro  as  shown  above  is
  26.      rather  limited.  It  couldn't,  for instance, be used to add 2 to the
  27.      variable COUNT instead of VAR.
  28.      
  29.         In order  to  provide  this  sort  of  flexibility,  you  can  pass
  30.      information  to  macros  as "parameters". You could re-write the macro
  31.      above to read
  32.      
  33.      
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.                                       42
  42.  
  43.  
  44.  
  45.  
  46.  
  47.                            USING THE 65C02 ASSEMBLER
  48.  
  49.  
  50.  
  51.                     ADDTWO  MACRO
  52.                             LDA   @P1
  53.                             CLC
  54.                             ADC   #2
  55.                             STA   @P1
  56.                             ENDM
  57.                     
  58.         Here we have replaced the occurrences of VAR by the  string  "@P1".
  59.      Now,  when  the  Assembler  expands  the  macro,  it  will replace all
  60.      occurrences of "@P1" with parameter number 1 of the macro call. To add
  61.      2 to VAR, you would then write
  62.      
  63.                             ADDTWO  VAR
  64.      
  65.      and to add 2 to COUNT, you would write
  66.      
  67.                             ADDTWO  COUNT
  68.      
  69.      
  70.         You can supply up to 9 parameters when you call a macro,  and  they
  71.      are  indicated  in  the  body of the macro by @P1, @P2, @P3 and so on.
  72.      (Note that you can also specify the parameters as @1, @2,  @3  and  so
  73.      on, omitting the "P". This is adequate for existing code; however, for
  74.      new  programs you should use the "@P1" form, as this is necessary when
  75.      you come to use the Macro Programming Language)
  76.      
  77.      
  78.      9.2 Specifying macro parameters
  79.      
  80.      
  81.         You can specify anything you want as parameters to macros. A  macro
  82.      can have up to 9 parameters, separated by a comma and optional spaces.
  83.      
  84.         A macro with 3 parameters could be called with lines like
  85.      
  86.                             CHECK  1,FRED,27
  87.                             CHECK  1 ,  FRED  , 27
  88.      
  89.      and so on.
  90.      
  91.         Normally,  the  Assembler  will  remove leading and trailing spaces
  92.      from each parameter. If you require leading or trailing spaces, or  if
  93.      the parameter has to include a comma, you will need to specify it as a
  94.      string, delimited by single- or double-quote characters. Thus, a macro
  95.      call might look like
  96.      
  97.                             THING  'Here, is a comma'
  98.      
  99.      and "@P1" will be replaced in the macro body with the characters
  100.      
  101.                                 Here, is a comma
  102.      
  103.         Note  that  the  string  delimiters  are  not  taken as part of the
  104.      parameter proper.
  105.  
  106.  
  107.                                       43
  108.  
  109.  
  110.  
  111.  
  112.  
  113.                            USING THE 65C02 ASSEMBLER
  114.  
  115.  
  116.  
  117.      
  118.      
  119.      
  120.      9.3 Nesting macros
  121.      
  122.         You can call macros from within macros, up to a depth of 5. If  you
  123.      attempt to nest deeper than that the Assembler will flag an error.
  124.      
  125.      
  126.      
  127.      9.4 Redefining opcodes and directives
  128.      
  129.         The Assembler allows you to set up macros to redefine any opcode or
  130.      directive.   For   example,   you  might  want  to  redefine  the  JSR
  131.      (Jump-to-Subroutine) opcode to automatically save the registers before
  132.      entering the subroutine. You could do this by declaring a macro called
  133.      JSR thus:
  134.      
  135.                          JSR   MACRO
  136.                                PHA
  137.                                TXA
  138.                                PHA
  139.                                TYA
  140.                                PHA
  141.                                JSR   @P1
  142.                                ENDM
  143.                          
  144.         Now, whenever the Assembler comes across a line  with  JSR  in  the
  145.      opcode  field,  it  will  expand the macro JSR rather than obeying the
  146.      opcode. It will plant the code to save the registers,  and  then  will
  147.      come to the line
  148.      
  149.                                JSR  @P1
  150.      
  151.      in the macro.
  152.      
  153.         Here,  because it is already in a macro, the Assembler will not use
  154.      the macro JSR. Instead it will assemble the opcode JSR,  planting  the
  155.      code to enter the subroutine.
  156.      
  157.      
  158.      9.5 Labels within macros
  159.      
  160.      
  161.         Suppose  you  wish  to write a macro that includes a branch of some
  162.      sort. You might write the macro definition as:
  163.      
  164.      
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.                                       44
  174.  
  175.  
  176.  
  177.  
  178.  
  179.                            USING THE 65C02 ASSEMBLER
  180.  
  181.  
  182.  
  183.                          THING  MACRO
  184.                                 LDA    @P1
  185.                                 BEQ    ZERO
  186.                                 EOR    #$FF
  187.                          ZERO   STA    @P2
  188.                                 ENDM
  189.                          
  190.         The first time the macro is called, it plants the code  bytes,  and
  191.      defines the label ZERO as the destination of the BEQ instruction. On a
  192.      subsequent  call,  though,  the  macro will produce the same code, and
  193.      will attempt to define the value of ZERO again. This  of  course  will
  194.      fail, since it already exists from the first macro call.
  195.      
  196.         The  Assembler  provides  a way round this problem, by giving you a
  197.      way of generating unique labels. Every time a  macro  is  called,  the
  198.      Assembler  sets  up what you can regard as a special parameter on your
  199.      behalf, which contains a string that  is  different  for  every  macro
  200.      call.  This  string  is  substituted,  in  the  same  way  as ordinary
  201.      parameters, by writing "@$MC" in the line.
  202.      
  203.         Thus, the above macro could be changed to be:
  204.      
  205.                          THING     MACRO
  206.                                    LDA    @P1
  207.                                    BEQ    ZERO@$MC
  208.                                    EOR    #$FF
  209.                          ZERO@$MC  STA    @P1
  210.                                    ENDM
  211.                          
  212.         Then, on the first macro call, every occurrence of  ZERO@$MC  might
  213.      be  changed to ZERO1X1. On the next call, they become ZERO2X1, so that
  214.      there is no clash between the macros.
  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.                                       45
  240.  
  241.  
  242.  
  243.  
  244.  
  245.                            USING THE 65C02 ASSEMBLER
  246.  
  247.  
  248.  
  249.      10. THE MACRO PROGRAMMING LANGUAGE
  250.      
  251.      
  252.      
  253.         A very powerful feature of the Assembler is its  Macro  Programming
  254.      Language.  This  allows  you  considerable  control  in how macros are
  255.      expanded - you can construct loops, manipulate  macro  parameters  and
  256.      perform  several  other  functions  that  allow you to build macros of
  257.      great power.
  258.      
  259.         Although this facility is mostly intended for  use  within  macros,
  260.      many  of  its  facilities  can  also  be  used outside macros to great
  261.      effect, as this section will explain.
  262.      
  263.         The Macro Programming Language's facilities  build  on  two  source
  264.      language  features  known  as  Assembly  Time  Variables  and Sequence
  265.      Symbols.
  266.      
  267.      
  268.      10.1 Sequence Symbols
  269.      
  270.      
  271.         These are "place markers" within your source files or within macros
  272.      that the Macro Programming Language uses in  loops.  Using  directives
  273.      such as AGO and AIF, you can make the Assembler move up or down within
  274.      a  file  or a macro, letting you repeatedly assemble some parts of the
  275.      source or totally omit others.
  276.      
  277.         Sequence Symbols are very similar to the labels that  are  part  of
  278.      the  source  proper,  and  they  can  contain  the same characters. To
  279.      distinguish them, Sequence Symbols always begin within a "%"  sign  in
  280.      the  first  character  of  the line. The Sequence Symbol should be the
  281.      only thing on  the  line:  if  you do  put  anything  else  there  the
  282.      Assembler will ignore it.
  283.      
  284.         To  take  an example of how Sequence Symbols could be used, suppose
  285.      your source file contained the lines
  286.      
  287.      
  288.                                AGO    %SKIP
  289.                                ASC    'These lines will never '
  290.                                ASC    'get assembled'
  291.                          %SKIP
  292.                                ASC    'But this one will'
  293.                          
  294.                          
  295.         The Assembler will encounter  the  AGO  directive,  and  will  then
  296.      ignore  everything  in  the  source  file  until it finds the Sequence
  297.      Symbol %SKIP. It will then resume its normal processing.
  298.      
  299.         Although this example  will  actually  work,  the  technique  isn't
  300.      greatly  useful,  as  ignoring source lines can be done just as easily
  301.      with the IF..ELSE..FI construction.  However,  AGO  (and  the  various
  302.      conditional  skips such as AIF) also allows you to go backwards in the
  303.  
  304.  
  305.                                       46
  306.  
  307.  
  308.  
  309.  
  310.  
  311.                            USING THE 65C02 ASSEMBLER
  312.  
  313.  
  314.  
  315.      source or macro - there is no other way of achieving this.
  316.      
  317.         The  Sequence  Symbols  used  in  any  file  or  macro  are   quite
  318.      independent of those in any other; thus you can safely use ones of the
  319.      same name in every file and macro, if you wish.
  320.      
  321.      
  322.      10.2 Assembly Time Variables
  323.      
  324.      
  325.         Assembly  Time  Variables,  or  ATVs, are string variables that the
  326.      Assembler itself uses while assembling your source files. As it  reads
  327.      the  program  source  (either  from a file or from the definition of a
  328.      macro) the Assembler continually looks for references to  ATVs.  These
  329.      are replaced - before the line is assembled - with the contents of the
  330.      ATV, thus allowing you to vary the source that is actually processed.
  331.      
  332.         You  can  use  ATVs  in many ways. For example, the first line of a
  333.      source might set an ATV string to  hold  the  version  number  of  the
  334.      program  you  are  assembling;  the  Assembler will then automatically
  335.      replace every reference to that name with the string.  Some  ATVs  are
  336.      created  by  the Assembler itself, and let you incorporate such things
  337.      as the name of the source file into the source itself.
  338.      
  339.         The main use, though, is in controlling  loops  within  macros  and
  340.      within source files.
  341.      
  342.      
  343.           10.2.1 Creating Assembly Time Variables
  344.           
  345.           
  346.            ATVs  have  names similar to the variables that form part of the
  347.           source  proper,  and  you  can  manipulate  them   with   various
  348.           directives.
  349.           
  350.           
  351.           10.2.1.1 Local and Global ATVs
  352.           
  353.           There are two types of ATV: local and global ones. 
  354.           
  355.             a. Global  ATVs exist for the whole of the assembly, and can be
  356.                used anywhere. They are created  and  manipulated  with  the
  357.                ASTR,  ASET,  ASTRIP  and ALEN directives, which you can use
  358.                even inside macros - the ATVs they create will  continue  to
  359.                exist after the macro finishes.
  360.                
  361.             b. Local  ATVs  are  created and manipulated by the MSTR, MSET,
  362.                MSTRIP and MLEN directives. These  directives  can  only  be
  363.                used inside macros, and the ATVs thy create can be used only
  364.                within  the same  macro  - they cease to exist at the end of
  365.                the macro expansion. You would use these,  for  example,  in
  366.                controlling loops within a macro.
  367.                
  368.                In  fact, you have already seen local ATVs in use in section
  369.  
  370.  
  371.                                       47
  372.  
  373.  
  374.  
  375.  
  376.  
  377.                            USING THE 65C02 ASSEMBLER
  378.  
  379.  
  380.  
  381.                9.1 on "Simple Macros". Whenever you  invoke  a  macro,  the
  382.                Assembler  creates  local  ATVs with names P1, P2, P3 and so
  383.                on, each holding one of the parameters you supplied  on  the
  384.                macro call.
  385.                
  386.                For example, the source line
  387.                
  388.                               NAME  ASET  'OSWRCH'
  389.                
  390.                will  set  up  an  ATV  called  NAME, whose contents are the
  391.                string 'OSWRCH'. Since the ASET directive has been used, the
  392.                ATV is global, and can be used anywhere in the assembly.
  393.                
  394.                
  395.                You can create local and global ATVs of the same name if you
  396.                wish. However, if you wish to refer to the  local  ATV,  you
  397.                should  be  careful  to always  use  the  "M"  form  of  the
  398.                directives. The "A" forms will always  create  global  ATVs,
  399.                even if local ones of the same name already exist.
  400.                
  401.                
  402.           10.2.1.2 String and Numeric Values
  403.           
  404.           
  405.           All  ATVs  are  stored  by  the  Assembler as printable character
  406.           strings. However, in many cases you will find  you  use  them  as
  407.           counters  for controlling loops: to make this easy, the Assembler
  408.           will automatically convert ATVs from numbers to strings  whenever
  409.           necessary.
  410.           
  411.           The  rule  used  is  quite  simple.  When processing ASET or MSET
  412.           directives the Assembler examines  the  first  character  of  the
  413.           operand  field. If it is a string delimiter, the operand is taken
  414.           as a string and is not evaluated. If it is any  other  character,
  415.           the  Assembler  treats  the  operand  as  a  numeric  expression,
  416.           evaluates it, and converts the result into a string for storage.
  417.           
  418.           Thus, the line
  419.           
  420.                               COUNT  ASET  15+3  
  421.           
  422.           will set up the ATV COUNT, containing the string "18", but
  423.           
  424.                               COUNT  ASET  '15+3'
  425.           
  426.           sets up the string "15+3".
  427.           
  428.           The operand can be any expression, provided it does  not  contain
  429.           any forward references: thus
  430.           
  431.                             COUNT  ASET  ADDRESS+10
  432.           
  433.           sets  COUNT to hold the string form of the result of adding 10 to
  434.           the address label ADDRESS.
  435.  
  436.  
  437.                                       48
  438.  
  439.  
  440.  
  441.  
  442.  
  443.                            USING THE 65C02 ASSEMBLER
  444.  
  445.  
  446.  
  447.           
  448.           If you use expressions that mix  numeric  and  character  literal
  449.           values,  some  caution  is needed to make sure that the Assembler
  450.           does what you want: for example,
  451.           
  452.                                VALUE  ASET  'A'+3
  453.           
  454.           would produce an error, rather than adding 3 to the code for  the
  455.           character  'A'. This is because the Assembler, seeing the operand
  456.           field beginning with a "'"  character,  will  treat  the  operand
  457.           field  as a string and find that it is invalid. To overcome this,
  458.           you may be able to re-order  the  operand  expression:  thus  you
  459.           could write the above example as
  460.           
  461.                                VALUE  ASET  3+'A'
  462.           
  463.           Now  the  Assembler  will  treat  the  operand field as a numeric
  464.           expression, since it does not begin with a string delimiter.
  465.           
  466.           In some cases, though (particularly in macros where you  may  not
  467.           know  beforehand what the expression may look like) it may not be
  468.           possible to re-order things safely. Here you  can  simply  put  a
  469.           dummy number in front of the expression: thus
  470.           
  471.                              VALUE  ASET  0+'A'+'B'
  472.           
  473.           would  add  the  character  values  'A'  and 'B', the leading "0"
  474.           character forcing the Assembler to treat the operand as a numeric
  475.           expression.
  476.           
  477.           The ALEN and MLEN directives similarly  convert  from  number  to
  478.           string for you. Here the operand must be a string: for example,
  479.           
  480.                           SIZE  ALEN  'A short string'
  481.           
  482.           sets  SIZE  to  hold  the string "14" - the length of the operand
  483.           string, converted from a number into a string.
  484.           
  485.           
  486.           10.2.1.3 String slicing
  487.           
  488.           The ASET and  MSET  directives  also  allow  to  you  to  "slice"
  489.           strings, or extract characters from inside them. You perform this
  490.           by adding some parameters in the operand field: for example
  491.           
  492.                          SLICE  ASET   'abcdefghij',3,2
  493.           
  494.           will  set  SLICE  to  hold  the  string  "cd". The second operand
  495.           parameter specifies the position of the  first  character  to  be
  496.           sliced  out  (the  string  starts  at character 1), and the third
  497.           parameter specifies the number of characters to be sliced.
  498.           
  499.           If you omit the third parameter, exactly one character is sliced:
  500.           thus
  501.  
  502.  
  503.                                       49
  504.  
  505.  
  506.  
  507.  
  508.  
  509.                            USING THE 65C02 ASSEMBLER
  510.  
  511.  
  512.  
  513.           
  514.                           SLICE  ASET   'abcdefghij',3
  515.           
  516.           will set SLICE to hold the string "c".
  517.           
  518.           Occasionally, string manipulations such as slicing may result  in
  519.           strings  that have leading or trailing spaces, and you may not be
  520.           able  to  tell  beforehand  how  many.  The  ASTRIP  and   MSTRIP
  521.           directives remove all leading and trailing spaces, so that
  522.           
  523.                           NEW   ASTRIP   '  abcd    '
  524.           
  525.           would set the string NEW to be "abcd".
  526.           
  527.           
  528.           10.2.1.4 Efficient use of memory
  529.           
  530.           The  strings  contained  by ATVs are held by the Assembler in the
  531.           symbol table, and so compete for memory with other  symbols.  You
  532.           can change the contents of an ATV to a string of different length
  533.           as  often  as  you  wish:  however, every time the string becomes
  534.           longer the Assembler will allocate a new block of memory for  it.
  535.           The   previous   block  cannot  be  used  again,  so  continually
  536.           increasing the size of  an  ATV  can  be  extremely  wasteful  of
  537.           memory.
  538.           
  539.           To   overcome   this,  the  ASTR  and  MSTR  directives  let  you
  540.           pre-declare a block of memory big enough to hold the maximum size
  541.           string you will use. For example,
  542.           
  543.                                  NAME  ASTR  50
  544.           
  545.           sets up a block long enough to hold a 50-byte string without  the
  546.           need to get more memory.
  547.           
  548.           The minimum  amount  of  memory  the Assembler will allocate is 5
  549.           bytes: this is enough to hold the largest possible numeric value,
  550.           so that loop counters will not  cause  memory  wastage  as  their
  551.           values grow - you need not use ASTR and MSTR for them.
  552.           
  553.           
  554.      10.2.2 Simple Substitution of Assembly Time Variables
  555.      
  556.      
  557.         Once  you  have  set  up  ATVs, you can use them to create variable
  558.      source lines. We have already come across this concept in section  9.1
  559.      on "Simple Macros", in the discussion of macro parameter substitution.
  560.      There, we saw that if the source of the macro contained the line
  561.      
  562.      
  563.                                    LDA  #@P1
  564.      
  565.      
  566.      the  Assembler  would replace "@P1" with whatever you had specified as
  567.  
  568.  
  569.                                       50
  570.  
  571.  
  572.  
  573.  
  574.  
  575.                            USING THE 65C02 ASSEMBLER
  576.  
  577.  
  578.  
  579.      the first parameter of the macro when you called it.
  580.      
  581.         ATVs are substituted into source lines in exactly the same way, and
  582.      as we saw, macro parameters are in fact local ATVs.
  583.      
  584.         The rule the Assembler uses is quite simple: whenever it detects an
  585.      "@" sign in the source (other than in a comment line)  it  expects  an
  586.      ATV  name  to  follow. The "@" and the name itself are replaced by the
  587.      contents of the ATV before the line is assembled.
  588.      
  589.         For example, you might keep the version number of a  program  in  a
  590.      small,  quickly-editable  file that is INCLUDEd into the source at the
  591.      start of an assembly. This might contain the line
  592.      
  593.                              VERSION  ASET  "3.45"
  594.      
  595.      which sets the ATV VERSION to hold the string  "3.45".  Then,  at  any
  596.      point  in  the  source  where  you needed to insert the version number
  597.      (such as in a screen message) you could write, for example
  598.      
  599.                         TITLE  ASC  "SuperGame @VERSION"
  600.      
  601.         The Assembler  would  replace  "@VERSION"  with  "3.45"  before  it
  602.      assembled the line, so the string actually planted would be
  603.      
  604.                                 "SuperGame 3.45"
  605.      
  606.         This   technique   lets   you   keep  the  version  number  in  one
  607.      easily-alterable place, and lets the Assembler take  care  of  putting
  608.      the  up-to-date  value  (or parts of the value) into the source at the
  609.      appropriate places.
  610.      
  611.      
  612.         There are some more complex uses of ATV substitution, and we  shall
  613.      discuss these later in section 10.3 on "Writing Complex Macros".
  614.      
  615.      
  616.         Some useful points to note on substitution are:
  617.      
  618.        a. If you want the "@" character to appear in the line the Assembler
  619.           processes,  your  source  must  contain two of them. Thus, if the
  620.           line you really want to assemble is
  621.           
  622.                                ASC  'VAT @ 15%' 
  623.           
  624.           write it in the source file  as
  625.           
  626.                                ASC  'VAT @@ 15%'
  627.           
  628.           
  629.        b. Once the Assembler finds an  "@"  character  in  the  source,  it
  630.           assumes that what follows is an ATV name. The end of this name is
  631.           assumed to be the first non-alphanumeric character that it meets,
  632.           or  the  end of the line. In almost all cases, this will cause no
  633.  
  634.  
  635.                                       51
  636.  
  637.  
  638.  
  639.  
  640.  
  641.                            USING THE 65C02 ASSEMBLER
  642.  
  643.  
  644.  
  645.           difficulty, but occasionally will, usually in complex macros.
  646.           
  647.           As an example, suppose you  had  declared  at  ATV  called  EXPR,
  648.           holding  the  string  "10+".  A subsequent source line might then
  649.           read
  650.           
  651.                                   LDA  #@EXPR3
  652.           
  653.           and the intention is for this to be transformed into
  654.           
  655.                                    LDA  #10+3
  656.           
  657.           In  this  case,  though,  the  substitution  will  fail,  as  the
  658.           Assembler will look for an ATV called EXPR3. To force it to do as
  659.           you want, write the source line as
  660.           
  661.                                  LDA  #@EXPR/3
  662.           
  663.           The  "/" character enables the Assembler to detect the end of the
  664.           ATV name, so it will look for EXPR as it should. The "/" will  be
  665.           discarded, so that the resulting line will be
  666.           
  667.                                    LDA  #10+3
  668.           
  669.           as  intended.  If you need a "/" character in the resulting line,
  670.           write it as "//".
  671.           
  672.           There is another techniques you might use in these circumstances.
  673.           The Assembler does not regard spaces as  significant  in  numeric
  674.           expressions, so that you could write
  675.           
  676.                                  LDA  #@EXPR 3
  677.           
  678.           to achieve the same result.
  679.           
  680.        c. No  ATV  substitution  is  performed  in  comment lines, in lines
  681.           containing Sequence Symbols, or in the definition of macros (i.e.
  682.           between the MACRO and ENDM directives). Apart from these, though,
  683.           substitutions can be made at any  place  in  a  line  -  you  can
  684.           substitute for labels, opcodes, operands or any parts of them.
  685.      
  686.      
  687.      
  688.      10.3 Writing Complex Macros
  689.      
  690.      
  691.      10.3.1 Programming macro loops
  692.      
  693.         Mostly,  you  will  use  the  Macro Programming Language to program
  694.      macro loops, controlled by various conditions.
  695.      
  696.      
  697.  
  698.  
  699.  
  700.  
  701.                                       52
  702.  
  703.  
  704.  
  705.  
  706.  
  707.                            USING THE 65C02 ASSEMBLER
  708.  
  709.  
  710.  
  711.           10.3.1.1 Simple loops controlled by counter
  712.           
  713.           
  714.           The simplest form of loop is one which is executed a fixed number
  715.           of times, and needs only a counter to control it.
  716.           
  717.           As an example, suppose that we need a macro to plant a number  of
  718.           bytes  containing  $FF  with  the DFB directive, the number being
  719.           specified by the first parameter. (There are much easier ways  of
  720.           doing  this  than  with  a  macro,  of course - this only shows a
  721.           general technique).
  722.           
  723.           The macro definition might then be:
  724.           
  725.                          PLANT  MACRO
  726.                          COUNT  MSET    0
  727.                          %LOOP
  728.                                 DFB     $FF
  729.                          COUNT  MSET    @COUNT+1
  730.                                 AIF     @COUNT<@P1,%LOOP
  731.                                 ENDM
  732.                          
  733.           To see how this works, we can examine each line in turn, assuming
  734.           that the macro was called with a line
  735.           
  736.                                     PLANT  7
  737.           
  738.           
  739.           Line 1 : This is the macro definition line.
  740.                    
  741.           Line 2 : This line sets up a local ATV called COUNT, and gives it
  742.                    a string value of "0".
  743.                    
  744.           Line 3 : This is a Sequence Symbol marking the top of  the  loop.
  745.                    Note that there is nothing else on the line with it.
  746.                    
  747.           Line 4 : This is the DFB line that plants the $FF byte required.
  748.                    
  749.           Line 5 : This   line  increments  the  value  of  COUNT.  As  the
  750.                    Assembler reads the line, it encounters "@COUNT",  which
  751.                    it  replaces  with  the current string value of the ATV.
  752.                    Thus the  first  time  this  line  is  encountered,  the
  753.                    Assembler will generate
  754.                    
  755.                                 COUNT  MSET  0+1
  756.                    
  757.                    The second time, it generates
  758.                    
  759.                                 COUNT  MSET  1+1
  760.                    
  761.                    and so on.
  762.                    
  763.           Line 6 : This  tests  whether the Assembler is to loop round once
  764.                    more.  As  with  line  4,  the  Assembler  will  replace
  765.  
  766.  
  767.                                       53
  768.  
  769.  
  770.  
  771.  
  772.  
  773.                            USING THE 65C02 ASSEMBLER
  774.  
  775.  
  776.  
  777.                    "@COUNT" with the current value of the ATV. "@P1" is, of
  778.                    course,  replaced  by  the first parameter of the macro.
  779.                    The first time round, the line processed is
  780.                    
  781.                                 AIF   0<7,%LOOP
  782.                    
  783.                    which is true, so the Assembler skips backwards  in  the
  784.                    macro to line 4 and resumes processing from there.
  785.                    
  786.                    
  787.                    
  788.           
  789.           10.3.1.2 Loops accessing macro parameters
  790.           
  791.           
  792.           Another  frequently-needed  form  of loop is one in which all the
  793.           parameters of the  macro  are  accessed  in  turn.  Suppose,  for
  794.           example,  you  need to write a macro THINGS, whose parameters are
  795.           all numbers. Each number is to be planted in a byte in the object
  796.           file with a DFB directive: to make THINGS interesting, the number
  797.           of parameters must be variable.
  798.           
  799.           Such a  macro  is  fairly  simple  to  write,  but  uses  an  ATV
  800.           substitution  technique  that  can,  at  first sight, be somewhat
  801.           daunting. If the job were simply to plant the value of  parameter
  802.           1, the line in the macro that does it would simply be
  803.           
  804.                                    DFB   @P1
  805.           
  806.           However,  we need to access each parameter in turn: the Assembler
  807.           must somehow be made to see "@P1" the first time round the  loop,
  808.           "@P2"  in  the  second,  and  so on. Effectively, then, we need a
  809.           substitution technique that lets us  have  a variable  ATV  name:
  810.           i.e.  one  that first  substitutes the number ("1", "2", "3" etc)
  811.           then substitutes for the ATV name so formed.
  812.           
  813.           The Assembler can do this easily, since ATV substitution operates
  814.           in a hierarchic fashion. For example, suppose that a source  line
  815.           contains
  816.           
  817.                                    @(P@COUNT)
  818.           
  819.           somewhere.
  820.           
  821.           On  seeing  the  first  "@"  character, the Assembler prepares to
  822.           substitute an ATV. It finds, though, that the next character is a
  823.           "(", so that it now expects a bracketed expression rather than an
  824.           ATV name. It notes where it has got to in the  source  line,  and
  825.           explores within the brackets.
  826.           
  827.           Now,  though,  it  stores  the  characters  it finds (rather than
  828.           passing them on to be assembled), and expects to end  up  with  a
  829.           valid ATV name by the time it gets to the ")" character. It notes
  830.           the  "P",  then  finds the second "@". This makes it try again to
  831.  
  832.  
  833.                                       54
  834.  
  835.  
  836.  
  837.  
  838.  
  839.                            USING THE 65C02 ASSEMBLER
  840.  
  841.  
  842.  
  843.           substitute an ATV, and this time  it  finds  a  real  ATV  called
  844.           COUNT,  which  we  shall  suppose  contains the string "1". After
  845.           "COUNT" it finds the ")" ending the bracketed  expression;  thus,
  846.           within the brackets the string it has built is now "P1".
  847.           
  848.           Having ended the bracketed expression, the Assembler goes back to
  849.           where  it  was.The  "(P@COUNT)" has provided the string "P1", and
  850.           this now is a valid ATV name. So it proceeds  to  substitute  the
  851.           value of ATV P1, the first macro parameter, as we intended.
  852.           
  853.           
  854.           To  see  how  we  might  use  this  technique,  we can consider a
  855.           definition of THINGS:
  856.           
  857.           
  858.                          THINGS  MACRO
  859.                          COUNT  MSET    1
  860.                          %LOOP
  861.                                 AIF     '@(P@COUNT)'='',%ALL.DONE
  862.                                 DFB     @(P@COUNT)
  863.                          COUNT  MSET    @COUNT+1
  864.                                 AIF     @COUNT<10,%LOOP
  865.                          %ALL.DONE
  866.                                 ENDM
  867.                          
  868.           To see how this works, we can examine each line in turn.
  869.           
  870.           Line 1 : This is the macro definition line.
  871.                    
  872.           Line 2 : This line sets up a local ATV called COUNT, and gives it
  873.                    a string value of "1".
  874.                    
  875.           Line 3 : This is a Sequence Symbol marking the top of the loop.
  876.                    
  877.           Line 4 : Since the number of parameters must be variable, we need
  878.                    to test whether we've processed them all.  You  can  see
  879.                    the  substitution  technique discussed above in use here
  880.                    to check if the next parameter is null - any  parameters
  881.                    that  you  don't  supply  in a macro call are strings of
  882.                    zero size. If the parameter is null, the Assembler skips
  883.                    forwards in the macro until  it  gets  to  the  Sequence
  884.                    Symbol %ALL.DONE.
  885.                    
  886.           Line 5 : This  is  the  DFB  line  that  plants the current macro
  887.                    parameter as a byte.
  888.                    
  889.           Line 6 : This line increments the  value  of  COUNT,  as  in  the
  890.                    previous example.
  891.                    
  892.           Line 7 : This  tests  whether the Assembler is to loop round once
  893.                    more. The final macro parameter is  P9,  so  once  COUNT
  894.                    reaches 10 the macro is finished.
  895.                    
  896.           Line 8 : This  is  the Sequence Symbol that line 4 skips to if it
  897.  
  898.  
  899.                                       55
  900.  
  901.  
  902.  
  903.  
  904.  
  905.                            USING THE 65C02 ASSEMBLER
  906.  
  907.  
  908.  
  909.                    finds a null parameter.
  910.                    
  911.           Thus, if the macro was called with a line
  912.           
  913.                               THINGS  1,$FE,FRED-1
  914.           
  915.           the loop would be traversed three times, and the  lines  actually
  916.           assembled would be
  917.           
  918.                                 DFB     1
  919.                                 DFB     $FE
  920.                                 DFB     FRED-1
  921.                          
  922.                          
  923.                          
  924.           The  technique  of  hierarchical  substitution, though most often
  925.           used to access macro parameters in turn,  can  be  used  in  many
  926.           other  applications: you can nest substitutions to as deep as you
  927.           are likely  to  need,  so  that  you  might  write  something  as
  928.           horrendous looking as
  929.           
  930.                            LDA   #@(XX@(COUNT@PTR)B)
  931.           
  932.           if you really needed to.
  933.           
  934.           
  935.           
  936.           10.3.2 Changing macro parameters
  937.           
  938.           
  939.            Macro  parameters  are  in fact local ATVs with names P1, P2, P3
  940.           and so on. This means that you can change them within a macro  as
  941.           you wish.
  942.           
  943.            One  example  of this might be to allow the use of default macro
  944.           parameters (although section 10.3.3 below shows an automatic  way
  945.           to  do  this). Suppose that a macro parameter should be a number,
  946.           whose default value is 1. You could define it as:
  947.           
  948.           
  949.                          TEST  MACRO
  950.                                AIF    '@P1'#'',%NEXT
  951.                          P1    MSET   1
  952.                          %NEXT
  953.                                LDA    #@P1
  954.                                ENDM
  955.                          
  956.           Within this example, we have:
  957.           
  958.           Line 1 : The macro definition line.
  959.                    
  960.           Line 2 : This tests if parameter 1 has been supplied. If  so,  it
  961.                    will  not  be  a  null string, so the Assembler skips to
  962.                    %NEXT.
  963.  
  964.  
  965.                                       56
  966.  
  967.  
  968.  
  969.  
  970.  
  971.                            USING THE 65C02 ASSEMBLER
  972.  
  973.  
  974.  
  975.                    
  976.           Line 3 : This line sets parameter 1 to the default value.
  977.                    
  978.           Line 4 : This is the Sequence Symbol skipped to if the  parameter
  979.                    is not defaulted.
  980.                    
  981.           Line 5 : This  line actually uses the parameter. It will assemble
  982.                    correctly even if the parameter was not given, since  in
  983.                    that  case  line 3 will have set it up to be the default
  984.                    value.
  985.                    
  986.                    
  987.           10.3.3 Setting default macro parameters
  988.           
  989.           
  990.            The example above showed one way of establishing a default value
  991.           of a macro parameter, but in fact  the  Assembler  gives  you  an
  992.           automatic and easy way of doing this with the DEFPARS directive.
  993.           
  994.            The  effect  of  this directive, which you can issue at any time
  995.           inside a macro, is  to  set  the  values  of  any  of  the  macro
  996.           parameters P1, P2, P3 and so on, unless they are already defined.
  997.           
  998.            For example, you might call a macro with a line
  999.           
  1000.                                   FRED    1,,3
  1001.           
  1002.           where  you  have defined parameters 1 and 3, but not parameter 2.
  1003.           If the macro now executes, say,
  1004.           
  1005.                               DEFPARS  100,200,300
  1006.           
  1007.           the Assembler will check the parameters in turn. Parameters 1 and
  1008.           3 are already defined, so the "100"  and  "300"  values  are  not
  1009.           used.  Parameter  2,  though, is not yet defined, so it is set to
  1010.           "200" from this point on.
  1011.           
  1012.            If you wished, say, to establish a default for only some of  the
  1013.           parameters  of  a  macro, simply specify only those parameters in
  1014.           the DEFPARS directive and default the others. Thus
  1015.           
  1016.                                  DEFPARS ,,,44
  1017.           
  1018.           sets a default for parameter 4, but has no effect  whatsoever  on
  1019.           parameters 1, 2, 3, 5, 6, 7, 8 and 9.
  1020.           
  1021.           
  1022.           
  1023.           10.3.4 Listing control for macros
  1024.           
  1025.           
  1026.            If  you  write  complex macros with lots of loops, you will find
  1027.           that the Assembler actually executes a large number of lines that
  1028.           just contain the AIF, MSET directives, etc. This  can  swamp  the
  1029.  
  1030.  
  1031.                                       57
  1032.  
  1033.  
  1034.  
  1035.  
  1036.  
  1037.                            USING THE 65C02 ASSEMBLER
  1038.  
  1039.  
  1040.  
  1041.           listing, and make it hard to see the actual directives that plant
  1042.           data or code (as well as using up a large amount of paper).
  1043.           
  1044.            To  overcome this, list level 2 will not list directives such as
  1045.           MSET, AIF, etc, unless they contain errors. In order  to  see all
  1046.           the  lines  of  a  macro  expansion, use list level 3. (Note that
  1047.           outside macros, ASET and other similar directives  will  list  at
  1048.           level 2).
  1049.           
  1050.           
  1051.           10.3.5 Exiting a macro prematurely
  1052.           
  1053.           
  1054.            You  may  sometimes  need to exit a macro as a result of a test.
  1055.           Depending on circumstances, you may be able to use AIF or AGO  to
  1056.           skip  to the physical end of the macro; however, you can also use
  1057.           the MEXIT directive. This exits the macro  immediately,  wherever
  1058.           in the macro body it is encountered.
  1059.           
  1060.           
  1061.           10.3.6 Comment lines within macros
  1062.           
  1063.            You  can include comment lines within the definitions of macros,
  1064.           just as in normal code. For  example,  a  short  macro  might  be
  1065.           defined as
  1066.           
  1067.           
  1068.                          TEST   MACRO
  1069.                          *
  1070.                          * Adjust value in PTR0
  1071.                          *
  1072.                                 INC    PTR0
  1073.                                 ENDM
  1074.                          
  1075.           The  three  comment lines will be stored in the macro definition,
  1076.           and (if the listing level is set to 2 or higher) will  be  listed
  1077.           whenever  you  call  the  macro. This lets you output comments to
  1078.           describe the actions of the macro. 
  1079.           
  1080.           The disadvantage of this technique is that the comment lines  are
  1081.           stored  in  their  entirety  in memory when the macro is defined,
  1082.           giving you correspondingly less space for the symbol table.
  1083.           
  1084.           When you come to writing complex macros making great use of ATV's
  1085.           and loops, you will find it most advantageous to include  liberal
  1086.           amounts  of  comment.  In order that these comments, which purely
  1087.           document how the macro works rather than the code  it  generates,
  1088.           shouldn't  use  memory,  comment lines beginning with "!" are not
  1089.           stored. Thus, you could write a macro as
  1090.           
  1091.                          TEST  MACRO
  1092.                          !
  1093.                          ! See if first parameter is null
  1094.                          !
  1095.  
  1096.  
  1097.                                       58
  1098.  
  1099.  
  1100.  
  1101.  
  1102.  
  1103.                            USING THE 65C02 ASSEMBLER
  1104.  
  1105.  
  1106.  
  1107.                                AIF    '@P1'#'',%NEXT
  1108.                          !
  1109.                          ! It is null, so reset it to "1"
  1110.                          !
  1111.                          P1    MSET   1
  1112.                          %NEXT
  1113.                          !
  1114.                          ! Parameter 1 now definitely has a value,
  1115.                          ! so we can use it
  1116.                          !
  1117.                                LDA    #@P1
  1118.                                ENDM
  1119.                          
  1120.           The lines beginning "!" will  appear  in  the  listing  when  you
  1121.           define the macro, but will not be stored and will not appear when
  1122.           the macro is called.
  1123.           
  1124.           
  1125.           
  1126.      10.4 System ATVs
  1127.      
  1128.         The  Assembler  provides  a  number  of read-only ATVs that you can
  1129.      substitute.  They  provide  information  on  the  Assembler  and   the
  1130.      environment that you can use to control assembly. Each system ATV name
  1131.      starts with a "$" character: they are
  1132.      
  1133.      
  1134.                     
  1135.           $CLST     The current code listing level.
  1136.                     
  1137.           $DEFCLST  The default code listing level.
  1138.                     
  1139.           $DEFLST   The default listing level.
  1140.                     
  1141.           $FLEVEL   "1"  if  the current file is an INCLUDE file; "0" if it
  1142.                     is not.
  1143.                     
  1144.           $FS       The number of the filing system in use, as returned  by
  1145.                     OSARGS with A=0, Y=0. The Acorn DFS returns "4", Econet
  1146.                     returns "5" and ADFS returns "8".
  1147.                     
  1148.           $LINE     The number of the current source line.
  1149.                     
  1150.           $LST      The current listing level.
  1151.                     
  1152.           $MC       The  macro call counter, used to generate unique labels
  1153.                     within macros (see section 9.5)
  1154.                     
  1155.           $MLEVEL   The current macro nesting level. If not in a macro, the
  1156.                     value is "0".
  1157.                     
  1158.           $OBJECT   The name of the current object file, which may  include
  1159.                     leading or trailing spaces.
  1160.                     
  1161.  
  1162.  
  1163.                                       59
  1164.  
  1165.  
  1166.  
  1167.  
  1168.  
  1169.                            USING THE 65C02 ASSEMBLER
  1170.  
  1171.  
  1172.  
  1173.           $OS       The  version  of  the MOS in use, as returned by OSBYTE
  1174.                     with A=0.
  1175.                     
  1176.           $OSHWM    The primary OSHWM value  of  the  machine  running  the
  1177.                     Assembler.
  1178.                     
  1179.           $PLENGTH  The current page depth used in the assembly listing, as
  1180.                     set by the PAGE directive.
  1181.                     
  1182.           $PWIDTH   The  current  line width of the asembly listing, as set
  1183.                     by the PAGE directive.
  1184.                     
  1185.           $PRINTING Indicates whether the assembly listing is being sent to
  1186.                     the screen or to a printer or file. The value  returned
  1187.                     is  "0" if the listing is being sent to the screen, and
  1188.                     "-1" if it is being sent to a printer or a file.
  1189.                     
  1190.           $SOURCE   The name of the current source file, which may  include
  1191.                     leading or trailing spaces.
  1192.                     
  1193.           $TIME     The  currently-set  timestamp string, which may include
  1194.                     leading or trailing spaces.
  1195.                     
  1196.           $TTL      The currently-set page title string, which may  include
  1197.                     leading or trailing spaces.
  1198.                     
  1199.           $VERSION  The  version  of the Assembler in use. This is returned
  1200.                     as a numeric string, so  that  version  1.60  sets  the
  1201.                     string to be "160".
  1202.                     
  1203.                     
  1204.         For example, the line
  1205.                                   ORG  @$OSHWM
  1206.      
  1207.      could  be  used to set the base address of the code to the OSHWM value
  1208.      of the machine being used, without the need to know  what  that  value
  1209.      was.
  1210.      
  1211.  
  1212.  
  1213.  
  1214.  
  1215.  
  1216.  
  1217.  
  1218.  
  1219.  
  1220.  
  1221.  
  1222.  
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228.  
  1229.                                       60
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.                            USING THE 65C02 ASSEMBLER
  1236.  
  1237.  
  1238.  
  1239.      Appendix 1 : OPCODES AND ADDRESSING MODES
  1240.      
  1241.      
  1242.         The  Assembler  supports  all  the  opcodes  of  the 6502 and 65C02
  1243.      processor families, using standard MOSTEK mnemonics. For  descriptions
  1244.      of  the  opcodes, see for example "The Advanced User Guide for the BBC
  1245.      Micro" (for 6502-compatible opcodes) and the "Master Reference  Manual
  1246.      Part   2"  (both  6502-  and  65C02-compatible  opcodes,  although  it
  1247.      describes the BBC BASIC Assembler syntax which  cannot  be  used  with
  1248.      this Assembler.)
  1249.      
  1250.         The 6502-compatible opcode mnemonics available are:
  1251.       
  1252.       ADC  AND  ASL  BCC  BCS  BEQ  BIT  BMI  BNE  BPL  BRK  BVC  BVS  CLC
  1253.       CLD  CLI  CLV  CMP  CPX  CPY  DEC  DEX  DEY  EOR  INC  INX  INY  JMP
  1254.       JSR  LDA  LDX  LDY  LSR  NOP  ORA  PHA  PHP  PLA  PLP  ROL  ROR  RTI
  1255.       RTS  SBC  SEC  SED  SEI  STA  STX  STY  TAX  TAY  TSX  TXS  TYA
  1256.       
  1257.         The 65C02-only mnemonics are:
  1258.      
  1259.       BRA  DEA  INA  PHX  PHY  PLX  PLY  STZ  TRB  TSB
  1260.       
  1261.         The opcode CLR can be used as a synonym for STZ.
  1262.       
  1263.         The  addressing  modes common to both the 6502 and 65C02 processors
  1264.      are:
  1265.      
  1266.                   Mode                            Syntax
  1267.                
  1268.                Implied                            op
  1269.                Accumulator                        op A  or  op
  1270.                Immediate                          op #expr8
  1271.                  Low byte                         op #>expr
  1272.                  High byte                        op #<expr
  1273.                Zero page                          op expr8
  1274.                  Indexed by X                     op expr8,X
  1275.                  Indexed by Y                     op expr8,Y
  1276.                Absolute                           op expr16
  1277.                  Indexed by X                     op expr16,X
  1278.                  Indexed by Y                     op expr16,Y
  1279.                Indirect pre-indexed               op (expr8,X)
  1280.                Indirect post-indexed              op (expr8),Y
  1281.                Absolute indirect                  op (expr)
  1282.                
  1283.                
  1284.         The addressing modes usable with the 65C02 processor only are:
  1285.      
  1286.                   Mode                            Syntax
  1287.                
  1288.                Zero-page indexed                  op (expr8)
  1289.                Absolute indirect pre-indexed      op (expr16,X)
  1290.                
  1291.                
  1292.         In these definitions, "expr8" represents an 8 bit number;  "expr16"
  1293.  
  1294.  
  1295.                                       61
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.                            USING THE 65C02 ASSEMBLER
  1302.  
  1303.  
  1304.  
  1305.      a 16-bit number; and "expr" a value that is either 8 or 16 bits long.
  1306.      
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326.  
  1327.  
  1328.  
  1329.  
  1330.  
  1331.  
  1332.  
  1333.  
  1334.  
  1335.  
  1336.  
  1337.  
  1338.  
  1339.  
  1340.  
  1341.  
  1342.  
  1343.  
  1344.  
  1345.  
  1346.  
  1347.  
  1348.  
  1349.  
  1350.  
  1351.  
  1352.  
  1353.  
  1354.  
  1355.  
  1356.  
  1357.  
  1358.  
  1359.  
  1360.  
  1361.                                       62
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.                            USING THE 65C02 ASSEMBLER
  1368.  
  1369.  
  1370.  
  1371.      Appendix 2: ASSEMBLER DIRECTIVES
  1372.      
  1373.      
  1374.         The Assembler supports a large number of directives, or pseudo-ops.
  1375.      This  section  gives  a  detailed  definition  of  each,  arranged  in
  1376.      alphabetical order.
  1377.      
  1378.         Directives follow the normal syntax of opcodes. All can be followed
  1379.      by comment fields started with  a  ";"  character;  however,  not  all
  1380.      directives may have labels.
  1381.      
  1382.         In the specification, items enclosed in "[]" brackets are optional,
  1383.      and can be omitted.
  1384.      
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.  
  1391.  
  1392.  
  1393.  
  1394.  
  1395.  
  1396.  
  1397.  
  1398.  
  1399.  
  1400.  
  1401.  
  1402.  
  1403.  
  1404.  
  1405.  
  1406.  
  1407.  
  1408.  
  1409.  
  1410.  
  1411.  
  1412.  
  1413.  
  1414.  
  1415.  
  1416.  
  1417.  
  1418.  
  1419.  
  1420.  
  1421.  
  1422.  
  1423.  
  1424.  
  1425.  
  1426.  
  1427.                                       63
  1428.  
  1429.  
  1430.  
  1431.  
  1432.  
  1433.                            USING THE 65C02 ASSEMBLER
  1434.  
  1435.  
  1436.  
  1437.      AGO     Skips to a Sequence Symbol.
  1438.              
  1439.              Syntax:
  1440.              
  1441.                                 AGO  <sequence>
  1442.              
  1443.              Example:
  1444.              
  1445.                                    AGO  %LOOP
  1446.              
  1447.              
  1448.      AIF     Skips to a Sequence Symbol if a condition is true.
  1449.              
  1450.              Syntax:
  1451.              
  1452.                           AIF  <expr>,<sequence>      
  1453.                 or
  1454.                           AIF  <stringexpr>,<sequence>
  1455.              
  1456.              If <condition> is false assembly continues in the next line.
  1457.              
  1458.              Example:
  1459.              
  1460.                            AIF  'FREDA'>'FRED',%LOOP
  1461.              
  1462.              
  1463.      AIFDEF  Skips to a Sequence Symbol if a symbol has been defined.
  1464.              
  1465.              Syntax:
  1466.              
  1467.                           AIFDEF  <symbol>,<sequence>
  1468.              
  1469.              Example:
  1470.              
  1471.                           AIFDEF  RAM.CODE,%DOING.RAM
  1472.              
  1473.              
  1474.      AIFNDEF Skips  to  a Sequence Symbol if a symbol has not been defined.
  1475.              The syntax is as for AIFDEF.
  1476.              
  1477.              
  1478.      ALEN    Sets a global ATV to the length of the operand string.
  1479.              
  1480.              Syntax:
  1481.              
  1482.                             <label>  ALEN  <string>
  1483.              
  1484.              Example:
  1485.              
  1486.                          SIZE  ALEN  'This is a string'
  1487.              
  1488.              
  1489.              
  1490.  
  1491.  
  1492.  
  1493.                                       64
  1494.  
  1495.  
  1496.  
  1497.  
  1498.  
  1499.                            USING THE 65C02 ASSEMBLER
  1500.  
  1501.  
  1502.  
  1503.      ASC     Defines an ASCII string.
  1504.              
  1505.              Syntax:
  1506.              
  1507.                             [<label>]  ASC  <string>
  1508.              
  1509.              Within <string> you can use the techniques of section 4.3.3 to
  1510.              plant control characters or characters with bit 7  set.  If  a
  1511.              label is specified, it is set to the address of the first byte
  1512.              of the string.
  1513.              
  1514.              Example:
  1515.              
  1516.                           TITLE  ASC  'SuperGame 3.45'
  1517.              
  1518.              
  1519.      ASET    Sets a global ATV to contain a string.
  1520.              
  1521.              Syntax:
  1522.              
  1523.                   <label>  ASET  <string>[,<expr1>[,<expr2>]]
  1524.                 or
  1525.                   <label>  ASET  <expr>                      
  1526.              
  1527.              The final two parameters in the operand field allow the string
  1528.              parameter  to  be  sliced.  Both are expressions that must not
  1529.              involve forward references. <expr1> specifies the  first  byte
  1530.              to  be sliced from the string (the first byte in the string is
  1531.              byte 1). <expr2> defines the size of the  slice;  if  omitted,
  1532.              one byte is extracted.
  1533.              
  1534.              Example:
  1535.              
  1536.                                 COUNT  ASET  100
  1537.              
  1538.              
  1539.      ASTR    Allocates space for a global ATV.
  1540.              
  1541.              Syntax:
  1542.              
  1543.                              <label>  ASTR  <expr>
  1544.              
  1545.              <expr>, which must not contain forward references, defines the
  1546.              space needed. The value can be up to 255 bytes.
  1547.              
  1548.              Example:
  1549.              
  1550.                                 NAME  ASTR  150
  1551.              
  1552.              
  1553.      ASTRIP  Sets  a  global  ATV  to  a string value, removing leading and
  1554.              trailing spaces in the process.
  1555.              
  1556.              
  1557.  
  1558.  
  1559.                                       65
  1560.  
  1561.  
  1562.  
  1563.  
  1564.  
  1565.                            USING THE 65C02 ASSEMBLER
  1566.  
  1567.  
  1568.  
  1569.              Syntax:
  1570.              
  1571.                            <label>  ASTRIP  <string>
  1572.              
  1573.              Example:
  1574.              
  1575.                         MIDDLE  ASTRIP  '   aardvark   '
  1576.              
  1577.              
  1578.      CASC    This is similar in action  to  ASC,  but  will  plant  a  byte
  1579.              containing  the  number of characters within the string before
  1580.              the string itself.
  1581.              
  1582.              
  1583.              
  1584.      CHN     Closes the current source file and starts another.
  1585.              
  1586.              Syntax:
  1587.              
  1588.                            [<label>]  CHN  <filename>
  1589.              
  1590.              The directive is not allowed in an INCLUDE file.
  1591.              
  1592.              Example:
  1593.              
  1594.                                 CHN  :2.NEXTBIT
  1595.              
  1596.              
  1597.      CHR     Defines the character used by the REP directive.
  1598.              
  1599.              Syntax:
  1600.              
  1601.                            [<label>]  CHR  character
  1602.              
  1603.              The character is specified literally, and not as  a  character
  1604.              constant.
  1605.              
  1606.              Example:
  1607.              
  1608.                                      CHR  #
  1609.              
  1610.              
  1611.      CLST    Sets the code listing level.
  1612.              
  1613.              Syntax:
  1614.              
  1615.                            [<label>]  CLST  [<expr>]
  1616.              
  1617.              <expr>,  which  must not contain forward references, gives the
  1618.              new listing level. If omitted,  the  level  is  reset  to  the
  1619.              default from the command line. The values allowed are:
  1620.              
  1621.                           0 List  only  the  first  3 bytes produced by any
  1622.                             line.
  1623.  
  1624.  
  1625.                                       66
  1626.  
  1627.  
  1628.  
  1629.  
  1630.  
  1631.                            USING THE 65C02 ASSEMBLER
  1632.  
  1633.  
  1634.  
  1635.                             
  1636.                           1 List all the bytes planted by any line except a
  1637.                             CODE directive.
  1638.                             
  1639.                           2 List all the bytes planted by all lines.
  1640.                             
  1641.              Example:
  1642.              
  1643.                                     CLST  2
  1644.              
  1645.              
  1646.      CODE    Includes a file (such as a  screen  dump)  directly  into  the
  1647.              object file.
  1648.              
  1649.              Syntax:
  1650.              
  1651.                           [<label>]  CODE  <filename>
  1652.              
  1653.              The specified file is copied, with no interpretation, directly
  1654.              to  the  object file. If <label> is specified it is set to the
  1655.              address of  the  first  byte  copied.  The  address  count  is
  1656.              increased by the size of the file.
  1657.              
  1658.              Example:
  1659.              
  1660.                                  CODE  SCRDUMP
  1661.              
  1662.              
  1663.      CSTR    Similar  to  STR,  but this directive plants a byte containing
  1664.              the number of characters  in  the  string  before  the  string
  1665.              itself.  The count includes the $0D byte that is automatically
  1666.              added at the end of the string.
  1667.              
  1668.              
  1669.      DB      This is identical to DFB.
  1670.              
  1671.      DDB     Defines a number of two-byte values, output in high-low order.
  1672.              
  1673.              Syntax:
  1674.              
  1675.                        [<label>]  DDB  <expr>[,<expr>...]
  1676.              
  1677.              Each expression in the operand field is evaluated  and  stored
  1678.              as  a  two-byte value. If <label> is present, it is set to the
  1679.              address of the high-order byte of the first expression.
  1680.              
  1681.              Each expression can be preceded by a repeat count as described
  1682.              in section 4.2.3.
  1683.              
  1684.              Example:
  1685.              
  1686.                          TABLE  DDB  28,32105,[10]$FFFF
  1687.              
  1688.              
  1689.  
  1690.  
  1691.                                       67
  1692.  
  1693.  
  1694.  
  1695.  
  1696.  
  1697.                            USING THE 65C02 ASSEMBLER
  1698.  
  1699.  
  1700.  
  1701.      DEFPARS Sets up default parameters for a macro. See section 10.3.3 for
  1702.              full details of this directive.
  1703.              
  1704.              
  1705.      DEND    Terminates a DSECT. 
  1706.              
  1707.              Syntax:
  1708.              
  1709.                                 [<label>]  DEND
  1710.              
  1711.              The address that  was  saved  when  the  DSECT  directive  was
  1712.              encountered is reset.
  1713.              
  1714.              Example:
  1715.              
  1716.                                       DEND
  1717.              
  1718.              
  1719.      DFB     Defines a number of single-byte values.
  1720.              
  1721.              Syntax:
  1722.              
  1723.                        [<label>]  DFB  <expr>[,<expr>...]
  1724.              
  1725.              Each  expression  in the operand field is evaluated and stored
  1726.              as a byte value. If <label> is  present,  it  is  set  to  the
  1727.              address of the first expression.
  1728.              
  1729.              Each expression can be preceded by a repeat count as described
  1730.              in section 4.2.3.
  1731.              
  1732.              Example:
  1733.              
  1734.                            TABLE  DFB  0,[27]1,FRED+2
  1735.              
  1736.              
  1737.      DFDB    This is identical to DDB.
  1738.              
  1739.              
  1740.      DFS     This is identical to DS.
  1741.              
  1742.      DFW     This is identical to DW.
  1743.              
  1744.              
  1745.      DISP    Displays a message on both pass 1 and pass 2.
  1746.              
  1747.              Syntax:
  1748.              
  1749.                            [<label>]  DISP  <string>
  1750.              
  1751.              <string>  may contain references to variables: for details see
  1752.              section 8.1.
  1753.              
  1754.              Example:
  1755.  
  1756.  
  1757.                                       68
  1758.  
  1759.  
  1760.  
  1761.  
  1762.  
  1763.                            USING THE 65C02 ASSEMBLER
  1764.  
  1765.  
  1766.  
  1767.              
  1768.                       DISP  'Program size is %D(*-$8000)'
  1769.              
  1770.              
  1771.      DISP1   As for DISP, except that the message is displayed only on pass
  1772.              1.
  1773.              
  1774.              
  1775.      DISP2   As for DISP, except that the message is displayed only on pass
  1776.              2.
  1777.              
  1778.              
  1779.      DO      A synonym for IF.
  1780.              
  1781.              
  1782.      DS      Reserves space in  the  object  file,  setting  the  bytes  so
  1783.              affected to zero.
  1784.              
  1785.              Syntax:
  1786.              
  1787.                              [<label>]  DS  <expr>
  1788.              
  1789.              <expr>, which must not include forward references, defines the
  1790.              amount  of  space  to be reserved. If <label> is present it is
  1791.              set to the address of the first byte reserved.
  1792.              
  1793.              Example:
  1794.              
  1795.                            DS  $C000-PROG.TOP.ADDRESS
  1796.              
  1797.              
  1798.      DSECT   Opens a "dummy section" that allows an area of  memory  to  be
  1799.              defined without generating any object code.
  1800.              
  1801.              Syntax:
  1802.              
  1803.                                 [<label>]  DSECT
  1804.              
  1805.              When  the DSECT directive is processed, the current address is
  1806.              noted by the Assembler, and the value is reset to that at  the
  1807.              end  of  the  previous  dummy  section  (or  0, if this is the
  1808.              first). An ORG directive can be used to change  the  value  if
  1809.              required.
  1810.              
  1811.              When  the  dummy section is terminated by a DEND directive the
  1812.              old value of the address is restored.
  1813.              
  1814.              Example:
  1815.              
  1816.                                      DSECT
  1817.              
  1818.              
  1819.      DW      Defines a number of two-byte values output in low-high order.
  1820.              
  1821.  
  1822.  
  1823.                                       69
  1824.  
  1825.  
  1826.  
  1827.  
  1828.  
  1829.                            USING THE 65C02 ASSEMBLER
  1830.  
  1831.  
  1832.  
  1833.              Syntax:
  1834.              
  1835.                        [<label>]  DW  <expr>[,<expr>...]
  1836.              
  1837.              Each expression in the operand field is evaluated  and  stored
  1838.              as  a  two-byte value. If <label> is present, it is set to the
  1839.              address of the low-order byte of the first expression.
  1840.              
  1841.              Each expression can be preceded by a repeat count as described
  1842.              in section 4.2.3.
  1843.              
  1844.              Example:
  1845.              
  1846.                               TABLE  DW FRED,BERT
  1847.              
  1848.              
  1849.      ELSE    Marks the end of the TRUE branch  of  a  conditional  assembly
  1850.              block  begun  by IF, IFDEF and IFNDEF. For details see section
  1851.              7.
  1852.              
  1853.              
  1854.              
  1855.      ENDM    Terminates the definition  of  a  macro  begun  by  the  MACRO
  1856.              directive.
  1857.              
  1858.              Syntax:
  1859.              
  1860.                                       ENDM
  1861.              
  1862.              
  1863.      EQU     Assigns a value to a symbol.
  1864.              
  1865.              Syntax:
  1866.              
  1867.                               <label>  EQU  <expr>
  1868.              
  1869.              <expr> must not contain forward references.
  1870.              
  1871.              Example:
  1872.              
  1873.                                OSWRCH  EQU  $FFEE
  1874.              
  1875.              
  1876.      EXEC    Specifies  the  bottom 16 bits of the 32 bit execution address
  1877.              of the object code.
  1878.              
  1879.              Syntax:
  1880.              
  1881.                             [<label>]  EXEC  <expr>
  1882.              
  1883.              The catalogue entry of the object file will be updated to show
  1884.              the specified execution address. <expr> can only be  a  16-bit
  1885.              quantity:  the  value  of the two top bytes of the address are
  1886.              set by the MSW directive.
  1887.  
  1888.  
  1889.                                       70
  1890.  
  1891.  
  1892.  
  1893.  
  1894.  
  1895.                            USING THE 65C02 ASSEMBLER
  1896.  
  1897.  
  1898.  
  1899.              
  1900.              If this directive is not used, the execution address is set to
  1901.              the address defined by the first ORG that is not  in  a  dummy
  1902.              section.
  1903.              
  1904.              Example:
  1905.              
  1906.                                  EXEC  START+3
  1907.              
  1908.              
  1909.      FI      Terminates  a conditional assembly block begun by IF, IFDEF or
  1910.              IFNDEF. For details, see section 7.
  1911.              
  1912.              
  1913.      FIN     This is identical to FI.
  1914.              
  1915.              
  1916.      HEX     Defines a series of bytes in the  object  program,  the  bytes
  1917.              being specified as a hexadecimal string.
  1918.              
  1919.              Syntax:
  1920.              
  1921.                             [<label>]  HEX  <string>
  1922.              
  1923.              <string>  must  contain  hexadecimal  digits (i.e. '0'..'9' or
  1924.              'A'..'F'), and each pair of digits is output as one byte.
  1925.              
  1926.              If <label> is present it is set to the address  of  the  first
  1927.              byte from the string.
  1928.              
  1929.              Example:
  1930.              
  1931.                           BYTE.LIST  HEX  'AB34FF2E7E'
  1932.              
  1933.              
  1934.      IF      Begins a conditional assembly block.
  1935.              
  1936.              Syntax:
  1937.              
  1938.                              [<label>]  IF  <expr>
  1939.              
  1940.              If   <expr>,  which  cannot  contain  forward  references,  is
  1941.              non-zero, the condition is TRUE, otherwise it  is  FALSE.  For
  1942.              details, see section 7.1.
  1943.              
  1944.              
  1945.      IFDEF   Begins a conditional assembly block.
  1946.              
  1947.              Syntax:
  1948.              
  1949.                            [<label>]  IFDEF  <symbol>
  1950.              
  1951.              If <symbol> has been defined, the condition is TRUE, otherwise
  1952.              it is FALSE. For details, see section 7.2
  1953.  
  1954.  
  1955.                                       71
  1956.  
  1957.  
  1958.  
  1959.  
  1960.  
  1961.                            USING THE 65C02 ASSEMBLER
  1962.  
  1963.  
  1964.  
  1965.              
  1966.              
  1967.      IFNDEF  Begins a conditional assembly block.
  1968.              
  1969.              Syntax:
  1970.              
  1971.                           [<label>]  IFNDEF  <symbol>
  1972.              
  1973.              If  <symbol>  has  not  been  defined,  the condition is TRUE,
  1974.              otherwise it is FALSE. For details, see section 7.2.
  1975.              
  1976.              
  1977.      INCLUDE Begins assembly from a new source  file,  afterwards  resuming
  1978.              with the current file.
  1979.              
  1980.              Syntax:
  1981.              
  1982.                          [<label>]  INCLUDE  <filename>
  1983.              
  1984.              The  Assembler  will  process  lines  from the specified file.
  1985.              Lines in the listing file will begin with an "I"  to  indicate
  1986.              their  origin.  At  end-of-file,  it resumes after the INCLUDE
  1987.              directive.
  1988.              
  1989.              The directive may not be used within  an  INCLUDE  file  or  a
  1990.              macro.
  1991.              
  1992.              Example:
  1993.              
  1994.                               INCLUDE  :3.DEFINES
  1995.              
  1996.              
  1997.      INFO    This is identical to DISP2.
  1998.              
  1999.              
  2000.      LFCOND  Specifies  that  lines  skipped  in  a  conditional  are to be
  2001.              listed.
  2002.              
  2003.              Syntax:
  2004.              
  2005.                                [<label>]  LFCOND
  2006.              
  2007.              For details, see section 7.4.
  2008.              
  2009.              
  2010.      LOAD    Specifies the bottom 16 bits of the 32 bit load address of the
  2011.              object code.
  2012.              
  2013.              Syntax:
  2014.              
  2015.                             [<label>]  LOAD  <expr>
  2016.              
  2017.              The catalogue entry of the object file will be updated to show
  2018.              the specified load  address.  <expr>  can  only  be  a  16-bit
  2019.  
  2020.  
  2021.                                       72
  2022.  
  2023.  
  2024.  
  2025.  
  2026.  
  2027.                            USING THE 65C02 ASSEMBLER
  2028.  
  2029.  
  2030.  
  2031.              quantity:  the  value  of the two top bytes of the address are
  2032.              set by the MSW directive.
  2033.              
  2034.              If this directive is not used, the load address is set to  the
  2035.              address  defined  by  the  first  ORG  that  is not in a dummy
  2036.              section.
  2037.              
  2038.              Example:
  2039.              
  2040.                                   LOAD  $1902
  2041.              
  2042.              
  2043.      LST     Sets the source listing level.
  2044.              
  2045.              Syntax:
  2046.              
  2047.                             [<label>]  LST  [<expr>]
  2048.              
  2049.              <expr>, which must not contain forward  references,  give  the
  2050.              new  level.  If  omitted,  the  level  is reset to the default
  2051.              specified in the command line.
  2052.              
  2053.              The allowed values are:
  2054.              
  2055.                     0 No lines are listed.
  2056.                       
  2057.                     1 List lines from files, but not from macros.
  2058.                       
  2059.                     2 List all lines, but not directives such as AIF within
  2060.                       macros.
  2061.                       
  2062.                     3 List all lines.
  2063.                       
  2064.              Lines containing errors are always listed.
  2065.              
  2066.              
  2067.      MACRO   Defines a macro.
  2068.              
  2069.              Syntax:
  2070.              
  2071.                                  <label>  MACRO
  2072.              
  2073.              The following lines are stored as the definition of the macro.
  2074.              No ATV substitution is performed on the lines. The  definition
  2075.              is  terminated  by  an  ENDM directive. Within the definition,
  2076.              comment lines starting with "!" will be listed but not  stored
  2077.              in memory.
  2078.              
  2079.              The macro name may not be more than 8 characters long.
  2080.              
  2081.              The MACRO directive may not be used within a macro.
  2082.              
  2083.              Example:
  2084.              
  2085.  
  2086.  
  2087.                                       73
  2088.  
  2089.  
  2090.  
  2091.  
  2092.  
  2093.                            USING THE 65C02 ASSEMBLER
  2094.  
  2095.  
  2096.  
  2097.                                   THING  MACRO
  2098.              
  2099.              
  2100.      MEXIT   Causes a macro to terminate immediately.
  2101.              
  2102.              Syntax:
  2103.              
  2104.                                      MEXIT
  2105.              
  2106.              
  2107.      MLEN    As  for  ALEN,  but  this  can be used only within a macro and
  2108.              creates a local ATV rather than a global one.
  2109.              
  2110.              
  2111.      MSET    As for ASET, but this can be used  only  within  a  macro  and
  2112.              creates a local ATV rather than a global one.
  2113.              
  2114.              
  2115.      MSTR    As  for  ASTR,  but  this  can be used only within a macro and
  2116.              creates a local ATV rather than a global one.
  2117.              
  2118.              
  2119.      MSTRIP  As for ASTRIP, but this can be used only within  a  macro  and
  2120.              creates a local ATV rather than a global one.
  2121.              
  2122.              
  2123.      MSW     Sets the two top bytes of the load and execution addresses.
  2124.              
  2125.              Syntax:
  2126.              
  2127.                              [<label>]  MSW  <expr>
  2128.              
  2129.              By default the bytes used are $FFFF, but if you are assembling
  2130.              code to run on a second processor you will need to change them
  2131.              to the appropriate value.
  2132.              
  2133.              Example:
  2134.              
  2135.                                      MSW  0
  2136.              
  2137.              
  2138.      ORG     Sets the value of the address counter.
  2139.              
  2140.              Syntax:
  2141.              
  2142.                              [<label>]  ORG  <expr>
  2143.              
  2144.              <expr>,  which  must not contain forward references, gives the
  2145.              new  value.  The  first  ORG  directive  that  is  not  in   a
  2146.              DSECT..DEND  block also defines the default load and execution
  2147.              addresses.
  2148.              
  2149.              The object file is not affected in any way; thus  if  you  use
  2150.              ORG to advance the address value, the Assembler will not plant
  2151.  
  2152.  
  2153.                                       74
  2154.  
  2155.  
  2156.  
  2157.  
  2158.  
  2159.                            USING THE 65C02 ASSEMBLER
  2160.  
  2161.  
  2162.  
  2163.              any  bytes  in  the object file to fill the gap. To accomplish
  2164.              this effect, you can use the DS directive.
  2165.              
  2166.              Example:
  2167.              
  2168.                                    ORG  $1900
  2169.              
  2170.              
  2171.      PAGE    Defines the page length and width of the listing.
  2172.              
  2173.              Syntax:
  2174.              
  2175.                        [<label>]  PAGE  <expr1>[,<expr2>]
  2176.              
  2177.              <expr1> is the physical number of lines on the paper  (default
  2178.              66). The Assembler leaves a small gap at the end of each page,
  2179.              to avoid the perforations.
  2180.              
  2181.              <expr2>  is the number of characters to print on each line. If
  2182.              omitted, the value is set to 80.
  2183.              
  2184.              PAGE has no effect on the screen display.
  2185.              
  2186.              Example:
  2187.              
  2188.                                   PAGE  88,132
  2189.              
  2190.              
  2191.              
  2192.      QUERY   Displays a question and reads in a reply, which  is  evaluated
  2193.              as an expression and used to define a label.
  2194.              
  2195.              Syntax:
  2196.              
  2197.                             <label>  QUERY  <string>
  2198.              
  2199.              For details, see section 8.3
  2200.              
  2201.              
  2202.              
  2203.      REP     Outputs  a  comment  line  to  the  listing  to  mark a source
  2204.              division.
  2205.              
  2206.              Syntax:
  2207.              
  2208.                             [<label>]  REP  [<expr>]
  2209.              
  2210.              <expr> must not  exceed  132  and  must  not  contain  forward
  2211.              references. If you omit the value, the Assembler will fill the
  2212.              output line to its full width.
  2213.              
  2214.              For details, see section 3.5.4
  2215.              
  2216.              
  2217.  
  2218.  
  2219.                                       75
  2220.  
  2221.  
  2222.  
  2223.  
  2224.  
  2225.                            USING THE 65C02 ASSEMBLER
  2226.  
  2227.  
  2228.  
  2229.      SFCOND  Specifies  that  lines  skipped in a conditional should not be
  2230.              listed.
  2231.              
  2232.              Syntax:
  2233.              
  2234.                                [<label>]  SFCOND
  2235.              
  2236.              For details, see section 7.4
  2237.              
  2238.              
  2239.      SKP     Leaves a gap in the listing or starts a new page.
  2240.              
  2241.              Syntax:
  2242.              
  2243.                              [<label>]  SKP  <expr>
  2244.                 or
  2245.                              [<label>]  SKP  H     
  2246.              
  2247.              In the first form, <expr> gives the number of lines to be left
  2248.              blank. In the second, a new page is started.
  2249.              
  2250.              The SKP directive itself is not listed.
  2251.              
  2252.              Example:
  2253.              
  2254.                                      SKP  5
  2255.              
  2256.              
  2257.      STOP    Aborts the assembly on pass 1, outputting a message.
  2258.              
  2259.              Syntax:
  2260.              
  2261.                            [<label>]  STOP  <string>
  2262.              
  2263.              The Assembler will display <string>, then abort with the error
  2264.              message "Stopped".
  2265.              
  2266.              Example:
  2267.              
  2268.                          STOP  'Too much in page zero'
  2269.              
  2270.              
  2271.      STR     This is  similar  to  ASC,  except  that  the  Assembler  will
  2272.              automatically  add  a  $0D byte (Carriage Return) to the bytes
  2273.              generated.
  2274.              
  2275.              
  2276.      SYSCLI  Issues a MOS command, allowing you, for example, to change the
  2277.              default disc drive.
  2278.              
  2279.              Syntax:
  2280.              
  2281.                           [<label>]  SYSCLI  <string>
  2282.              
  2283.  
  2284.  
  2285.                                       76
  2286.  
  2287.  
  2288.  
  2289.  
  2290.  
  2291.                            USING THE 65C02 ASSEMBLER
  2292.  
  2293.  
  2294.  
  2295.              You need not begin the string to be issued as  a  MOS  command
  2296.              with a "*", but it doesn't matter if you do. Note that care is
  2297.              needed  over  the  commands  you try to execute. Anything that
  2298.              uses memory will  almost  certainly  corrupt  the  Assembler's
  2299.              workspace and cause assembly to go horribly wrong.
  2300.              
  2301.              Example:
  2302.              
  2303.                                SYSCLI  'DRIVE 2'
  2304.              
  2305.              
  2306.      SYSVDU  Outputs one or more bytes to the screen and printer.
  2307.              
  2308.              Syntax:
  2309.              
  2310.                      [<label>]  SYSVDU  <expr>[,<expr>...]
  2311.              
  2312.              The  directive  is  similar  to  the  BASIC  VDU  command. The
  2313.              low-byte of each <expr> is written with a call to OSWRCH. This
  2314.              gives you a means of sending control codes to a printer to set
  2315.              page formats, etc.
  2316.              
  2317.              SYSVDU will send all the bytes you specify to the  screen.  If
  2318.              you  have used the "-P" command-line option, they will also be
  2319.              sent to the printer. To send the bytes only  to  the  printer,
  2320.              precede  each  with  a  "1" value. The bytes are not sent to a
  2321.              listing file selected with the "-F" option.
  2322.              
  2323.              SYSVDU operates on both passes of the Assembler.
  2324.              
  2325.              Example:
  2326.              
  2327.                                SYSVDU  1,27,1,'E'
  2328.              
  2329.              
  2330.      SYSVDU1 This directive is identical to SYSVDU, but  operates  only  on
  2331.              pass 1.
  2332.              
  2333.              
  2334.      SYSVDU2 This  directive  is  identical to SYSVDU, but operates only on
  2335.              pass 2.
  2336.              
  2337.      TABS    This directive allows you to redefine the  TAB  positions  the
  2338.              Assembler will use when listing source lines.
  2339.              
  2340.              Syntax:
  2341.              
  2342.                       [<label>]  TABS  <expr>[,<expr>...]
  2343.              
  2344.              You may specify up to 14 TAB positions: any excess values will
  2345.              be  ignored.  Specifying  the  directive with no operand filed
  2346.              will reset the built-in defaults.
  2347.              
  2348.              See section 3.2 for more details.
  2349.  
  2350.  
  2351.                                       77
  2352.  
  2353.  
  2354.  
  2355.  
  2356.  
  2357.                            USING THE 65C02 ASSEMBLER
  2358.  
  2359.  
  2360.  
  2361.              
  2362.              
  2363.      TTL     Defines the title string on the top of each listing page.
  2364.              
  2365.              Syntax:
  2366.              
  2367.                             [<label>]  TTL  <string>
  2368.              
  2369.              The Assembler uses the first 20 bytes of  the  string  as  the
  2370.              page title, and also starts a new page.
  2371.              
  2372.              Example:
  2373.              
  2374.                               TTL  'Screen Dumper'
  2375.              
  2376.              
  2377.      TIME    Defines the timestamp string output on each listing page.
  2378.              
  2379.              Syntax:
  2380.              
  2381.                            [<label>]  TIME  <string>
  2382.              
  2383.              The  Assembler  uses  the first 24 bytes of the string for the
  2384.              new timestamp. The value need not be a time; you can use it as
  2385.              a subsidiary page title.
  2386.              
  2387.              On a Master 128 the directive is ignored, as the timestamp  is
  2388.              read  from  the  real-time  clock.  The  Assembler can also be
  2389.              configured to read a third-party  real-time  clock  fitted  to
  2390.              other models.
  2391.              
  2392.              Example:
  2393.              
  2394.                           TIME  '25-August-1986 13:00'
  2395.              
  2396.              
  2397.      WAIT    This  displays  a  string  (see  under  DISP), then pauses the
  2398.              assembly until you press a key.
  2399.              
  2400.              
  2401.      WAIT1   As for WAIT, but operates only on pass 1.
  2402.              
  2403.              
  2404.      WAIT2   As for WAIT, but operates only on pass 2.
  2405.      
  2406.  
  2407.  
  2408.  
  2409.  
  2410.  
  2411.  
  2412.  
  2413.  
  2414.  
  2415.  
  2416.  
  2417.                                       78
  2418.  
  2419.  
  2420.  
  2421.  
  2422.  
  2423.                            USING THE 65C02 ASSEMBLER
  2424.  
  2425.  
  2426.  
  2427.      Appendix 3. DIFFERENCES FROM THE ADE ASSEMBLER
  2428.      
  2429.         The 65C02 Assembler contains a number of similar directives to  the
  2430.      ADE Assembler, and in almost all cases it will be possible to assemble
  2431.      programs written for ADE with it.
  2432.      
  2433.         A  few  directives,  though, have some minor differences, and there
  2434.      are also some small points on source format that must be considered.
  2435.      
  2436.        - Only single- and double-quote characters may delimit strings.
  2437.          
  2438.        - The second delimiter must not be omitted from character constants.
  2439.          
  2440.        - Character constants obey the same rule as strings in the  ASC  and
  2441.          STR  directives  for  control characters and those with bit 7 set.
  2442.          Thus the "|" and "^" characters need to be  doubled  if  they  are
  2443.          being defined as constants.
  2444.          
  2445.        - Strings  containing  commas  or  leading  or  trailing  spaces are
  2446.          specified as macro  parameters  within  normal  string  delimiters
  2447.          rather than in [] brackets.
  2448.          
  2449.        - Macro parameters must always be separated by commas.
  2450.          
  2451.        - The  SYSFX directive is ignored: to achieve the desired effect you
  2452.          should use the SYSCLI directive to issue a *FX command.
  2453.          
  2454.        - Macro libraries are not implemented.
  2455.          
  2456.        - Local labels within macros are not implemented. The system ATV $MC
  2457.          should be used to construct unique labels as described in  section
  2458.          9.5.
  2459.          
  2460.        - Expressions   are   evaluated  fully  hierarchically  rather  than
  2461.          left-to-right.
  2462.          
  2463.        - The "#" arithmetic operator is used for "inequality", returning -1
  2464.          if unequal and 0 if equal, rather than "modulus".
  2465.          
  2466.        - The LST directive has a numeric operand rather  than  the  strings
  2467.          OFF,  ON  and  FULL. For ADE compatibility, define symbols OFF, ON
  2468.          and FULL with the EQU directive to have values 0, 1  and  2.  List
  2469.          level 3 has no equivalent in ADE.
  2470.          
  2471.        - The  load  and  execution  addresses  are  set  by  the  first ORG
  2472.          directive only. To set them to different values use the  LOAD  and
  2473.          EXEC directives.
  2474.          
  2475.  
  2476.  
  2477.  
  2478.  
  2479.  
  2480.  
  2481.  
  2482.  
  2483.                                       79
  2484.  
  2485.  
  2486.  
  2487.  
  2488.  
  2489.                            USING THE 65C02 ASSEMBLER
  2490.  
  2491.  
  2492.  
  2493.      Appendix 4. DIFFERENCES FROM PREVIOUS RELEASES
  2494.      
  2495.         Version 1.60 of the 65C02 Assembler includes several new facilities
  2496.      and  a  number of corrections from the previous 1.52 release. The most
  2497.      important changes made are as follows:
  2498.      
  2499.        
  2500.      - A new directive, TABS, allows the layout  of  listing  lines  to  be
  2501.        configured.  A  patch  facility  allows  the  default settings to be
  2502.        configured.
  2503.        
  2504.      - New directives SYSVDU1 and SYSVDU2 perform the same action as SYSVDU
  2505.        but only on pass 1 and pass 2 respectively.
  2506.        
  2507.      - Comment lines can be started with a "!" character; such lines within
  2508.        macro definitions are not stored  in  memory  and  can  be  used  to
  2509.        annotate the macro itself.
  2510.        
  2511.      - Printer  handling  has  been extensively rewritten to avoid problems
  2512.        when using Econet print servers.
  2513.        
  2514.      - Assembly  listings  can  be  directed  to  a  file  with  the   "-F"
  2515.        command-line option.
  2516.        
  2517.      - String  slicing  operations in the ASET and MSET directives now work
  2518.        exactly as documented. In version 1.52, the string start  and  slice
  2519.        size  parameters were reversed, and the first byte of the string was
  2520.        numbered 0 and not 1.
  2521.        
  2522.      - A new MOS command, *CLI, allows  the  Assembler's  CLI  mode  to  be
  2523.        explicitly entered from any language.
  2524.        
  2525.      - A  REP  directive  with  no operand now fills the output line to its
  2526.        defined width.
  2527.        
  2528.      - System ATVs $PWIDTH and $PLENGTH allow the values set  by  the  PAGE
  2529.        directive to be read.
  2530.        
  2531.      - System  ATV  $PRINTING  allows  the source to determine if an output
  2532.        listing is being sent to printer or file, or to the screen only.
  2533.        
  2534.      - A repeat count of zero in directives such as DB causes no  bytes  to
  2535.        be  written  to  the  object file, rather than repeating the operand
  2536.        65536 times.
  2537.        
  2538.      - A zero operand in the DS directive causes a gap size of zero  rather
  2539.        than 65536.
  2540.        
  2541.      - Patch  facilities  allow the Assembler's translation of source bytes
  2542.        in the range 128..255 to be configured.
  2543.        
  2544.      - Patch facilities force the Assembler to read a  real-time  clock  on
  2545.        machines other than a Master 128.
  2546.        
  2547.  
  2548.  
  2549.                                       80
  2550.  
  2551.  
  2552.  
  2553.  
  2554.  
  2555.                            USING THE 65C02 ASSEMBLER
  2556.  
  2557.  
  2558.  
  2559.      - Patch  facilities  enable  the "~" character to be used in character
  2560.        constants and strings to plant the following character as a  control
  2561.        character with bit 7 set.
  2562.        
  2563.      - Patch  facilities  allow the Form Feeds sent to a printer at the end
  2564.        of a listing to be suppressed.
  2565.        
  2566.      - Source file repositioning (in directives such as AGO, AIF) no longer
  2567.        causes random failures with files larger than 14kbytes on  a  second
  2568.        processor.
  2569.        
  2570.      - The  DB  directive  now accepts negative operands in the range -1 to
  2571.        -127.
  2572.        
  2573.  
  2574.  
  2575.  
  2576.  
  2577.  
  2578.  
  2579.  
  2580.  
  2581.  
  2582.  
  2583.  
  2584.  
  2585.  
  2586.  
  2587.  
  2588.  
  2589.  
  2590.  
  2591.  
  2592.  
  2593.  
  2594.  
  2595.  
  2596.  
  2597.  
  2598.  
  2599.  
  2600.  
  2601.  
  2602.  
  2603.  
  2604.  
  2605.  
  2606.  
  2607.  
  2608.  
  2609.  
  2610.  
  2611.  
  2612.  
  2613.  
  2614.  
  2615.                                       81
  2616.  
  2617.  
  2618.  
  2619.  
  2620.  
  2621.                            USING THE 65C02 ASSEMBLER
  2622.  
  2623.  
  2624.  
  2625.      Appendix 5. CUSTOMISING THE ASSEMBLER
  2626.      
  2627.         Version 1.60 of the Assembler contains a number of options that can
  2628.      be configured or activated by changes to the ROM image. Typically  the
  2629.      facilities  controlled  in  this way are highly specific to particular
  2630.      hardware or modes of working, rather than of general use.
  2631.      
  2632.         In order to configure the Assembler you will  need  to  alter  some
  2633.      bytes  within  it,  using  a  machine  code  monitor  such as Exmon or
  2634.      Beebmon. The things you need to do a simple and  straightforward,  but
  2635.      as  with  all  such  operations,  you  should  make  sure  you have an
  2636.      unaltered copy of the Assembler stored safely on  a  disc  before  you
  2637.      begin.  You will  need  to  be  careful  that  you  alter  the correct
  2638.      locations and put  in  the  correct  values:  the  Assembler  will  be
  2639.      unlikely  to work correctly, and probably will not work at all, if you
  2640.      make a mistake.
  2641.      
  2642.      A5.1 The patch area
  2643.      
  2644.         In order to patch the Assembler, you will first need to locate  the
  2645.      patch table. This is an area of memory that either contains the actual
  2646.      locations  you  alter,  or  contains the addresses of the locations in
  2647.      other parts of the ROM.
  2648.      
  2649.         The patch area is not held at a fixed absolute  address,  but  will
  2650.      always follow the standard sideways ROM header. To find it, look first
  2651.      at  byte  $8007  in  the ROM (in this section, all addresses are given
  2652.      from the base of $8000, which is the memory address the Assembler runs
  2653.      at. To get the offset within a file for the  bytes  concerned,  simply
  2654.      subtract $8000 from all values). Add the value of byte $8007 to $8000,
  2655.      to  obtain  the  address  of  the copyright string (in version 1.60 it
  2656.      reads "(C)1987 Alan Phillips").
  2657.      
  2658.         At the end of the copyright string you will find a byte  containing
  2659.      the  value  of  zero;  the  patch  area starts at the byte immediately
  2660.      following this one.
  2661.      
  2662.         Athough the absolute position  of  the  patch  area  is  not  fixed
  2663.      between  releases, the format of it is, so that the following sections
  2664.      apply to 1.60 and any future releases.
  2665.      
  2666.      
  2667.           A5.1.1 The default TAB position list
  2668.           
  2669.           Bytes 0 and 1 of the patch table are the address of  the  default
  2670.           TAB  table used by the Assembler when listing source lines. (Note
  2671.           that, as usual, the address is stored with the least  significant
  2672.           byte first).
  2673.           
  2674.           The  address  in the patch table takes you to the area of the ROM
  2675.           where the default TAB positions are held.  To  change  them,  you
  2676.           should alter the first byte of the table to contain the number of
  2677.           TAB  positions  you  wish  to  define (the number you use must be
  2678.           between 1 and 14).  Following  this  you  should  place  the  TAB
  2679.  
  2680.  
  2681.                                       82
  2682.  
  2683.  
  2684.  
  2685.  
  2686.  
  2687.                            USING THE 65C02 ASSEMBLER
  2688.  
  2689.  
  2690.  
  2691.           positions themselves; they must be in ascending numeric order.
  2692.           
  2693.           For  example, to define 5 default TAB positions at columns 8, 17,
  2694.           25, 32 and 40, you would change the bytes in the TAB table to be
  2695.           
  2696.                               5  8  17  25  32  40
  2697.           
  2698.           
  2699.           A5.1.2 Source character translation
  2700.           
  2701.           Byte 2 of the  patch  area  controls  how  the  Assembler  treats
  2702.           characters  in the source file with bit 7 set. Normally the value
  2703.           is zero, instructing the Assembler to ignore such bytes. Changing
  2704.           it to some other value makes  the  Assembler replace  such  bytes
  2705.           with the value you supply.
  2706.           
  2707.           Thus,  for  example, you could change the byte in the patch table
  2708.           to the value $40 (the code for  a  space  character)  to  replace
  2709.           source characters with bit 7 set with a space).
  2710.           
  2711.           It  is up to you to make sure that the value you use is sensible:
  2712.           you should set the byte either to a space or to a TAB character.
  2713.           
  2714.           
  2715.           A5.1.3 Real time clock handling
  2716.           
  2717.           Byte 3 of the patch area controls  how  the  Assembler  uses  any
  2718.           real-time clock you may have fitted. By default the value is $FF,
  2719.           and  the Assembler will attempt to read a real-time clock only on
  2720.           a Master 128. You may, though, have fitted a third-party clock to
  2721.           another model:  setting  the  byte  value  to  0  will  make  the
  2722.           Assembler try to read the time on all models.
  2723.           
  2724.           Note,  though,  that your real-time clock must respond to exactly
  2725.           the same *FX calls as used on the Master 128: the  Assembler  has
  2726.           no  means  of  knowing  how to read the time from clocks that are
  2727.           operated in other ways.
  2728.           
  2729.           
  2730.           A5.1.4 Character constant and string options
  2731.           
  2732.           Byte 4 of the patch  area  controls  how  the  "~"  character  is
  2733.           treated  in character constants and strings. By default the value
  2734.           of the byte is zero, and the character  has  no  special  effect.
  2735.           Changing  the  value  to  $FF causes the "~" character to take on
  2736.           special meaning: it will now cause the following character to  be
  2737.           planted  as  a  control  character with bit 7 set. Naturally, you
  2738.           would need to write '~~' in a character constant  to  obtain  the
  2739.           "~" character itself if you turn this option on.
  2740.           
  2741.           
  2742.           
  2743.  
  2744.  
  2745.  
  2746.  
  2747.                                       83
  2748.  
  2749.  
  2750.  
  2751.  
  2752.  
  2753.                            USING THE 65C02 ASSEMBLER
  2754.  
  2755.  
  2756.  
  2757.           A5.1.5 Page throws at the end of a listing
  2758.           
  2759.           Byte  5  of the patch area controls whether the Assembler outputs
  2760.           Form Feed characters to a printer or listing file at the end of a
  2761.           listing. By default the value of the byte is $FF: this makes  the
  2762.           Assembler  output  a Form Feed both before and after the lines of
  2763.           statistics that tell you the number of errors, etc. Changing  the
  2764.           byte   to   0  suppresses  the  Form  Feeds,  so  the  statistics
  2765.           immediately follow the symbol table listing,  with  no  throw  to
  2766.           head-of-form following them.
  2767.           
  2768.  
  2769.  
  2770.  
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776.  
  2777.  
  2778.  
  2779.  
  2780.  
  2781.  
  2782.  
  2783.  
  2784.  
  2785.  
  2786.  
  2787.  
  2788.  
  2789.  
  2790.  
  2791.  
  2792.  
  2793.  
  2794.  
  2795.  
  2796.  
  2797.  
  2798.  
  2799.  
  2800.  
  2801.  
  2802.  
  2803.  
  2804.  
  2805.  
  2806.  
  2807.  
  2808.  
  2809.  
  2810.  
  2811.  
  2812.  
  2813.                                       84
  2814.  
  2815.  
  2816.  
  2817.