home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / program / s / sasm1 / Docs / Manual < prev    next >
Encoding:
Text File  |  1995-08-30  |  149.1 KB  |  3,121 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.                          SSSSS     AAAA
  13.                         SS        AA  AA
  14.                          SS      AA    AA   SSSSS     mmm  mmm
  15.                           SSSS   AA    AA  SS        mm mmmm mm
  16.                              SS  AAAAAAAA   SSSSS   mm   mm   mm
  17.                              SS  AA    AA       SS  mm   mm   mm
  18.                          SSSSS   AA    AA   SSSSS   mm   mm   mm
  19.  
  20.  
  21.                                          Version 1.70
  22.  
  23.  
  24.  
  25.                             Macro Assembler for the Archimedes
  26.  
  27.  
  28.  
  29.                           Copyright David Holden 1991,92,93,94,95
  30.  
  31.  
  32.                                     _______
  33.                                ____|__     |               (R)
  34.                             --|       |    |-------------------
  35.                               |   ____|__  |  Association of
  36.                               |  |       |_|  Shareware
  37.                               |__|   o   |    Professionals
  38.                             -----|   |   |---------------------
  39.                                  |___|___|    MEMBER
  40.  
  41.  
  42.                               Contents
  43.  
  44.             Section 1 - Preliminaries
  45.                     Introduction                    1.1
  46.                     Licence to Use                  1.2
  47.                     How to Register                 1.3
  48.                     Advantages of Registration      1.4
  49.                     Licence to Copy                 1.5
  50.             Section 2 - Using SAsm
  51.                     Use with floppy discs           2.1
  52.                     Command line syntax             2.2
  53.                     Null Parameters                 2.3
  54.                     Source Filenames                2.4
  55.                     Reconciliation of Wildcards     2.5
  56.                     Order of Assembly               2.6
  57.                     Length of Source File           2.7
  58.                     Line number space               2.8
  59.                     A short demonstration           2.9
  60.             Section 3 - The Source File
  61.                     Source File Syntax              3.1
  62.                     General                         3.2
  63.                     Important warning               3.3
  64.                     Warnings and Errors             3.4
  65.                     Comments                        3.5
  66.                     Descriptive text                3.6
  67.                     Large source files              3.7
  68.                     Basic keywords accepted         3.8
  69.                     Directives                      3.9
  70.                     Basic variables                 3.10
  71.                       #ORG                          3.11
  72.                       #SIZE                         3.12
  73.                       #END                          3.13
  74.                       #TYPE                         3.14
  75.                       #OBJ                          3.15
  76.                       #ERRFILE                      3.16
  77.                       #LIB                          3.17
  78.                       #VERBOSE                      3.18
  79.                       #QUIET                        3.19
  80.                       #INCLUDE                      3.20
  81.                       #INSERT                       3.21
  82.                       #AREA                         3.22
  83.                     Multiple data areas             3.23
  84.                       #LISTON                       3.24
  85.                       #LISTOF                       3.25
  86.                       #LISTFILE                     3.26
  87.                       #NOENHANCE                    3.27
  88.                       #ENHANCE                      3.27
  89.                       #XREF                         3.27
  90.                       #NOXREF                       3.30
  91.                       #XRFILE                       3.31
  92.                       #LABELFILE                    3.32
  93.                       #SWION                        3.33
  94.                       #SWIOFF                       3.34
  95.                       #CLI                          3.35
  96.                     Labels and Variables            3.36
  97.                     Defining registers etc.         3.37
  98.                     Defining constants              3.38
  99.                     Conditional Assembly            3.39
  100.                     LDM/STM with Writeback          3.40
  101.                 Assembly Loops                  3.41
  102.                     The OSET variable               3.42
  103.                     Assembly Listing                3.43
  104.                     Creating a Listing file         3.44
  105.                     Listing file directives         3.45
  106.                     Scope of listing                3.46
  107.             Section 4 - Labels
  108.                     Global Labels                   4.1
  109.                     Local Labels                    4.2
  110.                     Local Label Scope               4.3
  111.                     Using Local labels              4.4
  112.                     Previous or Next set            4.5
  113.                     Local Label Example             4.6
  114.                     Examples with Prev/Next         4.7
  115.                     Forward Branch to 00            4.8
  116.                     problems with Local Labels      4.9
  117.             Section 5 - Special features
  118.                     Enhanced 2nd Operand            5.1
  119.                     Extra Mnemonics                 5.2
  120.                     DW and DD                       5.3
  121.                     DB                              5.4
  122.                     Basic variables and DB          5.5
  123.                     ADRL                            5.6
  124.                     MOVL                            5.7
  125.                     DIV                             5.8
  126.             Section 6 - Macros
  127.                     Macro Functions - Pro/Con       6.1
  128.                     Expanded Macros - Pro/Con       6.2
  129.                     Macro Names                     6.3
  130.                     Expanded Macros                 6.4
  131.                       Defining expanded macros      6.5
  132.                       Macro parameters              6.6
  133.                       Local labels in macros        6.7
  134.                       Special features              6.8
  135.                       Examples                      6.9
  136.                       Errors in expanded macros     6.10
  137.                     Macro Functions                 6.11
  138.                       Built-in Functions            6.12
  139.                         FNgap                       6.13
  140.                         FNset                       6.14
  141.                         FNadr                       6.15
  142.                         FNmov                       6.16
  143.             Section 7 - The Macro Library
  144.                     Using the Macro Library         7.1
  145.                     The 'L' parameter               7.2
  146.                     The 'V' parameter               7.3
  147.                     SAsm$Lib OS variable            7.4
  148.                     Preparing a Library             7.5
  149.                     Length of Library file          7.6
  150.             Section 8 - SAsm and the Desktop
  151.                     New features                    8.1
  152.                     Using from the desktop          8.2
  153.             Section 9 - Problems and Questions
  154.                     Reporting and diagnostic        9.1
  155.                     Speed of operation              9.2
  156.                     Memory usage                    9.3
  157.                     Notes on Local Labels           9.4
  158.                     Common problems                 9.5
  159.             Appendices
  160.                     Release History
  161.                     Registration Form
  162.  
  163.                             Introduction
  164.                             ============
  165.     A long time ago when I found I needed more facilities than the Basic
  166.     assembler offers I tried Acorn's AASM. My personal opinion of AASM is
  167.     that it is overpriced, clumsy and, in some ways, less powerful than the
  168.     (free!) Basic assembler. I therefore decided to write my own,
  169.     provisionally titled BAsm. As usual it had to be fitted in with other
  170.     things, and meanwhile I needed an assembler. I continued to use the
  171.     Basic assembler for short utilities and AASM for longer ones. Soon I
  172.     found I was using AASM less as I gradually added bits to the Basic
  173.     assembler to give the additional facilities I needed.
  174.  
  175.     To make life easier I wrote a 'pre-processor' for the Basic assembler as
  176.     a stop-gap until I finished BAsm. Gradually it was improved and with
  177.     each improvement the need for BAsm receded and work on it assumed a
  178.     lower priority. Eventually my stop-gap program assumed a life of it's
  179.     own and had become so powerful that it could do just about everything I
  180.     wanted. At this point I realised it would be useful to others as well. I
  181.     re-wrote the program, making lot's of improvements, and named it SASM -
  182.     Simple ASseMbler
  183.  
  184.     Don't be put off by the word 'Simple'. Unless you are re-writing
  185.     Impression SAsm will probably fulfil all your needs. Simple is intended
  186.     to describe its ease of use. Its main limitation is that it cannot
  187.     produce output in AOF (Acorn Object Format) for linking to 'C' or other
  188.     languages. If you want to write in 'C' I'm afraid you are stuck with
  189.     ObjAsm or !AS until I get around to finishing BAsm. It also cannot
  190.     assemble Floating Point opcodes although you could add Macros to do
  191.     this. If you really must use them (I've never found the need) ask and I
  192.     will try to include them.
  193.  
  194.     SAsm is not an assembler. It is a pre-processor for the Basic assembler.
  195.     Don't worry about this. As far as the user is concerned SAsm works with
  196.     Text source files and behaves like a 'proper' assembler. It has lots of
  197.     facilities that the Basic assembler normally lacks, local labels,
  198.     multi-file assembly, error reovery, etc. yet at the same time the syntax
  199.     will be familiar to anyone who has used the Basic assembler. You also
  200.     have the power of Basic available with its Mathematical, Conditional
  201.     Assembly and Expression Evaluation abilities
  202.  
  203.     If you are not an expert at using the Basic assembler I suggest you read
  204.     the file 'Tutorial'. It won't teach you to write machine code but it
  205.     explains the use of Macro Function and Conditional Assembly with the
  206.     Basic assembler helps you understand SAsm better. (SAsm actually has
  207.     another, better, Macro system as well as Basic style Functions).
  208.  
  209.     Please read carefully the 'Licence to Use' and 'Licence to Copy' before
  210.     you use/copy SAsm.
  211.  
  212.                     David Holden
  213.                     39 Knighton Park Road
  214.                     Sydenham
  215.                     London SE26 5RN
  216.                       081 778 2659
  217.  
  218.     If you have any problems or suggestions for improvements to SAsm please
  219.     write or phone. If you write with an enquiry please enclose an SAE. If
  220.     you prefer to telephone I am normally available on weekday evenings.
  221.  
  222.     SAsm was produced by a member of the Association of Shareware
  223.     Professionals (ASP). ASP wants to make sure that the Shareware principle
  224.     works for you. If you are unable to resolve a Shareware related problem
  225.     with an ASP member by contacting the member directly, ASP may be able to
  226.     help. The ASP Ombudsman can help you resolve a dispute or problem with
  227.     an ASP member, but does not provide technical support for members'
  228.     products. Please write to the ASP Ombudsman at 545 Grover Road,
  229.     Muskegon, MI 49442-9427, U.S.A.  or send a CompuServe message via
  230.     CompuServe Mail to ASP Ombudsman 70007,3536 or FAX 616-788-2765.
  231.  
  232.                This program is not Public Domain, it is
  233.  
  234.        ssss  h   h   aaa   rrrr   eeeee  w      w   aaa   rrrr   eeeee
  235.       s      h   h  a   a  r   r  e      w      w  a   a  r   r  e
  236.        ssss  hhhhh  a   a  rrrr   eeee   w  w   w  a   a  rrrr   eeee
  237.            s h   h  aaaaa  r  r   e      w  w   w  aaaaa  r  r   e
  238.        ssss  h   h  a   a  r   r  eeeee   ww  ww   a   a  r   r  eeeee
  239.  
  240.     1.2    Licence to Use
  241.  
  242.     This program is distributed as Shareware. It is not Public Domain.
  243.     Shareware is not a type of software, it is a means of distributing
  244.     commercial software on a 'try before you buy' basis. Unless you have
  245.     already Registered you have not paid for the program, even if you paid a
  246.     fee to a PD Library or BBS for your copy. You are only licensed to use
  247.     SAsm for a period of Thirty Days. The trial period enables you to decide
  248.     if SAsm is suitable for you, and at the end of that time you must either
  249.     stop using it or Register. If you decide not to register you must stop
  250.     using SAsm immediately. Failure to comply with this condition is a
  251.     Breach of Copyright and recognised in almost all countries as Software
  252.     Piracy and therefore an offence.
  253.  
  254.         1.3       How to Register
  255.  
  256.     Registration costs just Ten Pounds, plus Two Pounds if you require a
  257.     laser printed manual. I have made the last page of this Manual a
  258.     Registration Form. Please use it when you register as it helps me to
  259.     keep my records tidy. Fill it in, preferably adding comments, and post
  260.     it to me. Don't forget your cheque for Eight Pounds. Write as much as
  261.     you wish, I do take notice of comments and suggestions.
  262.  
  263.     Each assembler for the ARM processor will produce slightly different hex
  264.     values for the same assembler mnemonics. SAsm leaves its 'fingerprints'
  265.     on the code produced. I can tell if a program was assembled using SAsm.
  266.     I will take action against ANYONE who uses SAsm and distributes code
  267.     WITHOUT REGISTRATION in breach of this licence
  268.  
  269.         1.4    Advantages of Registration
  270.  
  271.     The first advantage is that you will not, of course, be breaking the
  272.     law. Registration costs just Ten Pounds, so it's not expensive. However
  273.     there are some material advantages.
  274.  
  275.     When you register you will receive your personal copy of the latest
  276.     version of SAsm which can use external Macro Libraries This enables SAsm
  277.     to load Macros automatically during assembly. You will also receive the
  278.     tools to create Macro Libraries. This makes your code simpler because
  279.     you don't need to include all the macro definitions within it before you
  280.     call them. For an extra two pounds you can have a laser printed manual.
  281.  
  282.     You will also have the right to FREE UPDATES. Once you have registered
  283.     you can return your ORIGINAL copy of SAsm to me with a stamped, self
  284.     addressed label at any time for a copy of the latest version. To take
  285.     advantage of this offer you MUST return your ORIGINAL disc with your
  286.     personal copy of SAsm, not just a blank disc. You will also be entitled
  287.     to free or very low cost upgrades to any future assemblers or compilers
  288.     that I produce even if these are not part of the SAsm 'family'.
  289.  
  290.         1.5    Licence to Copy
  291.  
  292.     If you are a Sysop or run a PD or Shareware library READ THIS CAREFULLY.
  293.  
  294.         1.  The Author retains full copyright to this program and all the
  295.         material and documentation associated with it.
  296.  
  297.     2.  Any private individual may give copies of the unregistered
  298.         version of SAsm to his/her friends. Only PD or Shareware libraries
  299.         and BBS's which have been given permission by the Author are
  300.         permitted to distribute SAsm. Any distribution by any organisation
  301.         or for any reward whatsoever whether in fee or in kind without
  302.         permission is forbidden and will be treated as Breach of Copyright
  303.         even if the fee is merely intended to cover costs.
  304.  
  305.     3.  You may not make any changes to the program or documentation and you
  306.         must include the Examples directory and its contents and the
  307.         Tutorial, Manual and all other associated files. You may not make
  308.         any charge for this program or for any additional material you
  309.         supply. You may charge a reasonable fee to cover copying, media,
  310.         postage, overheads, etc.
  311.  
  312.     4.  You may not under any circumstances distribute copies of any
  313.         registered version of SAsm. These can be distinguished  because they
  314.         display the name of the registered user after the copyright message
  315.         whereas the version which may be freely distributed displays the
  316.         word 'Unregistered'.
  317.  
  318.     5.  You must not distribute any version of the 'MakeLib' application.
  319.         This is for the use of Registered users ONLY.
  320.  
  321.     6.  It is absolutely forbidden to distribute or copy any printed or
  322.         hardcopy version of the documentation, either in whole or in part.
  323.         The printed version of the Manual is for the personal use of
  324.         registered users only.
  325.  
  326.                             David Holden
  327.                             39 Knighton Park Road
  328.                             Sydenham
  329.                             London SE26 5RN
  330.                              081 778 2659
  331.  
  332.                             Using SAsm
  333.                                 ==========
  334.     SAsm is a 'Transient' program. When it is invoked by typing it's name at
  335.     the OS '*' prompt it is loaded from disc and Run. You will find two
  336.     versions of SAsm on the distribution disc. One is the transient
  337.     application, and the other is a Relocatable Module called SAsmMod. This
  338.     will be the preferred method if you don't have a hard disc. Load the
  339.     Module by double-clicking on it and it will then run from the RMA
  340.     whenever you type 'SASM' in exactly the same way as the transient
  341.     program runs from disc. The only disadvantage of the Module is that it
  342.     will take up an extra 25K or so of RAM in the RMA.
  343.  
  344.     Note that the Module version of SAsm does not actually run from the RMA.
  345.     When you invoke it the program code is copied down to &8000 and run from
  346.     there. It will therefore have the amount of RAM available that you have
  347.     set for the 'Next Slot' in the Task window. There is functionally no
  348.     difference between the two versions.
  349.  
  350.     From version 1.70 there is a desktop application !SAsm which will do
  351.     most of the work required to enable you to assemble complex projects
  352.     within the desktop. This lets you avoid using the CLI parameters and
  353.     switches described in the following section. However, you should read
  354.     through this as it will help you to understand how SAsm works, even
  355.     though you may never need to use them.
  356.  
  357.         2.1      Use from floppy discs
  358.  
  359.     Although SAsm will work much faster with a hard disc it is perfectly
  360.     satisfactory when used without one. In fact it was deliberately designed
  361.     with floppy disc operation in mind. If you have enough memory you can
  362.     use a RAM disc to hold all your files. The disadvantage of this is that
  363.     if you modify a source files and suffer a crash before you remember to
  364.     save the modified files you could lose part of your work.
  365.  
  366.     As SAsm uses only block file operations to load the source and save the
  367.     object files it will still operate quite fast from floppy discs. If you
  368.     use the Module version of SAsm this will save the time overhead of
  369.     loading the assembler itself each time. The slowest file operations are
  370.     associated with error, listing and label cross-reference files as these
  371.     are written line by line. The obvious solution is to direct all these to
  372.     the RAM disc which will be much faster than a floppy. As these files are
  373.     normally only needed temporarily it will not matter if they are lost. To
  374.     further reduce disc access time you could save the object file to the
  375.     RAM disc and copy your macro library (if used) there.
  376.  
  377.         2.2      Command line syntax
  378.  
  379.     The full syntax of the command string for SAsm is;
  380.  
  381.       SASM <source file list> [object filename] [error filename] [LXVQSNFA]
  382.  
  383.     Only <source file> is compulsory, the others are optional. So, after
  384.     *SASM leave one or more spaces and then type the name of your source
  385.     file(s). You can have as many as you like, separated by commas. The full
  386.     meaning of <source file list> is quite complex and for the complete
  387.     explanation read the section titled 'Source Filenames'.
  388.  
  389.     Because SAsm uses spaces a delimiters between command line fields you
  390.     must NOT put any spaces in your source file list.
  391.  
  392.     After the source file(s) leave a space then type the name of the Object
  393.     File. This is the name that will be given to the assembled code when it
  394.     is saved. If you don't type an Object Filename SAsm will assemble all
  395.     the files but won't save the finished product. You may wish to do this
  396.     if you just want to check for errors or find out how long the finished
  397.     code is it can be useful.
  398.  
  399.     The next parameter is the name of the Error File. Unlike the Basic
  400.     assembler SAsm will display error messages and try to continue with
  401.     assembly if it can. If you have many errors the first ones will scroll
  402.     off the screen and get lost. If you define a name for an error file all
  403.     error messages will be sent to the file. This can be loaded into an
  404.     Editor with the source code in another window so you can find and
  405.     correct them. If you use a Task Window you could 'capture' error
  406.     messages in this but a separate error file is neater.
  407.  
  408.     After the three filenames you can type one or more single letter
  409.     parameters or 'switches'. These may be in in upper or lower case. If you
  410.     use more than one they should be separated by spaces. Most of these
  411.     duplicate or interreact with Directives in the files and so the
  412.     descriptions here are rather brief because more information will be
  413.     found in the section on Directives.
  414.  
  415.     The 'X' parameter will cross reference (X-ref) all labels in the source
  416.     and report duplicates. If a duplicate is found a warning message is
  417.     displayed with the name of the label and the line number at which it
  418.     occurs. You can include this each time but normally it is only needed
  419.     the first time you link all your files as sometimes a duplicate label is
  420.     perfectly valid. For example I often use 'loop' or 'bak' repeatedly and
  421.     don't want a screen full of warnings. You can create a list of duplicate
  422.     names as a file by use of the #XRFILE directive (see later).
  423.  
  424.     'L' forces SAsm NOT to load any Macro definitions from the Library, even
  425.     if one exists. See the section on the Macro Library for an explanation
  426.     of this.
  427.  
  428.     'V' makes SAsm 'verbose' when loading Expanded Macros from a Library. As
  429.     each macro is loaded it's name is displayed. This is not normally needed
  430.     but it is included in case you want to check whether SAsm is using a
  431.     macro defined in the file or from the Library.
  432.  
  433.     'A' will produce an Assembler Listing file. If 'A' is followed by a
  434.     filename this will be used, otherwise it will be saved to the current
  435.     directory with the name 'ListFile'. If you do wish to use the default
  436.     name for a listing file make sure that the 'A' command is the last item
  437.     on the line, otherwise it will 'grab' the next parameter as a filename.
  438.     You will find more information on assembler listing files later. (NB-
  439.     The more obvious 'L' isn't used for a listing file because it was
  440.     already allocated by the time this feature was included.)
  441.  
  442.     'F' formats an assembler listing file with labels at the left and
  443.     instructions indented.
  444.  
  445.     'S' switches on processing of SWI names. This is described fully in the
  446.     section on the SWION/SWIOFF directives.
  447.  
  448.     'Q' makes SAsm Quit after pre-processing is complete but before
  449.     assembly. This is useful if you get a serious error during assembly as
  450.     it lets you produce a listing without the possibility of a complete
  451.     crash during assembly.
  452.  
  453.     'N' will list all global label Names after pre-processing. This is in
  454.     the form of list on the screen in alphabetical order. This switch will
  455.     stop a label cross-reference check so don't use 'X' and 'N' at the same
  456.     time. As this list is likely to be rather long you can use the LABELFILE
  457.     directive to save it to a file if you wish
  458.  
  459.         2.3      Null Parameters
  460.  
  461.     You will notice that these names must appear in order. So can you
  462.     produce an error file but no object file?, or a X-ref but no Error or
  463.     Object file? If these switches are defined within the source there is no
  464.     problem but most of the time this will not be the case as you would only
  465.     need x-ref or listing files for de-bugging purposes. To permit switches
  466.     to be used at the command line when one or more of the file names is not
  467.     present SAsm accepts the ~ character or any filename beginning with ~ as
  468.     the equivalent of no filename.
  469.  
  470.     For example, to assemble the source file 'My_Prog' without producing an
  471.     object file but listing all errors in the file 'Errors' you could use -
  472.  
  473.             *SASM  MyProg  ~  Errors
  474.  
  475.     If you use the '~' character in the object filename position you will
  476.     not get an object file even if a name is defined in the source file.
  477.     There is therefore a further alternative. If you use '!' as an object
  478.     filename SAsm will only produce an object file if the name is defined in
  479.     the source. The '!' character is interpreted as 'only produce an object
  480.     file when an OBJ directive exists'. This permits you to use switches and
  481.     an object file without needing to type a source file name.
  482.  
  483.         2.4      Source Filenames
  484.  
  485.     The source filename list can be a single filename or a series of names
  486.     separated by commas. Don't use spaces to separate the names because SAsm
  487.     regards a space as a field delimiter. This is important because if you
  488.     do use a space between source filenames and if SAsm is able to
  489.     successfully assemble the first file(s) the next name will be taken as
  490.     the object filename. This will result in the code being saved with this
  491.     name which will destroy the source file of the same name. Normally this
  492.     can't happen because the fact that some of the files aren't loaded will
  493.     produce errors but it could, so beware!
  494.  
  495.     Most users will probably use a 'make' file with 'INCLUDE' filenames to
  496.     assemble a project but you should understand the full command line
  497.     syntax to ensure that you know exactly how SAsm operates with wildcarded
  498.     filenames.
  499.  
  500.     To assemble the files  Start, Middle and End  in that order into the
  501.     object file  Code  you would use;
  502.  
  503.             *SASM  Start,Middle,End  Code
  504.  
  505.     This assumes the files are in the Currently Selected Directory (CSD).
  506.     Each name can of course have a path as well. If you have some standard
  507.     sub-routines called Subs in directory $.Source.Routines you could use;
  508.  
  509.     *SASM  Start,Middle,$.Source.Routines.Subs,End  Code
  510.  
  511.     SAsm loads the files in the order in which the names appear and treats
  512.     them as if they were one big file. You can therefore break the source up
  513.     into small chunks and sub routines which are easily edited. You may find
  514.     you have lots of standard routines that you want to assemble with your
  515.     program and you can put these in one or more separate files and
  516.     assembles them with each project.
  517.  
  518.     The easiest way to avoid all this typing is to program a function key
  519.     with the command. For the previous example if you type;
  520.  
  521.     *Key 5 *SASM Start,Middle,$.Source.Routines.Subs,End Code|M
  522.  
  523.     you need only press F5 to assemble your code. This saves the repetitive
  524.     typing but as the length of a function key string is limited to 255
  525.     characters it may not be enough to accommodate a long list of
  526.     path/filenames. SAsm therefore accepts wildcards in the source file
  527.     list. If you use a common part in all the filenames for a project this
  528.     feature can often enable you to assemble all the required files with
  529.     just a single wildcarded name.
  530.  
  531.         2.5      Reconciliation of Wildcards
  532.  
  533.     It might appear that 'filtering' of wildcards in filenames is
  534.     unnecessary. If you put all the source files in sub-directory 'Source'
  535.     of the CSD then typing  *SASM  Source.*  Code  should assemble them all
  536.     into the object file Code. In real life things aren't that simple. For
  537.     example, if you want to alter one of the source files but keep the
  538.     original in case the change doesn't work (always to be advised!). You
  539.     make the alterations, change the name of the original, and assemble the
  540.     code. The only problem is that SAsm would assemble BOTH files, the
  541.     original and the new. You could avoid this by moving the original to
  542.     another directory but this soon becomes very tedious.
  543.  
  544.     SAsm has a rigid system of deciding which files to assemble. It was
  545.     designed to work with the way I name source files. If you don't like it
  546.     let me know and I will try to accommodate your preferences, but please
  547.     try my way first, it's the result of much experience and you might find
  548.     you like it.
  549.  
  550.     SAsm works it's way through the list in order. It first finds all the
  551.     names which fit the wildcarded first name in your file list.
  552.  
  553.     SAsm rejects any file that doesn't have a filetype of 'Text' (FFF),
  554.     'Data' (FFD) or SAsm Make files (&2EF). This avoids trying to load a
  555.     previous object file or other non-source file if it was saved to the
  556.     same directory. As all text editors on the Archimedes save output as
  557.     'Text' by default this should not be a problem. If you do import a file
  558.     from some other source its type will probably be 'Data' and if not you
  559.     can easily change it. If you get a 'File not found' error but can see
  560.     that the file exists it is probably because its filetype is not &FFF,
  561.     &FFD or &2EF.
  562.  
  563.     The remaining files which fit the wildcarded name are then examined and
  564.     loaded IN ALPHABETICAL ORDER. Any file which has a digit 0-9 at the end
  565.     of its name is examined and if it has the same name as the previous file
  566.     but with a different number it is ignored.
  567.  
  568.     What this means is that if you give all your source files a name ending
  569.     in a number, the file with the LOWEST number will be loaded and the rest
  570.     ignored. This works because the lowest number is also the first
  571.     alphabetically. I start out at 99 and work my way down, so each version
  572.     is progressively called Name_99, Name_98, Name_97 etc. Within the
  573.     desktop the latest version will always be the first file in the
  574.     directory viewer.
  575.  
  576.     When all the files with names which fit a wildcarded filename have been
  577.     loaded SAsm will get the next name on the list and so on until all the
  578.     names have been dealt with.
  579.  
  580.         2.6      Order of Assembly
  581.  
  582.     Remember that SAsm assembles the files which can be matched to each
  583.     wildcarded name alphabetically. To return to the previous list with
  584.     'Start, Middle and End' if you use '*' to match all of these files then
  585.     they will be assembled in the order 'End, Middle, Start' which is not
  586.     what is required. As it is normally only the first and sometimes last
  587.     files whose order is important it is fairly easy to ensure that they are
  588.     assembled in the correct order by placing an extra digit at the start of
  589.     the name. For example renaming the files 'aStart, Middle, zEnd' would
  590.     ensure that they are assembled in the correct order while retaining
  591.     meaningful names.
  592.  
  593.     Since SAsm expands and reconciles wildcarded filenames in this way it is
  594.     mot essential to use a 'make' utility to assemble a long list of source
  595.     files. In fact the additional facilities offered by the INCLUDE
  596.     directive make this even simpler.
  597.  
  598.         2.7      Length of Source Files
  599.  
  600.     Because SAsm loads all the files into memory at once in might seem that
  601.     the total length of these files could not exceed the usual 640K (or
  602.     whatever you have set 'Next Slot' to) which is available as a Task. In
  603.     fact this is not the case. As SAsm loads each file it removes all the
  604.     spare spaces and assembler comments. If, like me, you indent every line
  605.     and use lots of comments you will probably find your source files shrink
  606.     to about 60% of their original size. Even allowing for the memory
  607.     required for variables, the assembler commands etc. you should find that
  608.     SAsm can load over 1MB of source with the usual 640K slot. If this isn't
  609.     sufficient SAsm can extend the slot, but the ability to operate with
  610.     minimum memory allows SAsm to operate very fast even on a 1Mb machine.
  611.  
  612.         2.8      Line number space
  613.  
  614.     When the pre-processed code is passed to the Basic assembler it must be
  615.     given line numbers so that Basic can understand it. This means that 3
  616.     bytes must be added to the start of each line. If there is not enough
  617.     room for this SAsm will attempt to relocate the file in memory. This is
  618.     unlikely to happen unless you have more than about 10,000 lines.
  619.  
  620.     It is possible that there isn't enough RAM for relocation and in this
  621.     case SAsm will be unable to continue. If this happens there are two
  622.     possible solutions. The simplest is to make more RAM available. Bring up
  623.     the Task Manager window on the desktop and increase the size of the
  624.     'Next Task' allocation. On a 1Mb machine you may need to 'kill off' some
  625.     tasks to be able to do this. If you cannot make more RAM available you
  626.     will need to reduce the number of lines in your source file. There is no
  627.     point in removing comments, column indents etc. because by the time this
  628.     error occurs they will all have been stripped by SAsm anyway. However
  629.     each line removed saves only three bytes so you will need to remove a
  630.     lot of them to make any real difference.
  631.  
  632.         2.9      A short demonstration
  633.  
  634.     Copy the file SAsm and the complete 'Example' directory to a blank disc
  635.     in drive 0. Now press F12 to leave the desktop or CTRL-F12 to open a
  636.     Task Window and type 'MOUNT :0' at the OS '*' prompt. To assemble the
  637.     demonstration program type;
  638.  
  639.             SASM  Example.H*  Hello
  640.  
  641.     The disc drive will start and after the SAsm copyright line you should
  642.     see the messages;
  643.  
  644.             Loading Source Files:
  645.             Example.Hello_A
  646.             Example.Hello_B
  647.             Example.Hello_C_50
  648.             Pre-processing completed - starting assembly
  649.             Pass 1
  650.             Pass 2
  651.             0 Errors
  652.             Code &xx bytes - Saved as 'Hello'
  653.  
  654.     You will find that a new file 'Hello' has appeared on the disc. To run
  655.     this program, which just displays a couple of messages, type 'Hello'.
  656.  
  657.     If you examine the contents of the directory Examples you will find that
  658.     as well as  Hello_A, Hello_B and Hello_C_50 (and several other files)
  659.     there is Hello_C_52. Since this file has a higher number than Hello_C_50
  660.     it was ignored.
  661.  
  662.     Now repeat the exercise but hold down the SHIFT key when you press
  663.     RETURN after entering the SAsm command line as previously. Everything
  664.     will seem as before but this time when you type *Hello to RUN the Object
  665.     code some of the messages will be different. This is a simple example of
  666.     Conditional Assembly, some of the code being changed if the SHIFT key is
  667.     held down during asssembly.
  668.  
  669.     I suggest that you load these three files into Edit and examine them.
  670.     They are not a good example of compact or well written code but they do
  671.     illustrate the layout of a multiple SAsm source file. You will notice
  672.     the use of the Conditional Assembly section which produces the two
  673.     different versions. Note also that branch instructions can be used to a
  674.     label in another file demonstrating that labels are global.
  675.  
  676.     You will also see the use of a Macro Function 'print_string'. This would
  677.     be more efficiently coded using OS_Write0 but it illustrates how Macros
  678.     Functions are written and used.
  679.  
  680.     The files 'Local' and 'Immed' are examples to illustrate the use of
  681.     local labels, SAsm's simplified 2nd operand instructions and Expanded
  682.     Macro's. These may be assembled and examined in a similar maner.
  683.  
  684.                             The Source File
  685.                             ===============
  686.  
  687.         3.1      Source file Syntax
  688.  
  689.     I will assume that the reader is familiar with the Basic Assembler.
  690.     Reference will be made to it and attention drawn to differences between
  691.     it and SAsm where they occur. Although the syntax used by SAsm is
  692.     similar to the Basic Assembler this applies only to the actual assembly
  693.     language itself. You can forget about square brackets, OPT, P%, O% and
  694.     all the things that are necessary before you can use the Basic
  695.     Assembler. The biggest change is that the source files for SAsm are TEXT
  696.     files and must NOT have line numbers.
  697.  
  698.     One of the features of SAsm is this similarity. This isn't an accident.
  699.     Firstly SAsm actually uses the Basic assembler to do much of the work.
  700.     Secondly it was designed from the start to be a 'step up' from the Basic
  701.     assembler so even it's most advanced features will be very quickly
  702.     mastered by anyone who is familiar with the 'built-in' assembler. You
  703.     won't therefore need to spend ages learning a whole new language and you
  704.     will be able to convert your old Basic assembler programs into SAsm
  705.     format very easily and quickly. Normally this takes only a few minutes
  706.     with a straightforward program.
  707.  
  708.         3.2      General
  709.  
  710.     In the following section you will find references to various commands
  711.     being separated by spaces. If your Editor uses a Tab character (ascii 9)
  712.     to separate text into columns this character will also be accepted. This
  713.     may not be specified each time to avoid constant repetition. If you do
  714.     find that a Tab character won't work but a space will please tell me and
  715.     I'll try to make it work.
  716.  
  717.     In this Manual references are made to the 'hash' character '#' (the
  718.     character above the '3' on the main keyboard). If that appeared in your
  719.     printout as a  pound sign then your printer is set to the English
  720.     character set so you will just have to read the file as if it had
  721.     printed a hash. There are no pound characters in this Manual.
  722.  
  723.         3.3      Important Warning
  724.  
  725.     SAsm makes use of the Basic integer variables O%, P% and Q%
  726.  
  727.     O% and P% are used conventionally by the Basic assembler. Q% defines the
  728.     OPT setting during assembly. It is therefore vital that you do NOT use
  729.     or manipulate any of these variables unless you are absolutely sure of
  730.     what you are doing.
  731.  
  732.     Similarly the upper case names ADDR, TYPE, OSET and SIZE are reserved
  733.     words and must not be used as Basic variables.
  734.  
  735.         3.4      Warnings and Errors
  736.  
  737.     In the following sections reference will be made to Warnings, Errors and
  738.     Fatal Errors.
  739.  
  740.     Warnings are issued if SAsm finds you have omitted or wrongly placed a
  741.     directive. The code will still be assembled and saved. Warnings will not
  742.     be written to the Error file.
  743.  
  744.     Errors are faults from which SAsm can recover but which make the code
  745.     useless. Unlike the Basic assembler SAsm will try to continue after an
  746.     error as there may be others to report, but the assembled code will not
  747.     be viable so no Object file will be produced. However if a Listing file
  748.     was specified then this will be produced. If SAsm finds an error in the
  749.     first pass it will not attempt a second pass. You may therefore need two
  750.     attempts to correct all the errors.
  751.  
  752.     A Fatal Error is an error from which SAsm cannot recover or which is so
  753.     serious that there is no point in continuing. An error in a Macro
  754.     Function or a missing file are examples of Fatal Errors.
  755.  
  756.         3.5      Comments
  757.  
  758.     SAsm defines a comment as EVERYTHING on a line after a semi-colon ';' or
  759.     a backslash '\'. SAsm therefore conforms to the syntax used by most
  760.     assemblers which differs from the Basic assembler. The Basic assembler
  761.     is almost unique in using the colon ':' as a statement delimiter. While
  762.     SAsm still recognises ':' and allows more than one mnemonic on a line
  763.     Basic regards ':' as the end of a comment and tries to assemble anything
  764.     on the line after it even if the ':' is in a comment. For example the
  765.     following line using the Basic assembler;
  766.  
  767.     mov r0,#0 : \ mov r1,#1 : mov r2,#2
  768.  
  769.     would be assembled as  mov r0,#0  followed by  mov r2,#2  The middle
  770.     instruction would be ignored because Basic recognises the '\' and
  771.     regards it as a comment but continues assembling when it finds the ':'
  772.     later in the line. Using SAsm you would get ONLY  mov r0,#0  as
  773.     everything on the line after the '\' is a comment.
  774.  
  775.     The exception is where a semi colon (;) is not preceded by a space or a
  776.     Tab character (ascii 9). This has been done so that you can use ';' in
  777.     Basic PRINT statements to display information during assembly. When you
  778.     use ';' in a line to define a comment make sure that it is preceded by a
  779.     space or a Tab or it will cause an error.
  780.  
  781.     If you want to use more text than can be fitted into a normal comment
  782.     then see the next section.
  783.  
  784.         3.6      Descriptive text
  785.  
  786.     Sometimes you may want to put a block of descriptive text in a source
  787.     file. This is often required before a major routine to describe what it
  788.     does, entry conditions, register state on exit, etc. Normally this is
  789.     done by preceding each line of the text with a ';' or '\' but this is
  790.     rather tedious, and it's easy to miss a ';' and get assembler errors. It
  791.     is also a nuisance if you want to edit it later because you must fiddle
  792.     about with all the ;'s if you reformat it.
  793.  
  794.     Most high level compilers permit blocks of descriptive text between
  795.     certain markers and the text is ignored by the compiler. This is very
  796.     convenient and I have therefore introduced this feature into SAsm using
  797.     the curly brackets, { and }, as the delimiters.
  798.  
  799.     The { must be the first non space character on a line. Everything up to
  800.     the closing } will then be ignored. The opening { may be followed by
  801.     text on the same line or be on a line of its own.
  802.  
  803.     There is an important proviso with the closing bracket. It MUST be
  804.     preceded by a space, Tab, or be the first character on a line. If this
  805.     is not done it won't be recognised as terminating a descriptive text
  806.     insert and you'll get errors.
  807.  
  808.     The reason for this is that these two characters could be used to 'blank
  809.     out' sections of code you don't want to assemble. Instead of needing a
  810.     ';' in front of every line you can enclose the entire block between {and
  811.     }. This makes it a lot simpler to avoid assembling debugging code, etc.
  812.     when you no longer need it but to restore it when you do. If you use
  813.     this feature for that purpose then, if the requirement for a space
  814.     before the closing } did not exist, there would be a problem with LDM
  815.     and STM instructions where the register list is enclosed in the same
  816.     characters. If you make sure that you don't have a space before the
  817.     closing } with your LDM and STM instructions (not difficult) then you
  818.     can use these characters to blank out code containing those
  819.     instructions.
  820.  
  821.     To make this even easier SAsm will ignore a closing } if it is the first
  822.     character on a line, unless, of course, it is actually the terminator of
  823.     a pair of {}'s. This would be an error under all normal circumstances so
  824.     it would never exist naturally. If you do use this feature to blank out
  825.     a section of code then to bring the code back into use you need only
  826.     delete (or 'comment out') the opening {and  the closing one will be
  827.     ignored.
  828.  
  829.     Obviously if a } with a preceding space exists in the section you want
  830.     to blank out you may get errors. The most likely cause of this is a } in
  831.     a comment, but this should be easy to check.
  832.  
  833.     In normal use the only problems you are likely to encounter is if you
  834.     forget the closing } or if you don't precede it with a space. SAsm will
  835.     then wipe out all the code up to the next closing } it finds, which will
  836.     probably produce a whole series of errors, or it will quit with a Fatal
  837.     Error if it comes to the end of the file before it finds a closing }.
  838.  
  839.         3.7      Large source files
  840.  
  841.     Basic can load files in text format and this is the way that SAsm
  842.     normally operates. However Basic always insists upon numbering programs
  843.     in this format in 10's. The trouble with this is that Basic can't accept
  844.     line numbers greater than about 65,000 so this would limit the maximum
  845.     source file size to around 6500 lines. This only applies to programs in
  846.     text format, if the program is numbered in 1's instead of 10's then it
  847.     can be over 65,000 lines long which is big enough for any eventuality.
  848.  
  849.     If a file is longer than about 6500 lines it is necessary for SAsm to
  850.     tokenise it instead of leaving this to Basic. This is completely
  851.     automatic, smaller programs will be left untouched and larger ones will
  852.     be tokenised. In order to simplify the SAsm code and to make the
  853.     operation as fast as possible this routine is not nearly as
  854.     comprehensive as the system used by basic itself. This is not normally a
  855.     problem as most of the Basic keywords would never be used in an
  856.     assembler source file. All of the graphics commands and many others have
  857.     been omitted and will produce errors if they are used.
  858.  
  859.     There is a possible conflict between the operators AND, EOR and OR and
  860.     assembler mnemonics AND, EOR and ORR. In theory the SAsm tokeniser can
  861.     distinguish between these when used as mnemonics or operators but
  862.     circumstances could exist where it could become confused. Obviously this
  863.     can't happen if the mnemonics are written in lower case. In fact with
  864.     larger programs you are advised to use lower case for ALL mnemonics as
  865.     this makes the tokenising faster.
  866.  
  867.     There is also room for confusion if you use variables with names that
  868.     include Basic keywords. Basic itself will always recognist 'theORy' as a
  869.     variable but the SAsm tokeniser might, under some circumstances, try to
  870.     tokenise the 'OR'. With well written source code this shouldn't be a
  871.     problem as normally variables have lower case letters or use only single
  872.     capitals as word delimiters but you should be aware of the possibility
  873.     of problems.
  874.  
  875.         3.8      Basic keywords accepted
  876.  
  877.     These are the only Basic keywords that can be used in an SAsm source
  878.     file longer than 6500 lines. There is no reason why others can't be
  879.     added, I just couldn't think of any reason to include them. If you do
  880.     have a real need then please tell me.
  881.  
  882.     ABS, AND, ASC, CALL, CASE, DATA, DEF, DIV, ELSE, ENDCASE, ENDIF,
  883.     ENDPROC, ENDWHILE, EOR, EVAL, FALSE, FN, FOR, GET, IF, INKEY, INSTR,
  884.     LEFT$, LOCAL, MID$, MOD, NEXT, NOT, OF, ON, OR, OTHERWISE, PRINT, PROC,
  885.     READ, REM, REPEAT, RESTORE, RIGHT$, SPC, STEP, STR$, STRING$, SYS, THEN,
  886.     TO, TRUE, UNTIL, VAL, WHEN, WHILE
  887.  
  888.         3.9      Directives
  889.  
  890.     You can include Directives in your source, some are necessary for the
  891.     proper operation of SAsm. A line where the first character is '#' is a
  892.     directive. If SAsm doesn't recognise what follows the '#' it assumes it
  893.     is a Basic statement and the line after the '#' will be passed to Basic.
  894.  
  895.     You can use SAsm without any preliminary directives in the source file.
  896.     Unlike the Basic assembler you can begin writing code straight away. If
  897.     you do this SAsm will start assembling the code to run from '0000'. This
  898.     doesn't matter as SAsm will produce position independent code unless you
  899.     have included specific references to addresses within your source.
  900.  
  901.     The '#' character can have spaces before and after it to improve
  902.     legibility if you wish, they will be ignored, but it MUST be the first
  903.     non-space character on a line. Directives should be the only item on the
  904.     line although you may follow them with comments.
  905.  
  906.     All directives are case insensitive. In the following pages they are
  907.     normally shown in upper case for clarity, but you may use lower case if
  908.     you prefer. Where a directive is to be passed to Basic its case and
  909.     syntax must conform to that required by Basic. Where a comment is
  910.     included in a directive which is to be passed to Basic it can still be
  911.     preceded by ';' or '\' rather than REM, and this is actually preferred.
  912.  
  913.     There must be a space after a directive where it is followed by
  914.     parameters.
  915.  
  916.         3.10     Directives and Basic variables
  917.  
  918.     Because SAsm passes unrecognised directives to Basic this could create
  919.     difficulties if you use any of the SAsm directives as Basic variables.
  920.     This will not of itself cause problems, for example, there is no reason
  921.     why you could not have a register called 'org'. However you should be
  922.     careful how you define such items, eg. using -
  923.  
  924.             # include = 7
  925.  
  926.     to set a Basic variable 'include' to 7 would create difficulties because
  927.     SAsm would recognise 'include' as one of its own directives and try to
  928.     interpret it. However -
  929.  
  930.             # fred = 6 : include = 7
  931.  
  932.     would be OK, because SAsm wouldn't recognise 'fred'. Similarly -
  933.  
  934.             # include=7
  935.             # include%=7
  936.             # include_it = 7
  937.  
  938.     are OK because there is no space following 'include' as required by SAsm
  939.  
  940.     In general you are advised to avoid using any SAsm directives as
  941.     variables or constants because this could be a source of strange errors.
  942.     Remember also that all SAsm directives are case insensitive so this
  943.     would apply to include, INCLUDE, Include, etc.
  944.  
  945.     The upper case versions of the directives ADDR, TYPE and SIZE, are
  946.     reserved words and must not be used as variables anywhere in your code.
  947.  
  948.         3.11     #ORG
  949.  
  950.     Defines the address the code will be assembled to run at. The syntax is
  951.     # ORG <number> where <number> is a valid address. <number> is assumed to
  952.     be hex whether or not it is preceded by '&'.
  953.  
  954.     If no #ORG directive is found assembly will start at location 0 and a
  955.     warning will be displayed. The #ORG directive must appear before the
  956.     first assembler statement. If an #ORG directive is found after this a
  957.     warning will be displayed and the code will be assembled to start at
  958.     location 0. This does not apply if you have defined TYPE (see later) as
  959.     'Absolute', 'Module' or 'Utility' because these filetypes, the most
  960.     commonly used, all have 'standard' load and execution addresses.
  961.  
  962.     There must be at least one space between the word 'org' and the number
  963.     which follows. This applies to all directives.
  964.  
  965.         3.12     #SIZE
  966.  
  967.     This advises SAsm of the expected size of the code so it can reserve a
  968.     large enough buffer for it. The full syntax is #SIZE <number> where
  969.     <number> is the estimated maximum size of the code. <number> will be
  970.     assumed to be in hex whether or not it is preceded by a '&' character.
  971.     Alternatively the number can be followed by the letter K in which case
  972.     it will be assumed to be a decimal number of Kilobytes (eg. 64K). There
  973.     must not be a space between the number and the K.
  974.  
  975.     If there is no #SIZE directive before the first assembler statement a
  976.     warning is given and 64K is allocated for the code. A #SIZE directives
  977.     after the first assembler statement is ignored.
  978.  
  979.         3.13     #END
  980.  
  981.     This takes no parameters and should be placed at the end of your
  982.     assembler and before any Macro Function definitions. Anything after #END
  983.     will be passed to Basic without the need for a '#' at the beginning of
  984.     the line. When SAsm finds #END it assumes it has reached the end of the
  985.     code and everything else is Macro Function definitions
  986.  
  987.     If DEFFN is found at the start of a line indicating that a Macro
  988.     Function definition has been found before an #END directive a warning
  989.     will be given and all subsequent lines will be passed to Basic.
  990.  
  991.         3.14     #TYPE
  992.  
  993.     This defines the filetype for the assembled code. Syntax is #TYPE
  994.     <filetype> where <filetype> is a valid filetype. If <filetype> is a
  995.     number it must be in hex, though it need not be preceded by a '&'
  996.     character. If it is a textual representation of a filetype it may or may
  997.     not be in quotes, for example -
  998.  
  999.             # type FF8
  1000.             # type "Absolute"
  1001.             # type Module
  1002.  
  1003.     If you do not include #TYPE the assembled code will be saved as an
  1004.     absolute block of memory with no filetype. The most common filetypes are
  1005.     &FFC for a position independent Utility, &FF8 for an Application to be
  1006.     loaded and Run at &8000 and &FFA for a Relocatable Module.
  1007.  
  1008.     Unlike the previous examples #TYPE can appear anywhere in the source. If
  1009.     more than one #TYPE directive appears the last one will be used.
  1010.  
  1011.         3.15     #OBJ
  1012.  
  1013.     Defines the name of the Object file. The syntax is #OBJ <filename> where
  1014.     <filename> can be any valid path/filename. If you type an object name at
  1015.     the Command Line it will override any #OBJ directive. You can therefore
  1016.     include an #OBJ directive in the source but assemble a different version
  1017.     if you choose by typing an Object name at the CLI.
  1018.  
  1019.         3.16     #ERRFILE
  1020.  
  1021.     Followed by a path/file name this defines the error filename to be used.
  1022.     Again an error filename typed at the command line will override this
  1023.     directive.
  1024.  
  1025.         3.17     #LIB
  1026.  
  1027.     Defines the Library file to be used. LIB should be followed by a
  1028.     path/file name. This overrides any Library defined in the SAsm$Lib
  1029.     variable.
  1030.  
  1031.     Using #LIB without a filename will force SAsm NOT to use a Library and
  1032.     so is equivalent to the command line 'L' switch.
  1033.  
  1034.         3.18     # VERBOSE
  1035.  
  1036.     Equivalent to the command line 'V' switch to force display of names of
  1037.     macros inserted from a Library. The advantage over the 'V' command line
  1038.     switch is that it can be inserted at any point and so need not show all
  1039.     the expanded macros, only those used after the directive is used.
  1040.  
  1041.         3.19     # QUIET
  1042.  
  1043.     Switches off display of macro names. You can use this with 'verbose' as
  1044.     often as you wish to switch on and off display of expanded macro names.
  1045.  
  1046.         3.20     #INCLUDE
  1047.  
  1048.     This allows additional files to be 'included' as well as the ones
  1049.     specified at the command line. The word INCLUDE should be followed by at
  1050.     least one space and then a single filename. Unlike files loaded from the
  1051.     command line only the FIRST file which matches the required name will be
  1052.     used and no checks will be made on its filetype.
  1053.  
  1054.     The INCLUDE directive in SAsm is different from its equivalent in 'C'.
  1055.     SAsm does NOT 'insert' the file at the point at which the directive
  1056.     occurs. There is another directive INSERT which performs this function
  1057.     but this is not intended to be used for assembler source files.
  1058.  
  1059.     INCLUDE creates a 'queue' of INCLUDE filenames. When it reaches the end
  1060.     of the current file it goes to this list and loads the first name in the
  1061.     queue. When that file has been dealt with it loads the next name and so
  1062.     on until the queue is empty. If one of the 'include' files contains more
  1063.     INCLUDE directives these names are added to the END of the queue. When
  1064.     the queue is empty SAsm returns to the filenames specified at the
  1065.     command line and carries on as before.
  1066.  
  1067.     INCLUDE files can therefore have further INCLUDE directives which can
  1068.     contain their own INCLUDE's and so on.
  1069.  
  1070.     If you have a complex program which consists of lots of small pieces of
  1071.     code and sub-routines you can create a 'master' file which will contain
  1072.     the #ORG, #TYPE etc. directives and then a list of #INCLUDE directives
  1073.     to define the files required to make up the program. This operates in
  1074.     the same way as 'Make' files for other assemblers and compilers. SAsm
  1075.     will simply load each INCLUDE file in your 'primary' file in the order
  1076.     in which you have listed them. As INCLUDE files are subject to similar
  1077.     discrimination to filenames typed at the command line the 'trailing
  1078.     number suffix' system can be used to assemble the latest versions.
  1079.  
  1080.     For example, a file containing just the following would assemble the
  1081.     named files with the lowest trailing numbers in the chosen order.
  1082.  
  1083.             # type     Absolute
  1084.             # size     1000
  1085.             # include  start_*
  1086.             # include  middle_*
  1087.             # include  end_*
  1088.  
  1089.         3.21     #INSERT
  1090.  
  1091.     This is used to 'insert' the file whose name follows into the code at
  1092.     that point. Unlike INCLUDE it is inserted directly into the code at the
  1093.     point at which the directive occurs. No filetype checking is carried out
  1094.     and only the first file found with a matching name is loaded. The file
  1095.     is not inserted during preprocessing but during assembly. It therefore
  1096.     cannot contain SAsm format assembler source but would normally consist
  1097.     of data required by the code. This could be sprites, screen images,
  1098.     templates, text or any other form of data. It could even be
  1099.     pre-assembled machine code although this is not likely to be usual.
  1100.  
  1101.     To reduce disc access the assembler merely 'makes room' on the first
  1102.     pass and actually loads the data on the second. Code or data following
  1103.     an INSERT directive will automatically be double-word aligned in case
  1104.     the file is of 'odd' size.
  1105.  
  1106.         3.22     #AREA
  1107.  
  1108.     This is intended to simplify setting up Data Area consisting of a series
  1109.     of bytes or words to be accessed using LDR Rx,[<reg>,#<offset]. Normally
  1110.     this is done by reserving an area of memory in some way and defining
  1111.     each individual offset line like this -
  1112.  
  1113.             .my_data   db *80,?      ;reserve 80 bytes
  1114.             # first  = 4
  1115.             # second = 8
  1116.             # third  = 12
  1117.  
  1118.     and so on. You would then use instructions such as -
  1119.  
  1120.             ADR R8,label             ;make R8 point to the data
  1121.             LDR R4,[R8,#second]
  1122.             STR R2,[R8,#third]
  1123.             LDR R1,my_data+second    ;without using a 'pointer' register
  1124.  
  1125.     The problem with this method of setting up a data area is that every
  1126.     offset must be calculated 'by hand' and if you make a mistake the data
  1127.     can become corrupted at runtime. Also if you want to change the size of
  1128.     an item, for example, to increase a byte sized item to a word, then
  1129.     every other offset will need to be recalculated. Not only tedious but
  1130.     easily leading to mistakes.
  1131.  
  1132.     The AREA directive makes this type of data area much easier to define.
  1133.     It automatically sets the value of each offset and calculates and
  1134.     allocates the amount of space required. The syntax is very simple, but
  1135.     you will need to take careful note of exactly how it works to avoid
  1136.     errors.
  1137.  
  1138.     A data area is declared by the #AREA directive and this is followed by
  1139.     the name to be used to refer to it and the size of the first item, eg -
  1140.  
  1141.             # area  my_data  4
  1142.  
  1143.     'my_data' will then become a normal Global Label and can be addressed
  1144.     just like any other label. You can use LDR/STR instructions with it if
  1145.     you wish or ADR/ADRL to make a register point to it.
  1146.  
  1147.     The important part comes next. Following the first line you introduce a
  1148.     series of 'pointers' into the data area, defining the size of each as
  1149.     you do so. Note that unlike the normal method of doing this you define
  1150.     the SIZE of each item, not its offset from the start. To reproduce the
  1151.     previous example using the AREA directive -
  1152.  
  1153.             # area  my_data  4
  1154.                     first    4
  1155.                     second   4
  1156.                     third    4
  1157.             # ea
  1158.  
  1159.     Note that the AREA block is terminated by an #EA (End Area) directive.
  1160.  
  1161.     This will produce the same results as the previous example but it is
  1162.     much easier to set up. Instead of working out the offset of each pointer
  1163.     all you need to do is to follow its name with the size of the item that
  1164.     you want to put there. In this example each item will have four bytes
  1165.     allocated. If you wanted single bytes you would use -
  1166.  
  1167.             # area  my_data  1
  1168.                     first    1
  1169.                     second   1
  1170.                     third    1
  1171.             # ea
  1172.  
  1173.     Obviously sizes can be mixed. Note that the number in the first
  1174.     declaration line defines the size of the first item which would normally
  1175.     be accessed by -
  1176.  
  1177.             LDR R0,[<reg>]    or    LDR R0,[my_data]
  1178.  
  1179.     As this item has an offset of 0 there is no need to define one for it.
  1180.     If you really do want to always refer to the first item with an offset
  1181.     then simply set the 'size' of this item to '0' so that the pointer
  1182.     defined on the following line will have an offset of 0.
  1183.  
  1184.     If you mix the sizes of items within a data area you may need to reset
  1185.     the pointer to ensure that sections are be word aligned. This can be
  1186.     done in the normal way with an ALIGN instruction. In fact ALIGN works
  1187.     differently when used in this context but its action is the same as
  1188.     usual.
  1189.  
  1190.     To illustrate this using mixed sizes as in the previous example -
  1191.  
  1192.             # area  my_data  1
  1193.                     first    1
  1194.                     align
  1195.                     second   4
  1196.                     third    4
  1197.             # ea
  1198.  
  1199.     This will ensure that 'second' and 'third' have word aligned values.
  1200.  
  1201.     Note that this will ONLY be true if the START of the data area is word
  1202.     aligned. This will normally be the case but if in doubt use 'align' on
  1203.     the line BEFORE the #AREA directive. Similarly if you have used odd
  1204.     sizes items in your data area you should follow it with 'align' to
  1205.     ensure that any code or data which follows is word aligned.
  1206.  
  1207.     Within the confines of an AREA directive, ie. between #area and #ea,
  1208.     only the structures shown above are permitted. No assembler mnemonics or
  1209.     any other directives or statements are allowed. Items must be placed one
  1210.     per line exactly as shown. You can have comments, preceded by the usual
  1211.     ';' or '\', either following an item on the same line or on lines of
  1212.     their own. You can have blank lines if you wish.
  1213.  
  1214.     If any line in an AREA begins with a '#' character that will terminate
  1215.     the area. In fact, you don't really need an #ea directive, # on its own
  1216.     will do but you are advised to use #ea for clarity. If an AREA operation
  1217.     is terminated before the end because of an error you may get various
  1218.     error messages depending upon exactly what the cause was. You may also
  1219.     get an '#EA directive found when not in Data Area' message.
  1220.  
  1221.     At present the data in the area is not preset to any value. I may add a
  1222.     feature to do this at some time in the future.
  1223.  
  1224.         3.23     Multiple data areas
  1225.  
  1226.     You may have realised that every offset defined by the AREA directive
  1227.     becomes a Global Variable. This makes it possible to define a series of
  1228.     identical data areas and use the same offsets to access them. This would
  1229.     be particularly useful in programs which operate upon more than one set
  1230.     of data at the same time.
  1231.  
  1232.     To return to the previous example if you subsequently used -
  1233.  
  1234.             .label_2  db *40,?
  1235.  
  1236.     to reserve some space for a second area. Now -
  1237.  
  1238.             ADRL R8, label_2
  1239.             LDR R1,[R8,#second]
  1240.  
  1241.     will address an identical offset in the second area.
  1242.  
  1243.         3.24     #LISTON
  1244.  
  1245.     This will create a file which will contain an assembler listing. It may
  1246.     be followed by an 'F' which will produce a 'formatted' listing. The
  1247.     listing file will not start at the beginning of the source code but at
  1248.     the point at which the LISTON directive occurs. (See later section on
  1249.     Assembler Listing)
  1250.  
  1251.         3.25     #LISTOFF
  1252.  
  1253.     Marks the point at which the assembler listing file will cease.
  1254.  
  1255.         3.26     #LISTFILE
  1256.  
  1257.     Followed by a filename this sets the name to be used for an assembler
  1258.     listing file.
  1259.  
  1260.         3.27     #NOENHANCE
  1261.  
  1262.     Switches off the second operand enhancements (see later). Included for
  1263.     untidy programmers who insist upon using instructions like MOV 1,2.
  1264.  
  1265.         3.28     #ENHANCE
  1266.  
  1267.     Switches second operator enhancements on again. This is the default.
  1268.  
  1269.         3.29     #XREF
  1270.  
  1271.     Switches on label cross reference. Once again the advantage of this over
  1272.     the 'X' switch is that it only takes effect from the point at which it
  1273.     appears.
  1274.  
  1275.         3.30     #NOXREF
  1276.  
  1277.     Switches off label cross reference. Can be used as often as required
  1278.     with the previous command to toggle x-ref on and off.
  1279.  
  1280.     There is an obvious interaction between the 'X' command line parameter,
  1281.     the XREF directive and this directive. The x-ref will begin at the XREF
  1282.     directive unless the 'X' command line parameter is used, in which case
  1283.     it will start at the beginning of the first file. It will finish at the
  1284.     NOXREF directive if one appears, if not at the end of the last file.
  1285.  
  1286.     XREF and NOXREF can appear more than once in the files. The function
  1287.     will simply be switched on or off as they are encountered. Beware of
  1288.     leaving NOXREF directives scattered in your files. They could cause the
  1289.     x-ref to be disabled without you realising it and therefore prevent
  1290.     duplicate labels from being revealed.
  1291.  
  1292.         3.31     #XRFILE
  1293.  
  1294.     Followed by a filename this sets the name for the label x-ref file if
  1295.     this is required. If duplicate labels are saved as a file they will not
  1296.     be displayed on screen, only the total number of duplicated names found
  1297.     will be shown. If no x-ref filename directive appears the listing will
  1298.     appear only on screen. If the XRFILE directive appears without a
  1299.     following filename then the default filename of 'xr_file" will be used.
  1300.  
  1301.     When shown on screen SAsm prints a message in the form -
  1302.  
  1303.           Warning : Duplicate label '<label>' at line <line number>
  1304.  
  1305.     where <label> is the duplicated label and <line number> is the number of
  1306.     the line on which the duplicate was found. There is no need to show the
  1307.     name of the file in which the duplicate was found because this will
  1308.     already have been displayed as SAsm loaded it. However when a duplicate
  1309.     list is saved as a file these filenames don't appear and so the name of
  1310.     the file in which each duplicate was discovered will also be shown.
  1311.  
  1312.     This directive doesn't initiate the x-ref, it just ensures that if it
  1313.     is enabledr from the command line or by the XREF directive then a file
  1314.     will be created. The directive must appear before the first label in the
  1315.     file or the file will not be created until the directive does appear.
  1316.     The obvious place for it is at the start of the file so that if you do
  1317.     invoke the x-ref function at any time the file will be available.
  1318.  
  1319.         3.32     #LABELFILE
  1320.  
  1321.     The 'N' command line switch has already been described. This switch will
  1322.     produce a sorted list on screen of all the global labels that SAsm finds
  1323.     in the source files. Obviously this list can be very long and so the
  1324.     LABELFILE directive allows the label list to be sent to a file.
  1325.  
  1326.     As with other filename directives it should be followed by at least one
  1327.     space and then a path/file name. If the directive appears a following
  1328.     name then the default name 'LabelFile' will be used.
  1329.  
  1330.     This directive does not initiate a label listing, it just ensures that
  1331.     if you do want one it will go to a file and not to screen. You can place
  1332.     it in your source and if you do need a label listing at any time it will
  1333.     be in the form of a file. If the list is to be sent to a file the
  1334.     message-
  1335.  
  1336.             Creating label list file '<filename>'
  1337.  
  1338.     will be displayed and the label list will not be displayed on screen.
  1339.  
  1340.     As with screen display of labels they are arranged one per line in
  1341.     alphabetical order. The 'sorting' of names is case sensitive so 'Exit'
  1342.     will come before 'exit' and 'aAdvark' before 'aadvark'.
  1343.  
  1344.     As well as the 'N' switch there is a 'shortcut' which will produce a
  1345.     label list. If you hold down both SHIFT keys as you press RETURN when
  1346.     you type the SAsm command line this will initiate a label list just as
  1347.     if you had used the 'N' switch. As usual whether the list is to screen
  1348.     or a file will depend upon whether you have included the LABELFILE
  1349.     directive or not.
  1350.  
  1351.         3.33     #SWION
  1352.  
  1353.     This switches on processing of SWI names. Normally if you wish to use
  1354.     the textual version of a SWI it must be enclosed in double quotes, eg
  1355.  
  1356.             SWI "OS_WriteC"
  1357.  
  1358.     Once this command or the command line 'S' switch has been used there is
  1359.     no need for the quotes, so you can simply use -
  1360.  
  1361.             SWI OS_WriteC
  1362.  
  1363.     It will also interpret any SWI number beginning with a '0' as a hex
  1364.     number, so that 'SWI 020' would be number 20 hex, 32 decimal, and not 20
  1365.     decimal.
  1366.  
  1367.     There are potential problems with this system which is why it is not
  1368.     made the default but must be deliberately activated. SAsm assumes that
  1369.     the parameter following a SWI instruction is a string if the first
  1370.     character is an upper case letter (A-Z). This should work because the
  1371.     names of all Acorn SWI's begin with a capital letter. So far as I am
  1372.     aware this also applies to all third-party modules. If a name begins
  1373.     with a lower case letter or a non-standard character such as an
  1374.     underscore it will not be recognised. The more likely problem would
  1375.     arise if you define constants for some SWI numbers. All is well if you
  1376.     give them names beginning with a lower case letter but if a name begins
  1377.     with a capital letter SAsm would regard it as a text version of a SWI
  1378.     and this would again produce an error. I have therefore decided that it
  1379.     is safer to make the user deliberately switch this on so that a program
  1380.     'converted' from 'raw' Basic assembler should (!) always work without
  1381.     error. The user can then modify the source file and use this feature at
  1382.     his/her discretion.
  1383.  
  1384.     In general you should not experience difficulties if you ensure that if
  1385.     you do use a SWI name which begins with a lower case letter you enclose
  1386.     its name in quotes and if you define constants for SWI numbers you make
  1387.     sure that their name does not begin with a capital letter.
  1388.  
  1389.         3.34     #SWIOFF
  1390.  
  1391.     Switches off SWI name processing described above.
  1392.  
  1393.         3.35     #CLI
  1394.  
  1395.     Anything on the line after this directive will be passed DIRECTLY to the
  1396.     operating system Command Line Interpreter. It is equivalent to a '*'
  1397.     command used in a Basic program. It is not like the Basic 'OSCLI'
  1398.     command as no substitution is carried out first. You should not put
  1399.     comments on the line after a #CLI directive, it won't bother SAsm but it
  1400.     might confuse the OS.
  1401.  
  1402.         3.36     Labels and Variables
  1403.  
  1404.     A label in SAsm is no different from any other variable. You must be
  1405.     careful not to use the same name for a label as a variable. I advise you
  1406.     use Basic Integer Variables for variables to minimise the possibility of
  1407.     problems. You should try to decide upon a 'system' so you don't
  1408.     inadvertently cause a conflict. I use only lower case letters in labels,
  1409.     but if I wish to create a variable I use an upper case character as the
  1410.     first letter of its name. This makes it obvious to me when reading code
  1411.     or comments whether I am referring to a variable or a label.
  1412.  
  1413.     Obviously variables will not be shown in the Label List, so if your code
  1414.     misbehaves and shows all the symptoms of a duplicate label but x-ref
  1415.     can't find it, examine your variables.
  1416.  
  1417.         3.37     Defining Registers
  1418.  
  1419.     To simplify writing code it is normal to give the C.P.U. registers names
  1420.     and define various other constants. In Basic this is done by assigning
  1421.     the chosen name a number using the syntax  <name>=<number>. The same
  1422.     method is used with SAsm except that you must precede your definitions
  1423.     with '#'. For example, to define register 5 as 'count' and register 6 as
  1424.     'flag'
  1425.  
  1426.             # count = 5
  1427.             # flag = 6
  1428.  
  1429.     or alternatively
  1430.  
  1431.             # count=5:flag=6
  1432.  
  1433.     R13,R14 and R15 are pre-defined as 'sp', 'link' and 'pc' in upper and
  1434.     lower case. All registers are pre defined as their equivalent 'r' and
  1435.     'R' numbers. Basic doesn't recognise a number like 'r4' as meaning
  1436.     register number 4 except when it is an assembler operand. If you try to
  1437.     pass 'r4' as a parameter an error would be generated. With SAsm you can
  1438.     use r0-r15 or R0-R15 as they have been pre defined.
  1439.  
  1440.     You can use this method to define SWI's, offsets in a data area, in fact
  1441.     anything you wish. Since these are normal Basic variables you can use
  1442.     integer and string variables if required.
  1443.  
  1444.         3.38     Defining constants
  1445.  
  1446.     Most code begins with a long list of constant definitions. For example,
  1447.     you will probably want to give names to registers, use variables to
  1448.     define the size of data areas and buffers, string variables for program
  1449.     version and support file names etc. This could, of course, be done as
  1450.     described above with a series of '#' statements but it is more elegant
  1451.     to use a standard Basic procedure.
  1452.  
  1453.     Remember that everything after the #END statement is just normal Basic.
  1454.     Therefore you can write a perfectly ordinary procedure after #END to
  1455.     define all your constants. Then, at the start of the first file, before
  1456.     the first assembler statement, put a call to this procedure, eg.
  1457.  
  1458.             # PROCdefine
  1459.  
  1460.     This will call the procedure and define all your constants.
  1461.  
  1462.     One thing you should be aware of is that everything from the start of
  1463.     the file up to the END directive is within the assembler loop. As it is
  1464.     a two pass assembler all constant declarations and procedures are
  1465.     enacted before each assembler pass. In the previous example PROCdefine
  1466.     would also be called before the second pass. This does not matter unless
  1467.     you have deliberately altered a variable at some stage in the program.
  1468.     If you have done so you should be aware that it will be reset before the
  1469.     second pass. If you particularly want a variable to be set only during
  1470.     the first pass then you could check the state if the variable PASS to
  1471.     ensure that the variable is not reset during the second pass.
  1472.  
  1473.         3.39     Conditional Assembly
  1474.  
  1475.     This works as with the Basic assembler, normally using IF THEN, (ELSE),
  1476.     ENDIF.  If you are unfamiliar with this please read the 'Tutorial' file.
  1477.     With SAsm there is no need to bother with assembler brackets, etc. Just
  1478.     put '#' in front of the lines which form the conditional block.
  1479.  
  1480.             # IF <condition> THEN
  1481.                .........            ; some code
  1482.                .........
  1483.                .........
  1484.             # ELSE
  1485.                .........            ; the alternative code
  1486.                .........
  1487.                .........
  1488.             # ENDIF
  1489.  
  1490.     Don't forget the 'THEN' at the end of the 'IF' line. The 'ELSE' section
  1491.     is of course optional.
  1492.  
  1493.     If an error occurs in a conditional section you may find subsequent
  1494.     'ELSE found without IF' or 'ENDIF found without IF' errors occurring.
  1495.     This is not significant, it just means the assembler has 'forgotten' it
  1496.     was in a conditional section when the original error was discovered.
  1497.  
  1498.     There is no reason why you cannot use other methods for more complex
  1499.     multiple choice options. For example the CASE statement could be used.
  1500.  
  1501.             # CASE <condition> OF
  1502.             # WHEN <condition 1>
  1503.                .........            ; some code
  1504.                .........
  1505.                .........
  1506.             # WHEN <condition 2>
  1507.                .........            ; some code
  1508.                .........
  1509.                .........
  1510.             # WHEN <condition 3>
  1511.                .........            ; some code
  1512.                .........
  1513.                .........
  1514.             # OTHERWISE
  1515.                .........            ; the alternative code
  1516.                .........
  1517.                .........
  1518.             # ENDCASE
  1519.  
  1520.     The OTHERWISE section is, of course, optional.
  1521.  
  1522.         3.40     LDM and STM instructions with Writeback
  1523.  
  1524.     LDM/STM are mainly used for stack management although they can be used
  1525.     for multiple register transfer to and from memory. Usually they will be
  1526.     used with Writeback in the form -
  1527.  
  1528.             LDMIA <reg> !,{<list>}
  1529.  
  1530.     With the Basic assembler it is necessary to leave a space between <reg>
  1531.     and the '!' character if a name has been assigned to the stack pointer
  1532.     register. Otherwise the Basic assembler isn't bright enough to interpret
  1533.     the instruction correctly and assumes that you are using some sort of
  1534.     contorted indirection to define the pointer register and tries to
  1535.     interpret the '!' as an indirection operator. This means that something
  1536.     like -
  1537.  
  1538.             STMIA sp !,{pc ,link}
  1539.  
  1540.     is required with a space before the '!'
  1541.  
  1542.     On the assumption that you are probably not doing anything like this
  1543.     SAsm permits the use of the '!' character without an intervening space
  1544.     so that the more natural -
  1545.  
  1546.             STMIA sp!,{pc ,link}
  1547.  
  1548.     is permitted.
  1549.  
  1550.         3.41     Assembly Loops
  1551.  
  1552.     With the Basic assembler it is common to use FOR-NEXT loops to fill an
  1553.     area of memory, eg.
  1554.  
  1555.             ]                   :REM exit assembler
  1556.             FOR I%=0 TO 255
  1557.             [ OPT PASS
  1558.             EQUB &FF            ;fill 256 bytes with &FF
  1559.             ]
  1560.             NEXT
  1561.             [ OPT PASS          ;back to assembler again
  1562.  
  1563.     You could still use this method with SAsm if you wish but it is simpler
  1564.  
  1565.             ........            ;normal code
  1566.             # FOR I%=0 TO 255
  1567.             EQUB &FF
  1568.             # NEXT
  1569.             ........            ;normal code again
  1570.  
  1571.     In fact SAsm has a much better way to assign and fill an area of memory
  1572.     using the DB mnemonic.
  1573.  
  1574.         3.42     The OSET variable
  1575.  
  1576.     With the Basic assembler you may want to 'poke' values into a data area
  1577.     after assembly, or you may wish to modify data in some way. As you would
  1578.     be aware of the address of the start of your code in memory, the offset
  1579.     used by the O% variable, and you will presumably have inserted a label
  1580.     at some convenient point as a marker, you would be able to calculate the
  1581.     exact location you wish to change. With SAsm the actual address of a
  1582.     location is hidden from the user so the variable OSET is set to give you
  1583.     a 'base' to use for these purposes.
  1584.  
  1585.     During assembly OSET is set such that OSET+<label> where <label> is any
  1586.     normal global label will point to the location IN MEMORY of <label>. For
  1587.     example, to 'poke' the string 'version$' into the location defined by
  1588.     the label 'version' you would use -
  1589.  
  1590.             # $(OSET+version) = version$
  1591.  
  1592.     You can, of course, add an offset to <label> if you wish. For example,
  1593.     to 'blank' 256 bytes from the label 'buffer' you could use
  1594.  
  1595.             # FOR I%=buffer TO buffer+255
  1596.             # ?(OSET+I%)=0
  1597.             # NEXT
  1598.  
  1599.     Both of these examples are contrived and the same results could be more
  1600.     efficiently be produced by other means. The most likely use for the OSET
  1601.     variable would be to disguise particular data in your code in some way.
  1602.     This makes it possible to compose text in plain language when writing
  1603.     the code but garble it after assembly.
  1604.  
  1605.         3.43     Assembly Listing
  1606.  
  1607.     SAsm does not normally produce an assembly listing. Not only would this
  1608.     obscure any Error or Warning messages it also slows down assembly.
  1609.  
  1610.     It can be useful to to see exactly what has happened to the source code
  1611.     after pre-processing. For example, to check that a macro has been
  1612.     expanded or a complex DB statement properly interpreted. SAsm has no
  1613.     provision for displaying an assembler listing on screen. This could be
  1614.     done by altering the OPT setting, directly manipulating the variable Q%,
  1615.     and programmers experienced in using the Basic assembler will be able to
  1616.     do this. This is not normally to be advised. Instead SAsm allows an
  1617.     assembler listing file to be created. This can be loaded into a text
  1618.     editor and examined at leisure. Two different layouts are available,
  1619.     Standard and Formatted.
  1620.  
  1621.     The Standard format produces a 'compact' listing with no spare spaces or
  1622.     column indenting. This makes it rather cramped and difficult to read but
  1623.     less than half the size of a Formatted file. This may be best if you are
  1624.     using floppy discs and require a listing of all or a large part of your
  1625.     code.
  1626.  
  1627.     The Formatted listing produces a file with labels in the left hand
  1628.     column. Mnemonics are indented by 24 spaces and operands indented by a
  1629.     further eight places. This makes the code much easier to read but it
  1630.     will probably double or treble the size of the file.
  1631.  
  1632.     In both cases only lines containing assembler are reproduced and all
  1633.     comments are stripped. All other lines, including blank lines, are
  1634.     ignored. There is therefore no direct line-to-line correlation with the
  1635.     original source file(s). (I'll include a switch to change this later).
  1636.  
  1637.     The listing file is written one line at a time so the operation is
  1638.     slower than other SAsm file operations. Using a hard disc or RAM disc
  1639.     even a large file will only take one or two second but with a floppy
  1640.     disc it could take several. The message 'Creating listing file' will
  1641.     appear at the start of the operation and it's end is signalled when the
  1642.     message 'Pre processing completed - starting assembly' appears.
  1643.  
  1644.         3.44     Creating a listing file
  1645.  
  1646.     Listing files are created by typing the parameters at the command line,
  1647.     by inserting suitable directives, or by a combination of both methods.
  1648.  
  1649.     The command line parameter is 'A' (for Assembler). This should be
  1650.     followed by the filename required. Remember that whatever follows the
  1651.     'A' parameter will become the filename so if, for example, you also want
  1652.     a label cross-reference and type an 'X' after the 'A' you won't get a
  1653.     x-ref but you will get a listing file called 'X'.
  1654.  
  1655.     If you don't follow the 'A' with a filename and it is the last parameter
  1656.     typed a default name of 'ListFile' will be used and the file will be
  1657.     created in the Currently Selected Directory. Assuming no other
  1658.     directives are used this will result in a listing file consisting of all
  1659.     the source files. If you have used the 'F' parameter this will be a
  1660.     Formatted file, if not it will be compact.
  1661.  
  1662.         3.45     Listing file directives
  1663.  
  1664.     Assembler listing files can be produced instead of or in addition to
  1665.     Object and/or Error files.
  1666.  
  1667.     There are three directives relating to listing files, LISTON, LISTOFF
  1668.     and LISTFILE. These are used to define the start point in the code from
  1669.     which a listing file will be created, the end point at which the listing
  1670.     file will finish, and the name to be given to the file.
  1671.  
  1672.     LISTFILE is followed by the path/name you wish to assign to the file. As
  1673.     the listing file is not created until all source files have been loaded
  1674.     it does not matter where in the source the LISTFILE directive appears.
  1675.     If there is more than one LISTFILE directive the last one found will
  1676.     apply. Any filename typed at the command line will override a directive
  1677.     filename and in this case a message to this effect will be displayed.
  1678.  
  1679.     By default a listing file begins with the first assembler statement and
  1680.     finish with the END directive. Most of the time you will only need to
  1681.     see a small part of the code and so LISTON and LISTOFF are used to mark
  1682.     the beginning and end of the file.
  1683.  
  1684.     If LISTON is followed by an 'F' or if an 'F' parameter was used at the
  1685.     command line then the file will be formatted.
  1686.  
  1687.     Note that LISTFILE of itself does not produce a listing file, it merely
  1688.     defines the filename which will be used if a file is required.
  1689.  
  1690.         3.46     Scope of a listing file
  1691.  
  1692.     You should understand how these commands and directives work to ensure
  1693.     that you get a listing of the required section of code. By default the
  1694.     listing file starts with the first assembler statement and stops with
  1695.      the #END directive. These start and end points are modified each time
  1696.     SAsm encounters a LISTON or LISTOFF directive. If there is more than one
  1697.     of either or both then the last one encountered will be the one which
  1698.     applies. It is therefore possible if a LISTON directive is encountered
  1699.     after the last LISTOFF directive for the required start of the listing
  1700.     to apparently be after the end. In this case SAsm will not be able to
  1701.     produce the file and will simply display an error message.
  1702.  
  1703.     If there is no LISTON directive the listing file will begin at the first
  1704.     assembler directive and continue until the LISTOFF directive. If there
  1705.     is no LISTOFF directive it will begin at the LISTON directive and
  1706.     continue until the END directive.
  1707.  
  1708.                              Labels
  1709.                              ======
  1710.         4.1      Global Labels
  1711.  
  1712.     All labels and variables are common throughout all files. You must
  1713.     remember this or strange things can happen. With SAsm you don't need to
  1714.     declare labels external, they are ALWAYS global.
  1715.  
  1716.     Adding the parameter 'X' to the command line invokes the label cross
  1717.     reference. This checks all labels and reports multiple definitions. For
  1718.     reasons already explained multiple definitions of a label are classed as
  1719.     Warnings only and not Errors. If you use labels like 'loop' or 'bak' to
  1720.     form short loops you will need to visually check the list of duplicates
  1721.     for 'foreign' names.
  1722.  
  1723.         4.2      Local Labels
  1724.  
  1725.     Since it is tedious to invent names for all the labels you need to make
  1726.     short jumps and loops a system of Local Labels has been included. These
  1727.     are defined in the same way as normal labels, ie. by preceding the label
  1728.     with a full stop. Local labels MUST be defined at the start of the line,
  1729.     which is good practice anyway, and consist of a two digit decimal number
  1730.     00-99.
  1731.  
  1732.     You are advised to read the following section carefully and ensure that
  1733.     you understand exactly how this system operates. It's perfectly
  1734.     straightforward and easy to use but if you don't use it properly you
  1735.     will get repeated errors or branches to the wrong destination.
  1736.  
  1737.         4.3      Local label scope
  1738.  
  1739.     You start each set of local labels with label '00'  When SAsm finds
  1740.     label 00 it forgets all previous local labels. You can therefore use the
  1741.     numbers 00 to 99 repeatedly and each label will only apply within its
  1742.     own section. When you start a new section of code or sub-routine make
  1743.     the first label 00  You can use label 00 even where a label is not
  1744.     actually needed to ensure that the scope of the current set of local
  1745.     labels is ended. Normally a reference to a local label will only apply
  1746.     to the label within that 'set', but you can refer to the previous and
  1747.     next sets and this will be described later
  1748.  
  1749.     Local labels can ONLY be used with Branch (or BL) and as the second
  1750.     operand in LDR and STR instructions, with or without conditions, and
  1751.     with the ADR or ADRL pseudo-opcode. They cannot be used within Macro
  1752.     Functions but they can be used in Expanded macros. You will soon find
  1753.     that you will use local labels for all the loops and short jumps in a
  1754.     section, using meaningful labels where appropriate. This makes the code
  1755.     much easier to follow because the main labels which define entry points
  1756.     and complete routines stand out.
  1757.  
  1758.         4.4      Using local lables
  1759.  
  1760.     There are some restrictions upon local labels which you should be aware
  1761.     of. They cannot be used as the operand of some instructions or psuedo
  1762.     opcodes. They can be used with all branch instructions, ADR, ADRL, LDR
  1763.     and STR. They cannot be passed as parameters to functions or expanded
  1764.     macros. They cannot be used in Macro Functions or anywhere after the END
  1765.     directive.
  1766.  
  1767.     A local label only has a meaningful value when used in the correct
  1768.     manner within its own scope. If you define labels 00, 01 and 02 in one
  1769.     section an attempt to branch to 03 within that section will produce an
  1770.     error, not a branch to 03 in the previous or next section.
  1771.  
  1772.     Although there are 100 individual labels available in any section this
  1773.     is far more than you should ever need. I find it best to divide each set
  1774.     into sub-sections so that each loop or sub-sub-routine has its own
  1775.     sub-set of labels. The first uses 00-09, the next 10-19, then 20-29 etc.
  1776.     This makes the code easier to read and ensures that there are spare
  1777.     labels in each sub-set if I need to add extra code later. You don't need
  1778.     to define the labels in any particular order provided you start at 00,
  1779.     it just looks neater and makes it easier to follow the flow of the code
  1780.     because a branch to a low number will go back towards the beginning of
  1781.     the section and to a high number forward to the end.
  1782.  
  1783.     Local labels are not checked by the x-ref routine. If you duplicate a
  1784.     local label within its set you will get the same problems as with any
  1785.     other duplicate label. This should not be a problem in practice,
  1786.     especially if you define labels in numerical order, because each set of
  1787.     labels will normally fit within a couple of 'screens' of code and
  1788.     duplicate or out of sequence labels can be plainly seen.
  1789.  
  1790.     The maximum number of sets of local labels is over 2700, which is enough
  1791.     for any eventuality.
  1792.  
  1793.         4.5      Previous or Next sets of labels
  1794.  
  1795.     It is possible to refer to a local label in the previous or next 'set'.
  1796.     Normally a reference to a local label would only apply to the label
  1797.     within its own set, but by preceding the label number with a '>' or '<'
  1798.     character you can refer to the next or previous set respectively. There
  1799.     must not be a space between the '>' or '<' and the first digit of the
  1800.     label number.
  1801.  
  1802.     Obviously for this to work the label must exist in the set referred to
  1803.     or you will get an error
  1804.  
  1805.         4.6      Example
  1806.  
  1807.     Any Branch instruction will only reach back to the last 00 label and
  1808.     forward to (but not including) the next, except where the '>' and '<'
  1809.     modifiers are used. There can be no overlapping of local label sets. The
  1810.     following example should make this clear.
  1811.  
  1812.             .00    ........ ; some code
  1813.                    ........
  1814.             .01    ........
  1815.                    ........
  1816.                    ........
  1817.             .02    BNE 01   ; This will branch BACK to the last 01
  1818.                    ........
  1819.                    ........
  1820.             .00    ........ ; This starts a new section of labels
  1821.                    BGT 01       ; Branch FORWARD to 01 in this section
  1822.                    ........
  1823.                    ........
  1824.             .01    ........
  1825.                    BEQ 02       ; This will produce an error as 02 is
  1826.                    ........     ; not defined in this section
  1827.                    ........
  1828.                    BLT 00       ; Branch BACK to the last 00
  1829.             .00    ........ ; Start another section
  1830.                    ........
  1831.                    ADR r1,00    ; Put address of the LAST 00 in R1
  1832.                    ADR r2,01    ; put address of the NEXT 01 in R2
  1833.                    ........
  1834.             .01    ........
  1835.  
  1836.         4.7      Examples with prev/next set
  1837.  
  1838.     You can refer to a local label in the next or previous set by using the
  1839.     '>' and '<' characters as modifiers. For example -
  1840.  
  1841.             ADR r1,>01
  1842.  
  1843.     would make r1 point to '01' in the NEXT set of local labels, and -
  1844.  
  1845.             ADR r1,<04
  1846.  
  1847.     would make it point to '04' in the PREVIOUS set.
  1848.  
  1849.     Modifiers can be employed wherever a local label can be used. Note that
  1850.     there must not be a space between the prefix and the label number. It is
  1851.     particularly useful for separating data and code. You can use a
  1852.     different set of labels for each to minimise the chance of errors but,
  1853.     providing the data immediately precedes or follows the code which uses
  1854.     it, it can still be accessed.
  1855.  
  1856.     Although modifiers can be used within expanded macros they must only
  1857.     refer to label sets defined within that macro. They cannot be used to
  1858.     refer to a label set in code before or after the macro itself.
  1859.  
  1860.         4.8      Forward branch to 00
  1861.  
  1862.     This was previously a source of many errors as experienced programmers
  1863.     are used to being able to branch forward to a label, especially if they
  1864.     can actually see it in front of them on the screen.
  1865.  
  1866.     Consider this short piece of code;
  1867.  
  1868.                     cmp r0,#32
  1869.                     bne 00
  1870.                     ........        ;code to be skipped if r0 not 32
  1871.                     ........
  1872.             .00     ........        ;rest of code
  1873.  
  1874.     This won't work. The branch would go BACKWARDS to the last 00. To branch
  1875.     forward to '00'. However, it is now possible to achieve the desired
  1876.     object by using the '>' prefix, for example -
  1877.  
  1878.             bne >00
  1879.  
  1880.     would work properly.
  1881.  
  1882.         4.9      Problems with local labels
  1883.  
  1884.     The most common problems occur when users do not understand the scope of
  1885.     a local label. This has been covered fully and is very simple, but it
  1886.     still seems to cause problems, so check this first.
  1887.  
  1888.     Remember that a local label must be defined at the beginning of the
  1889.     line. With the Basic assembler you could use -
  1890.  
  1891.             .label_1 mov r0,#4 : mov r1,#5 : .label_2
  1892.  
  1893.     This will still work with SAsm but NOT if the second label is a local
  1894.     label. From the earlier example you can see that -
  1895.  
  1896.             .90 : mov r0,#4 : mov r1,#5 : .00
  1897.  
  1898.     wouldn't work. The two labels must be on separate lines.
  1899.  
  1900.                             Special Features
  1901.                             ================
  1902.         5.1      Enhanced 2nd operand
  1903.  
  1904.     This operates on the second operand of instructions CMP, MOV, TST and
  1905.     TEQ. It will work whether or not the instruction is conditional but it
  1906.     can NOT be used with CMN or MVN (yet!). For it to work there must be a
  1907.     space between the opcode and the first operand.
  1908.  
  1909.     The aim is to make it easier when the second operand is an immediate
  1910.     value rather than another register. The Basic assembler requires the
  1911.     second operand to have a leading '#' character for it to be recognised
  1912.     as an immediate value. SAsm will accept this but will also recognise
  1913.     most immediate numeric operands.
  1914.  
  1915.     If the second operand begins with a digit 0-9, an '&', a '%' or is
  1916.     enclosed in double quotes SAsm will assume that it is an immediate value
  1917.     whether or not it is preceded by '#'. There is also no need to use the
  1918.     Basic 'ASC' prefix if a character is enclosed in double quotation marks.
  1919.     For example -
  1920.  
  1921.               SAsm                 Basic Assembler equivalent
  1922.  
  1923.             cmp r0,"A"                    cmp r0,#ASC"A"
  1924.             mov r0,020                    mov r0,#&20
  1925.             mov r2,"z"+1                  mov r2,#ASC"z"+1
  1926.             mov r2,1+"z"  !Error - won't recognize "z" as an ascii value
  1927.             cmpne r0,13                   cmpne r0,#13
  1928.             teq r0,"m"                    teq r0,#ASC"m"
  1929.             cmp r0,%110                   cmp r0,#%110
  1930.             mov r0,&A4                    mov r0,#&A4
  1931.             mov r0,0A4                    mov r0,#&A4
  1932.             mov r0,A4  !Error - A4 won't be recognised as a number
  1933.  
  1934.     As you can see this makes the code easier to read and also avoids errors
  1935.     if you forget the '#'.
  1936.  
  1937.     Note that you can ONLY use these shortcuts when the number is obviously
  1938.     an immediate value. If it is a variable you must still use '#'.
  1939.  
  1940.     WARNING - With this system an actual number in the second operand
  1941.     position is always assumed to be an immediate value. If you really DO
  1942.     mean a register you will have problems. For example, the instruction
  1943.     'mov 1,3' is interpreted by the Basic assembler as 'copy the contents of
  1944.     register r3 into register r1' but by SAsm as 'load register r1 with the
  1945.     immediate value 3'.
  1946.  
  1947.     To avoid this ambiguity it is usual when writing ARM code to prefix
  1948.     register numbers with 'r' or 'R', but this is not compulsory and the
  1949.     Basic assembler doesn't require it. If you have fallen into bad habits
  1950.     and just use a simple register number then you will have problems.
  1951.  
  1952.     There are two possible solutions. Firstly you could mend your ways and
  1953.     refer to registers properly like everyone else. Secondly you could use
  1954.     the #NOENHANCE directive to disable this feature.
  1955.  
  1956.         5.2      Extra mnemonics
  1957.  
  1958.     These are not actually mnemonics but macros which are expanded by the
  1959.     preprocessor. They are used in the code just like normal opcodes and so
  1960.     the distinction can normally be ignored. One important difference is
  1961.     that unlike normal mnemonics some CANNOT have conditional suffixes.
  1962.  
  1963.     Some call the built-in macro functions and you should refer to these for
  1964.     clarification if required.
  1965.  
  1966.     They may all be written in upper or lower case like normal assembler
  1967.     mnemonics.
  1968.  
  1969.         5.3      DW and DD
  1970.  
  1971.     These are expansions of EQUD and EQUW and in fact are translated into
  1972.     these when expanded. The main advantage is that DW and DD can be used to
  1973.     reserve a series of words or double words and not just one at a time.
  1974.     These follow the mnemonic as a comma separated list. For example -
  1975.  
  1976.             DD 1,2,3,4,5,6
  1977.  
  1978.     would be expanded by the preprocessor to -
  1979.  
  1980.             EQUD 1:EQUD 2:EQUD 3:EQUD 4:EQUD 5:EQUD 6
  1981.  
  1982.     which can save a lot of typing.
  1983.  
  1984.     Because the line will actually become longer, which is obvious from
  1985.     looking at the above example, it is possible for these (and DB which
  1986.     follows) to make the line expand beyond the permitted limit of 255
  1987.     characters. You should therefore avoid putting too many items on a
  1988.     single line.
  1989.  
  1990.     If any of the numbers begin with a zero SAsm will assume the number is
  1991.     in hex format, whether or not it is preceded by an '&' character. For
  1992.     example '20' would be decimal 20 but '020' would be translated as &20,
  1993.     eg. hex 20 which is decimal 32.
  1994.  
  1995.         5.4      DB
  1996.  
  1997.     This is a general purpose macro which replaces EQUB and EQUS and also
  1998.     allows an area of memory to be reserved for data and preset to any value
  1999.     if required.
  2000.  
  2001.     In it's simplest form DB is like DW and DB but with bytes as a multiple
  2002.     EQUB. If the parameter is a string enclosed in double quotes it acts
  2003.     like EQUS. These can be mixed in the same DB command which makes
  2004.     defining strings with control codes much easier. For example -
  2005.  
  2006.          DB 7,"Some text",10,13,"New line",0
  2007.  
  2008.     would be expanded to -
  2009.  
  2010.          EQUB 7:EQUS "Some text":EQUB 10:EQUB 13:EQUS "New line":EQUB 0
  2011.  
  2012.     As with DW and DD beware of allowing the line to become too long.
  2013.  
  2014.     Again numbers beginning with a zero will be regarded as hexadecimal.
  2015.  
  2016.     DB can be used with a multiplier to reserve an area of memory and set it
  2017.     to any value. If a parameter begins with '*' then the following number
  2018.     is taken as a multiplier and the number after that as the value to be
  2019.     inserted. For example -
  2020.  
  2021.         DB *100,32      (which could also be written as DB *100," " )
  2022.  
  2023.     would reserve 100 bytes as a data area and load them with the value 32,
  2024.     a space character.
  2025.  
  2026.     This can be mixed with strings and single bytes and can be used rather
  2027.     like SPC or STRING$ in Basic. For example -
  2028.  
  2029.         DB "1",*10,32,*8,".",*10,32,"First Menu Item",0
  2030.  
  2031.     would be expanded to the zero terminated string -
  2032.  
  2033.         1          ........          First Menu Item
  2034.  
  2035.     One advantage of this is that the multiplier need not be an actual
  2036.     number but could be an expression. This makes it a lot easier to change
  2037.     the size of data areas or the length of strings by simply altering the
  2038.     value of the variable.
  2039.  
  2040.     If you just wish to reserve an area of memory and do not need it to be
  2041.     set to any particular value then using a question mark as the value
  2042.     after the multiplier will do so. For example
  2043.  
  2044.             DB  *100,?
  2045.  
  2046.     would reserve 100 bytes but leave the area set to whatever random data
  2047.     already existed there.
  2048.  
  2049.         5.5      Basic variables and DB
  2050.  
  2051.     You can use variables instead of constants with DB. With the Basic
  2052.     assembler you could use -
  2053.  
  2054.             EQUD <var1> : EQUB <var2> : EQUB <var3>
  2055.  
  2056.     so with SAsm you could use -
  2057.  
  2058.             DB <var1>, <var2>, <var3>
  2059.  
  2060.     The previous examples using strings have shown an immediate string
  2061.     enclosed in double quotes. With the Basic assembler it is possible to
  2062.     use a Basic string variable with EQUS, eg.
  2063.  
  2064.             EQUS version$
  2065.  
  2066.     In earlier versions of SAsm this couldn't be done with DB but it is now
  2067.     permitted. SAsm will recognise any variable ending in the '$' character
  2068.     as a string so the 'DB variable$' will now equate to EQUS variable$. You
  2069.     can also use string concatenation, eg.
  2070.  
  2071.             DB prog_name$ + version$
  2072.             DB prog_name$ + " Version "+version$
  2073.             DB prog_name$ + STR$(version_number)
  2074.             DB "A String"+CHR$(7)
  2075.  
  2076.     although in the last case it would actually be neater to use -
  2077.  
  2078.             DB "A String",7
  2079.  
  2080.     For string concatenation to work with immediate strings the '+' must
  2081.     IMMEDIATELY follow the closing quotes as in the above examples.
  2082.  
  2083.     Immediate strings must be enclosed in double quotes. It would be
  2084.     possible to modify SAsm to allow single quotes as in many other
  2085.     assemblers but this would then make it impossible to permit this
  2086.     character inside immediate strings.
  2087.  
  2088.     SAsm will not recognise Basic strings defined with the '$' indirection
  2089.     indicator. With the Basic assembler you could use -
  2090.  
  2091.             EQUS $location%
  2092.  
  2093.     which would use the cr terminated string at 'location%'. This won't work
  2094.     using DB but it is so unlikely that it would be needed that I don't
  2095.     regard this as a problem. There may be other combinations of variables
  2096.     that won't work with DB, if you do have any difficulties please tell me.
  2097.  
  2098.         5.6      ADRL
  2099.  
  2100.     This is a two instruction 16 bit ADR directive. It takes the same
  2101.     parameters as the normal ADR directive, that is the syntax is -
  2102.  
  2103.             ADRL <register>,<location>
  2104.  
  2105.     ADRL will always assemble two instructions when <location> is greater
  2106.     then the current address. This is because the exact position of
  2107.     <location> will not be determined until the second pass. However if
  2108.     <location> is before the current address it's position will already be
  2109.     known and so a single instruction will be assembled whenever possible.
  2110.  
  2111.     If code length or speed is important you could use the ADR instruction
  2112.     until you get an 'out of range' error to ensure that no superfluous
  2113.     instructions are included.
  2114.  
  2115.     There MUST be a space between ADRL and <register> and it can be
  2116.     conditional
  2117.  
  2118.         5.7      MOVL
  2119.  
  2120.     This is a method of loading a large immediate number into a register. A
  2121.     series of ADD or SUB instructions will be assembled to load the value.
  2122.     The syntax is MOVL <reg>,<number>. If <number> begins with a zero it
  2123.     will be regarded as hexadecimal. <number> can of course be positive or
  2124.     negative. If it is negative then MVN instructions may be used by the
  2125.     macro but DO NOT adjust the number to allow for this as is required by
  2126.     the normal MVN instruction. The macro will make all the adjustments
  2127.     necessary so just write the actual number you require.
  2128.  
  2129.     This macro is fairly simple and may not produce the most efficient code
  2130.     for loading a given value. If speed or code length is paramount it may
  2131.     be possible to reduce the number of operations by hand coding.
  2132.  
  2133.     There MUST be a space between MOVL and <reg> and it can be conditional
  2134.  
  2135.         5.8      DIV
  2136.  
  2137.     This macro will perform a 32 bit integer division. The full syntax is;
  2138.  
  2139.         DIV <dividend reg>,<divider reg>,<quotient reg>,<temp reg>
  2140.  
  2141.     It therefore requires four DIFFERENT registers as its parameters and you
  2142.     are responsible for loading the correct values into the registers before
  2143.     using DIV. The results returned are;
  2144.  
  2145.             <quotient reg> = <dividend reg> DIV <divider reg>
  2146.             <dividend reg> = <dividend reg> MOD <divider reg>
  2147.  
  2148.     The <temp reg> is used for working only and will be corrupted.
  2149.  
  2150.     For example, to divide a number in R0 by a number in R1 and return the
  2151.     result in R2 using R3 as temporary workspace use;
  2152.  
  2153.             div r0,r1,r2,r3
  2154.  
  2155.     On exit r1 will be unchanged and r0 will contain the remainder if the
  2156.     number did not divide exactly.
  2157.  
  2158.     There MUST be a space between DIV and <register> and that because it
  2159.     expands to a large section of code it CANNOT be made conditional.
  2160.  
  2161.     Note -
  2162.  
  2163.     I have received complaints informing me that DIV doesn't work and just
  2164.     gives error messages. It does work perfectly. Most of these complaints
  2165.     turned out to be from people who hadn't read (or hadn't understood) the
  2166.     instructions. The parameters passed to DIV are the numbers of the
  2167.     REGISTERS it will use, not the actual numbers to be divided. You are
  2168.     responsible for writing code to load the actual values into these
  2169.     registers before using DIV to do the division. There is also no error
  2170.     checking. If you try to do something silly like divide by zero you could
  2171.     end up with your code either crashing or going into an infinite loop.
  2172.  
  2173.     If you want a general purpose division routine I suggest you write a
  2174.     sub-routine or expanded macro which deals with all of these things and
  2175.     uses DIV to do the actual work.
  2176.  
  2177.                                   Macros
  2178.                                   ======
  2179.  
  2180.     Sasm supports two types of Macros. Expanded Macros and Macro Functions.
  2181.     There are advantages and disadvantages with each type. Both can be
  2182.     included in your Macro Library.
  2183.  
  2184.         6.1      Macro Functions - Pro/Con
  2185.  
  2186.     These are normal Basic Functions and their use and format is described
  2187.     in the 'Tutorial'. They have two disadvantages. Firstly, because they
  2188.     are Basic Functions you must include assembler brackets, OPT setting,
  2189.     etc. and forward branches are awkward. Secondly it is not possible to
  2190.     use any of the special features of SAsm such as local labels, db, adrl,
  2191.     movl, etc. within a Macro Function. Also you cannot call or define an
  2192.     Expanded Macro from within a Macro Function.
  2193.  
  2194.     A serious disadvantage is that SAsm cannot recover from an error in a
  2195.     Macro Function. Such errors are Fatal and will produce an error message
  2196.     giving a line number that does not exist in the file.
  2197.  
  2198.     The first advantage is that this type of macro is not expanded by the
  2199.     pre processor so no matter how many times you use it no more memory is
  2200.     used. The second advantage will only apply if you use a Macro Library
  2201.     without a hard disc. This is because a Macro Function only appears once,
  2202.     at the end of the code, and so only one disc access to load it from the
  2203.     Library will be required.
  2204.  
  2205.         6.2      Expanded Macros - Pro/Con
  2206.  
  2207.     These are sections of code which are inserted into the file each time
  2208.     the Macro is invoked. The big advantage with this method is that you can
  2209.     use all the special features of SAsm, local labels, etc. You can also
  2210.     call Macro Functions or other Expanded Macros from within this type of
  2211.     macro.
  2212.  
  2213.     Because Expanded Macros become part of the normal code SAsm can normally
  2214.     recover from errors in them in the same way as it can recover from most
  2215.     other errors.
  2216.  
  2217.     The disadvantage is that an Expanded Macro must be defined before it is
  2218.     used, although it can be defined in your Macro Library. Also as the
  2219.     macro code is inserted into your source each time it is used more memory
  2220.     is required, although this unlikely to be a problem in practice.
  2221.  
  2222.         6.3      Macro Names
  2223.  
  2224.     Because Macro Functions and Expanded Macros are different they can have
  2225.     the same name. You can even have Expanded Macros and Macro Functions
  2226.     with the same name in your Library. SAsm will sort out which to use.
  2227.  
  2228.         6.4      Expanded Macros
  2229.  
  2230.     An Expanded Macro must be defined before it is used. If you use a Macro
  2231.     Library it may be defined there and it will be loaded from the Library.
  2232.     If you define a macro in the source file and one of the same name exists
  2233.     in the Library then the macro in the source file will be used.
  2234.  
  2235.         6.5      Defining Expanded Macros
  2236.  
  2237.     An expanded macro is defined as follows.
  2238.  
  2239.             # SM  <name>
  2240.             ........            \
  2241.             ........             > Normal SAsm code
  2242.             ........            /
  2243.             # EM
  2244.  
  2245.     and invoked by -
  2246.  
  2247.             @ <name>
  2248.  
  2249.     In each case <name> is the name given to the macro and, like the
  2250.     parameters, is case sensitive. Like other SAsm directives the '#' used
  2251.     by #SM (Start Macro) and #EM (End Macro) must be the first characters on
  2252.     the line. The '@' character should be the first non-space character on
  2253.     the line or, if the line starts with a label, the first non space
  2254.     character after the label. There must not be ANYTHING on the line after
  2255.     the macro call except a comment, defined in the usual way.
  2256.  
  2257.     When SAsm encounters '@' it tries to match the following name with a
  2258.     previously defined macro. When found it inserts a copy of the code into
  2259.     the file. If there are locaL labels in a macro they will be unique
  2260.     within that definition, but non-local labels will be global.
  2261.  
  2262.         6.6      Macro Parameters
  2263.  
  2264.     You can pass parameters of almost any type to an Expanded Macro. The
  2265.     syntax of the defining line of the start of a macro is -
  2266.  
  2267.             # sm  <name> <param 1> , <param 2> , <param 3> ....
  2268.  
  2269.     and of the calling line -
  2270.  
  2271.             @ <name>  <param val 1> , <param val 2> , <param val 3> ....
  2272.  
  2273.     where <name> is the name given to the macro, <param> is the name given
  2274.     to a parameter and <param val> is the value the parameter will be given
  2275.     when the macro is expanded. There must be at least one space between
  2276.     <name> and the first parameter and parameters are separated by commas.
  2277.  
  2278.     A parameter is a Global Variable and must conform to the Basic variable
  2279.     type for the value it will hold. It can be Integer, String or Floating
  2280.     Point. The parameter passed must be suitable for that type of variable.
  2281.     It need not be a constant value. Any expression which can be evaluated
  2282.     during assembly to the correct type of variable may be used.
  2283.  
  2284.     You may recognise that the syntax has been made identical to the way
  2285.     that parameters are passed to Basic Functions and Procedures except that
  2286.     there are no brackets.
  2287.  
  2288.         6.7      Local Labels in Expanded Macros
  2289.  
  2290.     Local labels can be used in expanded macros and these must conform to
  2291.     the syntax used elsewhere. You MUST start local labels in a macro
  2292.     definition with '00' to ensure that the labels will be unique.
  2293.  
  2294.     When the macro expansion ends the 'flow' of local labels in the main
  2295.     code before the macro was used will be restored. A macro, with its own
  2296.     set of local labels, can exist within the area of normal local labels
  2297.     without confusion. In practical terms this means that, provided you
  2298.     ensure that any local labels used in a macro start with '00', you can
  2299.     ignore the fact that a macro exists for the purposes of local labels in
  2300.     the main code.
  2301.  
  2302.     Similarly if expanded macros are nested then any local labels defined
  2303.     will be unique within that invocation and the labels in the calling
  2304.     macro will branch around labels in the called macro.
  2305.  
  2306.     Remember that, like all non local labels, any other labels defined in an
  2307.     expanded macro will become global and will assume the value assigned in
  2308.     the current invocation.
  2309.  
  2310.     You should understand that the '<' and '>' modifiers will only apply to
  2311.     the previous and next sets of local labels within the actual macro. They
  2312.     cannot be used to access code outside the macro, and any attempt to do
  2313.     so will produce an error.
  2314.  
  2315.         6.8      Special features of Expanded macros
  2316.  
  2317.     The biggest advantage of expanded macros is that you can take advantage
  2318.     of the special features of SAsm when using them. The ADRL, MOVL DB, DW
  2319.     and DD pseudo-ops can be used if required.
  2320.  
  2321.     You can call Macro Functions and other Expanded Macros can be invoked
  2322.     from within macros. Expanded Macros can be 'nested' to a maximum depth
  2323.     of twenty. In theory this could be greater but I couldn't think of any
  2324.     (non-contrived) circumstance when I would need more than four or five so
  2325.     I limited it to twenty.
  2326.  
  2327.     Expanded Macros must NOT be invoked recursively. This would set up an
  2328.     infinite loop which would cause all available memory to be filled. This
  2329.     is another reason for limiting nesting of macros because if this is done
  2330.     by accident an error will be flagged long before this stage is reached.
  2331.  
  2332.         6.9      Example
  2333.  
  2334.     This is an example of how you could use a macro to print a string at any
  2335.     location on the screen. Note that as usual I have used more spaces than
  2336.     are actually necessary to make things clearer.
  2337.  
  2338.             # SM   print_tab  x_pos , y_pos , display$
  2339.               swi  256+31
  2340.               swi  256+x_pos
  2341.               swi  256+y_pos
  2342.               swi  OS_WriteS
  2343.               equs display$
  2344.               equb 0
  2345.               align
  2346.             # EM
  2347.  
  2348.     The operation of the code should be obvious. Firstly there is the
  2349.     equivalent of 'VDU 31, x_pos, y_pos' to position the text cursor where
  2350.     required. OS_WriteS is then used to print the text which is placed in
  2351.     memory immediately after it.
  2352.  
  2353.     So, to print 'This is a test' at column 10, line 4 you would use
  2354.  
  2355.             @  print_tab  10,4,"This is a test"
  2356.  
  2357.     To illustrate nesting macros the following example splits this procedure
  2358.     into two separate macros, one of which uses the other.
  2359.  
  2360.             # SM  do_tab  x , y
  2361.               swi  256+31
  2362.               swi  256+x
  2363.               swi  256+y
  2364.             # EM
  2365.             # SM  print_tab  x_pos , y_pos , display$
  2366.               @ do_tab  x_pos, y_pos
  2367.               swi  OS_WriteS
  2368.               equs display$
  2369.               equb 0
  2370.               align
  2371.             # EM
  2372.  
  2373.     This would be used in exactly the same way as the previous example, but
  2374.     note that as 'print_tab' uses 'do_tab' then 'do_tab' must be defined
  2375.     before it can be used in 'print_tab'.
  2376.  
  2377.             @  print_tab  10,4,"This is a test"
  2378.  
  2379.     Would give the same results, and in this instance the code actually
  2380.     assembled would be exactly the same.
  2381.  
  2382.     In fact, it could be split still more. Leaving the macro 'do_tab' as
  2383.     previously defined;
  2384.  
  2385.             # SM  print_string  string$
  2386.               swi OS_WriteS
  2387.               equs string$
  2388.               equb 0
  2389.               align
  2390.             # EM
  2391.             # SM  print_tab  x_pos , y_pos , display$
  2392.               @ do_tab  x_pos,y_pos
  2393.               @ print_string  display$
  2394.             # EM
  2395.  
  2396.     Once again exactly the same actual code would be assembled.
  2397.  
  2398.         6.10     Errors in Expanded macros
  2399.  
  2400.     SAsm should be able to recover from errors in expanded macros. The error
  2401.     message will be slightly different from normal and in the form;
  2402.  
  2403.      Error <message> at line <number> in Macro <macro name> at line
  2404.                                <line number> in file <file name>
  2405.  
  2406.     The line number in the file will be the line where the macro was
  2407.     invoked. The line number within the macro will be the offset from the
  2408.     start of the macro where the error occurred. If this was the invoking
  2409.     line then the error will be shown as having occurred in line 0.
  2410.  
  2411.     This can appear strange if the macro invokes other macros. When the
  2412.     error happens the macro has been expanded, so the line number may be
  2413.     greater than the apparent size of the macro. For instance, in the final
  2414.     example shown above if an error occurred in the line which invoked
  2415.     'print_string' in the macro 'print_tab' the error would be shown as
  2416.     having occurred not at line 2, but at line 5.
  2417.  
  2418.     This is not normally a problem is practice because the actual error can
  2419.     usually be found by inspection but I may improve upon it later.
  2420.  
  2421.         6.11     Macro Functions
  2422.  
  2423.     Macro Functions are defined and used exactly as in the Basic assembler.
  2424.     If you don't know how this works I refer you to the 'Tutorial'.
  2425.  
  2426.     A Macro Function is a Basic Function who's definition, as in a normal
  2427.     Basic program, appears after the #END directive. You use it by writing
  2428.     FN<name>, where <name> is the name of the function, in the assembler
  2429.     source. Most Macro Functions will require parameters and these are
  2430.     passed, enclosed in brackets after the function name, in the usual way.
  2431.  
  2432.     You must remember when defining a Macro Function that when it is called
  2433.     you have quit the assembler and are back in normal Basic. As a macro
  2434.     will probably include assembly code you will need to use the square
  2435.     brackets and define the OPT setting to re-enter assembler.
  2436.  
  2437.     SAsm uses two variables to define the OPT setting, Q% and PASS. You can
  2438.     use either of these when defining Macro Functions although I suggest you
  2439.     use PASS as its purpose is more obvious. The only time you need depart
  2440.     from this is if you are using a forward branch in the macro. In this
  2441.     case you must set a two-pass loop within the macro and you MUST define
  2442.     your own OPT variable. You could modify PASS because although it is set
  2443.     by SAsm at the beginning of each assembler pass it is not actually used,
  2444.     but it is safer to use an independent variable. It is very important
  2445.     that you do NOT modify in any way the Basic Integer variable Q%.
  2446.  
  2447.     WARNING - You cannot use the extra mnemonics DB, DW, DD, DIV, ADRL, MOVL
  2448.     or the enhanced immediate 2nd operands in Functions. These can only be
  2449.     used in the main body of the code or within Expanded Macros. You can
  2450.     call functions FNadr, FNmov, FNdiv and FNset as alternatives if
  2451.     required. These will be retained in later versions for this purpose.
  2452.     These restrictions will not be removed in later versions of SAsm since
  2453.     whenever possible you are advised to use Expanded Macros instead.
  2454.  
  2455.         6.12     The Built-In Functions
  2456.  
  2457.     SAsm has a number of pre-defined Macro Functions and the following
  2458.     section describes them. Do not to use them in new work except when
  2459.     called from within other Macro Functions as the extra mnemonics ADRL,
  2460.     MOVL, DIV, DB, DW and DD should be used instead.
  2461.  
  2462.     As well as the functions described there are two others FNadrc and
  2463.     FNmovc. These should not be used directly and so are not documented but
  2464.     do not create your own functions with these names or conditional ADRL
  2465.     and MOVL will not work correctly.
  2466.  
  2467.     NOTE - The old functions FNdb, FNdw and FNdd have now been deleted.
  2468.  
  2469.         6.13     FNgap ( <size> )
  2470.  
  2471.     Defines a gap in the code for use as a data area of <size> bytes. The
  2472.     memory is not pre set to any value. If <size> is not exactly divisible
  2473.     by 4 and you intend to follow FNgap with an opcode you should use ALIGN
  2474.     to ensure that further assembly occurs on a word boundry. Use 'DB' for
  2475.     preference unless within a Macro Function.
  2476.  
  2477.         6.14     FNset ( <size>,<value> )
  2478.  
  2479.     Similar to FNgap except that the memory is preset to <value>. Use the DB
  2480.     mnemonic in preference wherever possible.
  2481.  
  2482.         6.15     FNadr ( <register>,<location> )
  2483.  
  2484.     FNadr is an expansion of the ADR pseudo-opcode. Its syntax is the same
  2485.     except that the parameters must be enclosed in brackets. It can reach
  2486.     any byte within 64K or within 256K if <location> falls on a word
  2487.     boundry. If <location> is a forward reference FNadr always assembles two
  2488.     instruction. If a backward reference FNadr assembles a single
  2489.     instruction if possible.
  2490.  
  2491.     This is equivalent to the ADRL expanded mnemonic which should be used in
  2492.     preference.
  2493.  
  2494.         6.16     FNmov ( <register>,<value> )
  2495.  
  2496.     This is an expansion of the MOV opcode to load a register with an
  2497.     immediate value. Unlike the normal MOV this will generate sufficient ADD
  2498.     opcodes after the initial MOV to load any 32 bit number. If <value> is a
  2499.     negative number then MVN and SUB will be used. Note that when using
  2500.     negative numbers you do not need to subtract 1 as you do with MVN. eg.
  2501.     to load r3 with -123456 just use  FNmov (3,-123456)
  2502.  
  2503.     Use the MOVL mnemonic for preference unless within a Macro Function.
  2504.  
  2505.                                The Macro Library
  2506.                                =================
  2507.           ** This facility is available only to REGISTERED users **
  2508.  
  2509.         7.1      Using the Macro Library
  2510.  
  2511.     The Registered version of SAsm can record every Macro Function or
  2512.     Expanded Macro call in your source file. If it is an Expanded Macro and
  2513.     it has not been previously defined somewhere in your code then it can be
  2514.     loaded from a Library file and inserted in the source. If it is a Macro
  2515.     Function it will be checked against the definitions found after the #END
  2516.     directive. If one or more definitions cannot be found it will try to
  2517.     load the missing definitions from a Library file.
  2518.  
  2519.     For Macro Functions the Library is only checked after all the source
  2520.     files have been loaded so a Macro Function in a source file will
  2521.     'override' a macro of the same name in the Library.
  2522.  
  2523.     If an Expanded Macro is defined in the source file it is used in
  2524.     preference to one of the same name in the Library. If a macro is defined
  2525.     part way through the source files then calls to that macro before it is
  2526.     defined will be loaded from the Library and those after will use the
  2527.     version in the source file.
  2528.  
  2529.         7.2      The 'L' parameter
  2530.  
  2531.     If you have a hard disc this operation is so fast that the only way you
  2532.     know it is happening is that SAsm will tell you that it is loading Macro
  2533.     Functions or that the Library isn't required. If you are using a single
  2534.     floppy drive you may have your Library file on another disc. When you
  2535.     know that no Library macros are required it is annoying to have to
  2536.     change discs and allow SAsm to satisfy itself that the (probably
  2537.     misspelt) missing Macro isn't in the Library. You can therefore add the
  2538.     suffix 'L' to the command line to tell SAsm NOT to use the Library, even
  2539.     if SAsm$Lib (see later) is defined.
  2540.  
  2541.         7.3      Use of the 'V' parameter
  2542.  
  2543.     If you have used the 'V' (verbose) parameter then as each Expanded Macro
  2544.     is being searched for a message is displayed. Normally this takes the
  2545.     form -
  2546.  
  2547.         Searching Library for Macro <macro name> - Loaded
  2548.  
  2549.     But if the macro cannot be found in the Library it will say -
  2550.  
  2551.         Searching Library for Macro <macro name> - Not found in Library
  2552.  
  2553.     At this stage a missing macro will not produce an error but it will
  2554.     become one during assembly.
  2555.  
  2556.         7.4      The SAsm$Lib OS variable
  2557.  
  2558.     To tell SAsm that a Library exists you should either create an OS
  2559.     variable 'SAsm$Lib' with the path/file name of the Library or use the
  2560.     #LIB directive within the source file. To use the SAsm$Lib variable type
  2561.     at the OS '*' prompt 'Set SAsm$Lib <filename>' where <filename> is the
  2562.     path/file name of your Macro Library or put this command in your !Boot
  2563.     file. You can of course have more than one Macro Library and just change
  2564.     SAsm$Lib to refer to the one in current use.
  2565.  
  2566.     If SAsm can't find a macro definition in the source files it will check
  2567.     to see if a Library has been defined. If so will extract the 'index'
  2568.     which MakeLib has created. This will be checked against any missing
  2569.     definition and if these appear in the Library they will be included.
  2570.  
  2571.     If SAsm can't find a macro in the source and the 'L' parameter hasn't
  2572.     been used but a Library hasn't been defined then an Error message will
  2573.     be displayed. If you are sure that all the macros exist in the source it
  2574.     is best to use the 'L' parameter to ensure that this doesn't happen.
  2575.  
  2576.         7.5      Preparing a Macro Library
  2577.  
  2578.     First create a file of Macro Functions and/or Expanded Macros. These are
  2579.     macro definitions exactly like the ones you would use in source files.
  2580.  
  2581.     Each Expanded Macro should begin with the #SM directive and end with the
  2582.     #EM directive.
  2583.  
  2584.     On your program disc you will find an application called 'MakeLib'. Copy
  2585.     this to a blank disc and *MOUNT the disc or copy it to the Library
  2586.     directory of your hard disc. At the OS '*' prompt type;
  2587.  
  2588.             *MakeLib  <source filename>  <Library filename>
  2589.  
  2590.     where <source filename> is the full path/file name of your Macro
  2591.     definition file and <Library filename> is the path/file name that you
  2592.     wish to call the actual Library file that SAsm will use.
  2593.  
  2594.     MakeLib will load your Macro source file and prepare it for use by SAsm.
  2595.     Once MakeLib has created the Library file the original source is no
  2596.     longer required but you should keep it so that you can add new macros
  2597.     and update your Library in the future.
  2598.  
  2599.     The present version of MakeLib can only accept a single source file but
  2600.     I intend to improve it to accept wildcards in a similar manner to SAsm.
  2601.  
  2602.         7.6      Length of Library file
  2603.  
  2604.     The source for a Library file can be any length and have as many
  2605.     comments ay you like. As with SAsm source files these will all be
  2606.     stripped before the routines are added to the actual Library.
  2607.  
  2608.     The Library file can hold about 200 Macro definitions. I suggest that in
  2609.     practice you only put the macros you frequently require in your Library
  2610.     and use INCLUDE files for those only rarely needed. This will make the
  2611.     search time shorter and also probably allow you to put your Library on
  2612.     your normal working disc if you are using a single floppy.
  2613.  
  2614.                         SAsm and the Desktop
  2615.                         ====================
  2616.  
  2617.     SAsm was originally intended to be used at the OS command line prompt.
  2618.     However, the introduction of good text editors such as !Zap and other
  2619.     tools now make it possible to to develop programs within the Archimedes
  2620.     desktop. Although SAsm itself is not integrated into the desktop
  2621.     environment versions after 1.40 have features which help them to be used
  2622.     in this way. The introduction of the desktop Front End program !SAsm
  2623.     enables SAsm to be used entirely within the desktop environment. I shall
  2624.     refer to the front end program as !SAsm to distinguish it from SAsm
  2625.     itself. !SAsm should have been included with your copy of SAsm, and it
  2626.     has its own separate instructions so I shall not go into it in detail
  2627.     here.
  2628.  
  2629.         8.1      The new features
  2630.  
  2631.     The changes which have been introduced are described in the section on
  2632.     directives. They enable all the parameters which previously had to be
  2633.     typed at the command line (and more) to be inluded in the file as
  2634.     Directives. This means that only the name of a single 'make' file needs
  2635.     to be typed and this file can contain all other data needed to assemble
  2636.     the program.
  2637.  
  2638.     Even without the 'front end' you can use SAsm within the desktop very
  2639.     easily and assemble projects by clicking on a single 'Obey' file. You do
  2640.     not need to set the CSD as you will can use the <Obey$Dir> OS variable
  2641.     to define the start point of your project directory structure.
  2642.  
  2643.         8.2      Using SAsm from the Desktop
  2644.  
  2645.     You can include everything needed to assemble an extensive project in a
  2646.     single short 'make' file. This would contain all the preliminary
  2647.     directives (org, size, type, etc) plus directives to define the object
  2648.     and error filenames and the library to be used. Following these will
  2649.     come a list of Include files to be assembled. The main advantage of this
  2650.     system for desktop use is that it enables an Obey file to run SAsm. In
  2651.     fact !SAsm can create a suitable Obey file so you can assemble a project
  2652.     without actually loading !SAsm itself. For example, to assemble a
  2653.     desktop project you should set up a directory structure as shown.
  2654.  
  2655.                              root
  2656.                               |
  2657.                               |
  2658.                  -----------------------------
  2659.                 |                             |
  2660.               source                        !app
  2661.  
  2662.     The 'root' directory would contain your 'make' file and the Obey file
  2663.     which will run it. It need not, of course, be the actual root directory
  2664.     of a disc, it is just the root directory of your project. The !App
  2665.     directory will be the RiscOS application directory for your project. The
  2666.     'Source' directory will contain all of your source files. You could, of
  2667.     course, also have other directories to hold special library files, error
  2668.     files, notes, etc. if required.
  2669.  
  2670.     Assuming the Make file is simply called 'Make' the Obey file would
  2671.     contain just two lines -
  2672.  
  2673.             Set   Project$Dir <Obey$Dir>
  2674.             Sasm  <Project$Dir>.Make
  2675.  
  2676.     When you double-click on this file it will atomatically create an OS
  2677.     variable 'Project$Dir (or whatever you want) and set it to 'Obey$Dir',
  2678.     ie. to the 'root' directory of your project. It will then Run SAsm
  2679.     (either from the RMA if you have loaded the Module version or from disc)
  2680.     with the filename of the Make file.
  2681.  
  2682.     The Make file should define the various parameters to assemble the
  2683.     program using the <Project$Dir> variable. Alternatively you could set
  2684.     the OS variable using the CLI directive from within the Make file. It
  2685.     would also contain directives to define the error file, library and
  2686.     object file, for example -
  2687.  
  2688.             # errfile <Project$Dir>.err
  2689.             # obj     <Project$Dir>.!App.!Runimage
  2690.  
  2691.     and the files to be assembled would be -
  2692.  
  2693.             # include <Project$Dir>.source.first_*
  2694.             # include <Project$Dir>.source.second_*
  2695.             # include <Project$Dir>.source.third_*
  2696.  
  2697.     or whatever they are called. Note that you can still use the 'descending
  2698.     trailing digits' wildcard to assemble the latest version.
  2699.  
  2700.     The Make file need not, of course, be in the 'root' directory, it could
  2701.     be in the source directory if you prefer, (it is, technically, just
  2702.     another source file). If you don't have a hard disc you will probably
  2703.     prefer to have your source files (and certainly the error file) on the
  2704.     RAM disc. As SAsm doesn't create any temporary files you don't need much
  2705.     spare space.
  2706.  
  2707.     To assemble a project in this way just double-click on the Obey file.
  2708.  
  2709.     You can, of course, use SAsm in a 'Task' window but this means you will
  2710.     need to define directories and type filenames again. The biggest
  2711.     advantage of using a task Window is that if SAsm does crash the Wimp
  2712.     will normally allow you to close the window, thus killing the task. This
  2713.     is very useful when I'm using SAsm for development work on SAsm where
  2714.     this can happen. A disadvantage of a Task Window is that on ARM 2
  2715.     machines it does slow up operation.
  2716.  
  2717.                         Problems and Questions
  2718.                         ======================
  2719.     Important
  2720.  
  2721.     I'm continually trying to improve SAsm. Please tell me if you have any
  2722.     problems, even if you haven't registered. It's only by acting on bug
  2723.     reports and suggestions that I can keep improving it.
  2724.  
  2725.     9.1      Reporting and diagnosing problems
  2726.  
  2727.     Tell me which version of SAsm you are using, you may have experienced a
  2728.     'bug' which has already been fixed. A lot of time can be wasted trying
  2729.     to reproduce an error which can't occur on a later version. Ideally send
  2730.     the version of SAsm you are using. I may no longer have a copy of that
  2731.     version (there have been quite a few updates!)
  2732.  
  2733.     Send a copy of the source file(s) that caused the problem, preferably
  2734.     all files not just the one that gave the error, plus any error files
  2735.     generated or other information. I need to know exactly how the program
  2736.     failed, 'it wouldn't work with this' isn't very helpful! If you use SAsm
  2737.     in a Task Window then if possible 'Save' the contents and include it. If
  2738.     you don't normally run SAsm from a Task Window then if possible please
  2739.     do so that you can send me the file.
  2740.  
  2741.     Try to create listing and error files. If SAsm produces an uncorrupted
  2742.     listing file it indicates the problem isn't in preprocessing. This
  2743.     doesn't mean that something in preprocessing isn't causing a problem for
  2744.     the assembler, but it does indicate that it will probably be easy to
  2745.     spot and solve. Sometimes SAsm will produce a valid listing or error
  2746.     file but it's type will be Data and not Text. Once again this is a
  2747.     valuable pointer to the likely source of the problem.
  2748.  
  2749.     You may be able to produce a listing file by using a 'null' object
  2750.     filename (~) even though you can't get an object file. If you can do
  2751.     this you may be able to examine it and discover the problem.
  2752.  
  2753.     You may feel all this isn't necessary because I should be able to
  2754.     reproduce the problems that you have experienced, but this may not be
  2755.     possible. I have often been sent source code which assembled perfectly
  2756.     when I tried it. On one occaision it wouldn't work on the users machine
  2757.     because he was trying to run it in a P.D. Task Window program using
  2758.     RiscOS 2 and it was the Task Window that had crashed, not SAsm. There
  2759.     was no way that I could have reproduced this except that the user
  2760.     enclosed a screen 'grabbed' from the desktop and I recognised the non
  2761.     standard window.
  2762.  
  2763.     I use SAsm a lot so it *should* be bug free since it gets a lot of
  2764.     testing, not least because I use it to assemble SAsm itself. However,
  2765.     like most programmers I write code in a fairly consistent way and to a
  2766.     regular format. I use some features a lot, some rarely, others almost
  2767.     never. Experience shows that there is always someone who does something
  2768.     that I have never thought of. Often this is quite legitimate, sometimes
  2769.     downright weird, but it may introduce a variation I haven't allowed for.
  2770.     Most changes to SAsm are 'fixes' and improvements to accommodate the way
  2771.     that other people work.
  2772.  
  2773.     One thing that can happen with both SAsm and the Basic asembler is that
  2774.     labels, constants and register names are all 'normal' global variables.
  2775.     Most assemblers and compilers treat register names, labels and constants
  2776.     differently. You must be careful not to use the same name for more than
  2777.     one item. It is very easy to define a label and a register or an offset
  2778.     into a data area with the same name and disastrous consequences.
  2779.  
  2780.     You may find that with a complex program it is best to use some sort of
  2781.     prefix or suffix for data offsets and registers. Using names like r_ptr
  2782.     for a register and d_offset for a data area offset will avoid this sort
  2783.     of problem. Another solution is to use upper case names (beware the SAsm
  2784.     reserved variables) or names beginning with a capital letter for
  2785.     constants. As most constants will be integers a good solution is to make
  2786.     them all Basic integer variables by ending the name with % because
  2787.     'number' and 'number%' are different variables. No doubt you will devise
  2788.     your own method of sorting the various names into easily identified
  2789.     categories.
  2790.  
  2791.     If you suspect this might be the trouble then list out all your labels
  2792.     to a file and check them against register names and constants. That's
  2793.     why this function was included and it can save a lot of time.
  2794.  
  2795.     If all else fails there is one final thing you can try. The registered
  2796.     version of SAsm can save the fully processed data as a file before
  2797.     assembly. You can do this either by using a 'p' parameter at the command
  2798.     line or, instead of pressing RETURN when you type the command, hold down
  2799.     both SHIFT keys and press the keypad ENTER. This stops any assembly
  2800.     taking place and saves the whole file with whatever you had assigned as
  2801.     the object filename.
  2802.  
  2803.     This function was included for my own purposes when debugging SAsm
  2804.     itself. The resulting file is difficult to understand but it may help
  2805.     you (or me) to discover what is happening. It is only mentioned as a
  2806.     tool of last resort because it is really intended to show up
  2807.     shortcomings in SAsm.
  2808.  
  2809.         9.2      Speed of operation
  2810.  
  2811.     The two questions I am most often asked about SAsm are 'what language is
  2812.     it written in?' and 'how fast is it?'.
  2813.  
  2814.     These can most easily be answered together. SAsm is written in machine
  2815.     code using SAsm. Each version is assembled using the previous version.
  2816.     The source code is then changed to take advantage of any new features
  2817.     and re-assembled. I therefore test SAsm by 'self assembling'.
  2818.  
  2819.     The source for SAsm consists of more than 7000 lines split over eleven
  2820.     files. These are loaded from disc, assembled, and the source file saved
  2821.     to disc in less than seven seconds on an A440 with an ARM 2 processor
  2822.     and an ST506 hard disc or about three seconds on an A5000 or Risc PC. I
  2823.     think this is fast enough for most purposes.
  2824.  
  2825.     Without a hard disc the time taken would be quite a bit longer, but as
  2826.     SAsm can use a RAM disc this shouldn't be a difficulty unless you are
  2827.     trying to write long programs on a 1Mb machine. Unlike most assemblers
  2828.     and compilers SAsm doesn't use much memory for its own purposes.
  2829.  
  2830.         9.3      Memory usage
  2831.  
  2832.     SAsm starts by using whatever RAM is made available by the NEXT TASK
  2833.     allocation. If this is insufficient it will try to grab more from the
  2834.     Wimp Pool. If this is successful it will eventually hand all of this
  2835.     over to Basic for the actual assembly. Normally this will allow enough
  2836.     overhead for the Basic Heap, but if there are a lot of variables this
  2837.     may not be the case. If you do get a Basic error message implying that
  2838.     there isn't enough room the solution is to start out with a large
  2839.     allocation by dragging the 'NEXT' slider. In extreme cases this problem
  2840.     could cause a complete hang-up because there may not be enough memory
  2841.     available to report the error, so Basic calls the error handler, but
  2842.     there isn't enough memory to report the error, so......
  2843.  
  2844.     Whichever version of SAsm you are using the SAsm application code itself
  2845.     will be located at &8000. After the application code space is allocated
  2846.     for data areas used by SAsm. A 16K 'buffer' is allowed and the first
  2847.     file is loaded above this space. This will probably be about 50K above
  2848.     the start of the 'slot' at &8000 and this is the only RAM normally used
  2849.     by SAsm. As the file is processed it is copied down to the start of this
  2850.     buffer. Obviously the 'tail' of the processed file will eventually
  2851.     overlay the beginning of the 'raw' file, but this is not of any
  2852.     consequence. When the first file has been processed a new 16K buffer is
  2853.     allocated after its end and the next file is loaded and processed. This
  2854.     continues until all the files are completed.
  2855.  
  2856.     With smaller programs this is passed to Basic in this form for assembly.
  2857.     However Basic can't cope with untokenised programs in excess of about
  2858.         6500 lines, so anything larger than this must be tokenised by SAsm. If
  2859.     this is necessary you will see a message to this effect.
  2860.  
  2861.         9.4      Some notes on Local Labels
  2862.  
  2863.     I shall describe briefly how SAsm handles local labels as is is
  2864.     possible, although unlikely, for it to conflict with other variables.
  2865.  
  2866.     You will be aware that Basic does not permit variable names to begin
  2867.     with a number. SAsm therefore adds a two letter prefix to each local
  2868.     label. This is given a wide spread to speed up access by Basic. The
  2869.     prefix starts at 'zz' and reduces to 'Az', then 'zy' to 'Ay' etc. The
  2870.     label prefix is reset each time a '00' label is encountered. You can see
  2871.     exactly how this works by examining any Listing file where local labels
  2872.     have been used. Where local labels are used in expanded macros a similar
  2873.     method is used but with a three character prefix.
  2874.  
  2875.     The system is simple and is designed to be very fast for Basic to use.
  2876.     However it is possible for conflicts to exist if you have defined a
  2877.     label or other variable in this form, eg. a variable 'xy10' could cause
  2878.     problems. To avoid this you are strongly advised to ensure that your own
  2879.     variables and labels don't use this form, eg. 'xy_10' couldn't possibly
  2880.     cause a problem.
  2881.  
  2882.         9.5      The most common problems
  2883.  
  2884.     There are a few 'features' of SAsm which can cause trouble. Some are
  2885.     minor bugs that are unimportant once you know about them and will be
  2886.     fixed when I have time. Others are errors which can occur because of
  2887.     changes in the syntax used by SAsm. I will record some of the queries
  2888.     raised by users to help others avoid the same problems.
  2889.  
  2890.     Before you decide it's a bug in SAsm that's making things go wrong
  2891.     PLEASE read these and assure yourself that none of them could possibly
  2892.     apply. Most 'problem code' I am sent display one or more of these errors
  2893.  
  2894.     Because of the way SAsm operates it does not have perfect control over
  2895.     assembly and there will always be things which can make it crash. These
  2896.     are slowly being eliminated and the error trapping is being improved so
  2897.     that things which could cause a crash or a 'lock up' in earlier versions
  2898.     are now either accepted or just give an error message.
  2899.  
  2900.     1. There MUST be a space between the mnemonic and the first operand for
  2901.        many of SAsm's functions to work. This is not always essential with
  2902.        the Basic assembler but it is good practice so I make no apologies.
  2903.  
  2904.     2. MOVL, ADRL and DIV are actually macro's and not assembler mnemonics.
  2905.        ADRL and MOVL can be made conditional but because DIV expands to many
  2906.        lines of code with internal compare instructions it cannot.
  2907.  
  2908.         3. Make sure that you start every set of local labels with '00'.
  2909.  
  2910.     4. You cannot use local labels, DB, DW, DD, ADRL, MOVL, DIV or the
  2911.        enhanced second operator functions after the #END directive, so you
  2912.        can't use them within Macro Functions. You can use them within
  2913.        Expanded Macros because these are defined before the #END statement.
  2914.  
  2915.     5. Because DB, DW and DD instructions may expand considerably they can
  2916.        cause a 'line too long' error if you put too much on one line.
  2917.  
  2918.     6. SAsm removes redundant spaces and comments as it works but other
  2919.        operations expand it. Normally the contraction is greater than the
  2920.        expansion so the file shrinks. As a file is loaded a 16K 'overhead'
  2921.        is allowed in case the file grows. This should be plenty, but in
  2922.        extreme cases of large files without spare spaces or comments the
  2923.        program could crash. I will add routines to guard against this when I
  2924.        get time but I don't regard it as a major fault since one aim of SAsm
  2925.        is to let you split up and spread out your source files.
  2926.  
  2927.     7. SAsm regards a ';' as defining a comment so if you insert a line of
  2928.        Basic which has a PRINT statement that includes the ';' character
  2929.        with a preceding space it will be 'cut off'.
  2930.  
  2931.     8. There must be a CR or LF at the end of the last line of each file.
  2932.        Check by loading the file into your editor and pressing CTRL-DOWN
  2933.        to move the cursor or caret to the end of the file. It should be on a
  2934.        blank line below the last line. If it appears at the end of the last
  2935.        line there isn't a final terminator and you'll have problems.
  2936.  
  2937.     9. SAsm can abort with an error if there is not enough space for line
  2938.        numbers. This is because after SAsm has finished with the files Basic
  2939.        will need to add 3 bytes to each line for the line number and length
  2940.        byte. The solution is to make more memory available.
  2941.  
  2942.     10.SAsm can quit with a fatal error giving a line number greater
  2943.        than the length of the file the error occurred in. Usually this means
  2944.        the error happened inside a Macro Function. This is always a problem
  2945.        with Basic Functions and there is no simple solution. Often the only
  2946.        way of discovering the error is to examine every FN call in the file
  2947.        where the error occurred. The filename given will be the name of the
  2948.        file from which the function was called, and if it is used elsewhere
  2949.        the most probable cause is an error in one of the parameters passed.
  2950.        If it persists you could try splitting up the offending file into
  2951.        smaller sections to help you to 'zero in' on the problem.
  2952.  
  2953.     11.If SAsm crashes for any reason it can leave an error or x-ref file
  2954.        open. If there is a fatal error these files should be closed but if
  2955.        SAsm itself crashes this may not happen. You won't be aware of this
  2956.        until you run SAsm again when the 'file open' error will occur as
  2957.        SAsm tries to open an already open error file. IN THEORY you should
  2958.        just get a 'beep' and a warning message telling you that the error
  2959.        file was open and assembly will proceed. If this happens you will
  2960.        have lost the first error message although the error will be counted.
  2961.        Source or Object files can't be left open as these are only accessed
  2962.        as whole files. If a filing system doesn't give the standard error
  2963.        number this error won't be intercepted. In this case the program will
  2964.        go into an infinite loop because every time it tries to report the
  2965.        'file open' error it will generate ...... a file open error! If this
  2966.        happens when using a Task Window try pressing F12 and typing 'SHUT'.
  2967.  
  2968.     12.The parameters passed to the DIV macro are the register numbers it
  2969.        will use, not the values operated upon. You are responsible for
  2970.        loading the values into the respective registers before using the
  2971.        macro. Don't forget that these registers will be altered afterwards.
  2972.        This macro has no error checking. If you try to divide by zero or do
  2973.        something stupid it may crash or go into an infinite loop. It works
  2974.        well, but it's dumb, so it's up to you to use it properly.
  2975.  
  2976.     13.It doesn't matter whether you use a LF (ascii 10) or CR (ascii 13)
  2977.        at the end of each line. Most text editors use LF's but some can use
  2978.        either or even a LF/CR combination as is used on PC's. SAsm will not
  2979.        work with a LF/CR or CR/LF combination. All textural output from SAsm
  2980.        such as Listing and Error files conforms to the standard Archimedes
  2981.        format of a LF terminating each line.
  2982.  
  2983.     14.If assembly appears to stop part way through check you don't have an
  2984.        #END directive before the real end. This can happen if you re-arrange
  2985.        the order of the files or if the last file is loaded out of sequence.
  2986.  
  2987.     15.Check that wildcarded filenames only apply to one file or you will
  2988.        get some files assembled twice! This can cause the previous error.
  2989.  
  2990.     16.If you have a data area and the first 'instruction' immediately
  2991.        following this is ADRL then you MUST ensure that the end of the data
  2992.        area is ALIGN'ed. Otherwise the address might be calculated from an
  2993.        'odd' base which will introduce errors.
  2994.  
  2995.     17.The Basic Tokenising routine is NOT comprehensive. It should cope
  2996.        with all simple Basic constructs of the type likely to be used in an
  2997.        assembler source file. In theory it should distinguish between AND
  2998.        and EOR when used as mnemonics or as operators. If in doubt use the
  2999.        lower case versions of the mnemonics.
  3000.  
  3001.                               Release History
  3002.                               ==============
  3003.  
  3004.     1.0     Oct. 91 First release
  3005.     1.1     Nov. 91 Functionally as 1.0
  3006.                     Bug fixes
  3007.                     X-ref and Macro Library functions re-written
  3008.     1.2     Nov. 91 Bug fixes
  3009.                     Much improved error handling
  3010.                     INCLUDE directive added
  3011.     1.21    Jan 92  Restrictions on INCLUDE directive with
  3012.                     Shareware version removed.
  3013.     1.22    Mar 92  Improved error handler
  3014.     1.23    May 92  Minor bug fixes
  3015.     1.24    June 92 Line numbering rewritten, dramatic speed increase for
  3016.                     large files
  3017.                     Line number space relocation added
  3018.     1.25    July 92 adrl, movl, div, db, dw, dd, added
  3019.                     Enhanced immediate 2nd operand
  3020.     1.26    Feb 93  Bug in adrl in some examples of 1.25 fixed.
  3021.                     No public release of this version.
  3022.     1.30    Mar 93  Expanded macros introduced.
  3023.                     db *xx,? to reserve area without setting
  3024.                     New Makelib tool for expanded macros
  3025.                     Module provided so SAsm can be run from the RMA
  3026.     1.31    Apr 93  ADRL and MOVL can be conditional
  3027.     1.32    Jun 93  Bug fixed in expanded macro stack.
  3028.     1.41    Aug 93  #obj, #lib, #errfile, #cli, #verbose, #quiet,
  3029.                     #xref and #noxref directives introduced.
  3030.                     Tab characters accepted as delimiters.
  3031.     1.42    Sep 93  Bug with DB, DD and DW in upper case fixed.
  3032.                     Bug with comment on Macro call line fixed.
  3033.                     'Line Too Long' trapped during preprocessing
  3034.     1.43    Dec 93  Expanded macro call permitted after label
  3035.                     Minor bug fixes
  3036.     1.44    Dec 93  #enhance and #noenhance directives introduced
  3037.     1.45    Dec 93  Bug in macro call with no params fixed
  3038.     1.46    Dec 93  'P' parameter introduced
  3039.                     #insert directive introduced
  3040.     1.50    Jan 94  x-ref list to file
  3041.                     x-ref bug fix with label same as opcode
  3042.                     Assembler listing file
  3043.                     Added short help text
  3044.                     SWI name processing
  3045.                     Local labels with LDR and STR
  3046.                     String variables accepted by DB
  3047.                     'Q' switch added to quit before assembly
  3048.                     'N' switch added to list label names
  3049.                     #LABELFILE to send labels to file
  3050.     1.51    Mar 94  Minor bug in #SWION fixed
  3051.                     reg! permitted without space for LDM/STM
  3052.                     More improvements to error trapping
  3053.                     DIV now included in unregistered version
  3054.     1.52    Mar 94  Filetypes Module and Utility don't need ORG
  3055.                     Bug with obj filename starting with '!' fixed
  3056.                     Added 'demo' application
  3057.  
  3058.     1.53    Mar 94  Labels now listed alpahbetically, not reverse
  3059.                     FNdb, FNdd, FNdw removed
  3060.                     #AREA directive introduced
  3061.                     Descriptive text between {and } allowed
  3062.                     OSET variable implemented
  3063.                     Bug in trapping open Error File error fixed
  3064.     1.54    Apr 94  Basic tokenising introduced with large files
  3065.                     Corrected bug with ':' in INCLUDE filenames
  3066.     1.55    Jun 94  Fixed bug which sometimes gave errors with some
  3067.                     conditional ADRL instructions
  3068.     1.56    Jul 94  dynamic memory management introduced
  3069.     1.60    Feb 95  Bug in #include introduced in 1.54 fixed
  3070.                     First line of an #AREA directive no longer needs an
  3071.                     offset
  3072.                     Missing number after a name in an #AREA is now a
  3073.                     recoverable error
  3074.                     '>' and '<' modifiers for local label introduced
  3075.     1.70    July 95 Major internal rewrite for messages.
  3076.                     #size directive can now be in the form '50K' etc.
  3077.                     !SAsm desktop front end supplied
  3078.  
  3079.  
  3080.                            Registration Form for SAsm
  3081.  
  3082.     Registration costs Ten Pounds, a laser printed Manual costs a further
  3083.     Two Pounds if required. Please post this form with your cheque to;
  3084.  
  3085.     David Holden,  39 Knighton Park Road,  Sydenham,  London SE26 5RN
  3086.     ____________________________________________________________________
  3087.     Name and Address:
  3088.  
  3089.  
  3090.  
  3091.  
  3092.  
  3093.  
  3094.  
  3095.  
  3096.  
  3097.     Do you require a printed Manual (£2 extra) -
  3098.     ____________________________________________________________________
  3099.     Where did you obtain SAsm:
  3100.  
  3101.  
  3102.  
  3103.  
  3104.  
  3105.  
  3106.  
  3107.     ____________________________________________________________________
  3108.     Have you had any problems:
  3109.  
  3110.  
  3111.  
  3112.  
  3113.  
  3114.  
  3115.  
  3116.  
  3117.  
  3118.  
  3119.     ____________________________________________________________________
  3120.     What additional features would you like:
  3121.