home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / utilities / utilss / sasm / SAsm / Manual next >
Text File  |  1993-10-25  |  105KB  |  2,229 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.       
  14.                      SSSSS     AAAA
  15.                     SS        AA  AA
  16.                      SS      AA    AA   SSSSS     mmm  mmm
  17.                       SSSS   AA    AA  SS        mm mmmm mm
  18.                          SS  AAAAAAAA   SSSSS   mm   mm   mm
  19.                          SS  AA    AA       SS  mm   mm   mm
  20.                      SSSSS   AA    AA   SSSSS   mm   mm   mm
  21.  
  22.  
  23.                                      Version 1.43
  24.  
  25.  
  26.  
  27.                       The Simple Assembler for the Archimedes
  28.  
  29.  
  30.  
  31.  
  32.                        Copyright David Holden 1991,1992,1993
  33.  
  34.  
  35.  
  36.                                _______
  37.                           ____|__     |               (R)
  38.                        --|       |    |-------------------
  39.                          |   ____|__  |  Association of
  40.                          |  |       |_|  Shareware
  41.                          |__|   o   |    Professionals
  42.                        -----|   |   |---------------------
  43.                             |___|___|    MEMBER
  44.  
  45.  
  46.  
  47.  
  48.  
  49.                                     CONTENTS
  50.                                                             Page
  51.  
  52.                    Preliminaries
  53.                          Introduction             ........   1
  54.                          Licence to Use           ........   2
  55.                          How to Register          ........   2
  56.                          Advantages of Registration ......   2
  57.                          Licence to Copy          ........   3
  58.  
  59.                    Using SAsm
  60.                          Invocation               ........   4
  61.                          Null Parameters          ........   5
  62.                          Source Filenames         ........   6
  63.                          Reconciliation of Wildcards .....   6
  64.                          Order of Assembly        ........   7
  65.                          Length of Source File    ........   8
  66.                          Line number space        .........  8
  67.                          A short demonstration    ........   9
  68.  
  69.                    The Source File
  70.                          Source File Syntax       ........   10
  71.                          Warnings and Errors      ........   10
  72.                          Comments                 ........   11
  73.                          Directives               ........   11
  74.                            #ORG                   ........   12
  75.                            #SIZE                  ........   12
  76.                            #TYPE                  ........   12
  77.                            #END                   ........   13
  78.                            #INCLUDE               ........   13
  79.                            #OBJ                   ........   14
  80.                            #LIB                   ........   14
  81.                            #ERRFILE               ........   14
  82.                            #CLI                   ........   14
  83.                            #VERBOSE               ........   14
  84.                            #QUIET                 ........   14
  85.                            #XREF                  ........   14
  86.                            #NOXREF                ........   14
  87.                          Defining registers etc.  ........   15
  88.                          Conditional Assembly     ........   15
  89.                          Assembly Loops           ........   16
  90.                          Assembly Listing         ........   16
  91.  
  92.                    Macros
  93.                          Macro Functions - Pro/Con  ......   17
  94.                          Expanded Macros - Pro/Con  ......   17
  95.                          Macro Names              ........   17
  96.  
  97.                    Expanded Macros
  98.                          Defining expanded macros ........   18
  99.                          Macro parameters         ........   18
  100.                          Local labels in macros   ........   19
  101.                          Special features         ........   10
  102.                          Examples                 ........   20
  103.                          Errors in expanded macros .......   21
  104.  
  105.  
  106.  
  107.                                     CONTENTS
  108.                                                             Page
  109.  
  110.                    Macro Functions
  111.                          General                  ........   22
  112.                          Built-in Functions       ........   22
  113.                            FNgap                  ........   23
  114.                            FNset                  ........   23
  115.                            FNadr                  ........   23
  116.                            FNdw and FNdd          ........   23
  117.                            FNdb                   ........   24
  118.                            FNmov                  ........   24
  119.  
  120.                    Extra Mnemonics
  121.                            DW and DD              ........   25
  122.                            DB                     ........   26
  123.                            ADRL                   ........   27
  124.                            MOVL                   ........   27
  125.                            DIV                    ........   28
  126.                          Enhanced 2nd Operand     ........   29
  127.  
  128.                    Labels
  129.                          Global Labels            ........   30
  130.                          Local Labels             ........   30
  131.                          Local Label Scope        ........   30
  132.                          Local Label Example      ........   31
  133.                          Forward Branch to 00     ........   31
  134.  
  135.                    The Macro Library
  136.                          Using the Macro Library  ........   32
  137.                          The 'L' parameter        ........   32
  138.                          The 'V' parameter        ........   32
  139.                          SAsm$Lib OS variable     ........   33
  140.                          Preparing a Library      ........   33
  141.                          Length of Library file   ........   34
  142.  
  143.                    SAsm and the Desktop
  144.                          New features             ........   35
  145.                          Using from the desktop   ........   35
  146.  
  147.  
  148.                          Problems                 ........   37
  149.                          Release History          ........   39
  150.                          Registration Form        ........   Endpiece
  151.  
  152.  
  153.                                                                    Page 1 
  154.  
  155.                              -=O=-  INTRODUCTION  -=O=-
  156.  
  157.       A long time ago when I found I needed more facilities than the Basic 
  158.       assembler offers I tried Acorn's AASM. My personal opinion of AASM is 
  159.       that it is overpriced, clumsy and, for many purposes, LESS powerful 
  160.       than the (free!) Basic assembler. I therefore decided to write my own, 
  161.       provisionally titled BAsm. As usual it had to be fitted in with other 
  162.       things, and meanwhile I needed an assembler. I continued to use the 
  163.       Basic assembler for short utilities and AASM for longer ones. Soon I 
  164.       found I was using AASM less and less as I gradually added bits to the 
  165.       Basic assembler to give the additional facilities I needed.
  166.  
  167.       To make life easier I wrote a 'pre-processor' for the Basic assembler 
  168.       as a stop-gap until I finished BAsm. Gradually it was improved and 
  169.       with each improvement the need for BAsm receded and work on it assumed 
  170.       a lower priority. Eventually my stop-gap program assumed a life of 
  171.       it's own and had become so powerful that it could do just about 
  172.       everything I wanted. At this point I realised it would be useful to 
  173.       others as well. I re-wrote the program, making lot's of improvements, 
  174.       and named it SASM - Simple ASseMbler for the Archimedes
  175.  
  176.       Don't be put off by the word 'Simple'. Unless you are re-writing 
  177.       Impression SAsm will probably fulfil all your needs. Simple is 
  178.       intended to describe its ease of use. Its main limitation is that it 
  179.       cannot produce output in AOF (Acorn Object Format) for linking to 'C' 
  180.       (ugh!) or other languages. If you really must write in 'C' I'm afraid 
  181.       you are stuck with AASM until I get around to finishing BAsm. It also 
  182.       cannot assemble Floating Point opcodes although you could easily add 
  183.       Macros to do this. If you really must use them (I have never found the 
  184.       need) let me know and I will try to include the facility.
  185.  
  186.       SAsm is not actually an assembler. It is a pre-processor for the Basic 
  187.       assembler. Don't worry about this. As far as the user is concerned 
  188.       SAsm works with Text source files and behaves like a 'proper' 
  189.       assembler. It has lots of facilities that the Basic assembler normally 
  190.       lacks, local labels, multi-file assembly, error reovery, etc. yet at 
  191.       the same time the syntax will be familiar to anyone who has used the 
  192.       Basic assembler. You also have the power of Basic available with its 
  193.       Mathematical, Conditional Assembly and Expression Evaluation abilities
  194.  
  195.       If you are not an expert at using the Basic assembler I suggest you 
  196.       read the file 'Tutorial'. This won't teach you to write machine code 
  197.       but it does explain how to write Macros and use Conditional Assembly 
  198.       with the Basic assembler and will help you understand SAsm better.
  199.  
  200.       Please read carefully the 'Licence to Use' and 'Licence to Copy' 
  201.       before you use/copy SAsm.
  202.  
  203.                              David Holden
  204.                              39 Knighton Park Road
  205.                              Sydenham
  206.                              London SE26 5RN
  207.                              081 778 2659
  208.  
  209.                                                                    Page 2 
  210.  
  211.                   SAsm is SHAREWARE, it is NOT Public Domain
  212.  
  213.           ssss  h   h   aaa   rrrr   eeeee  w      w   aaa   rrrr   eeeee
  214.          s      h   h  a   a  r   r  e      w      w  a   a  r   r  e
  215.           ssss  hhhhh  a   a  rrrr   eeee   w  w   w  a   a  rrrr   eeee
  216.               s h   h  aaaaa  r  r   e      w  w   w  aaaaa  r  r   e
  217.           ssss  h   h  a   a  r   r  eeeee   ww  ww   a   a  r   r  eeeee
  218.  
  219.                          -=O=-  LICENCE TO USE  -=O=-
  220.  
  221.       This program is distributed as SHAREWARE. It is NOT Public Domain. This 
  222.       means that you are only licensed to use it for a period of THIRTY DAYS. 
  223.       At the end of that time you must either stop using it or REGISTER. 
  224.       Failure to comply with this condition is a Breach of Copyright and is 
  225.       now recognised in almost all countries as an offence.
  226.  
  227.       Use of ANY version of SAsm for any TRAINING or EDUCATIONAL purposes 
  228.       without payment of the Registration Fee is ABSOLUTELY FORBIDDEN.
  229.  
  230.  
  231.                          -=O=-  HOW TO REGISTER  -=O=-
  232.  
  233.       Registration costs just Eight Pounds. I have made the last page of this 
  234.       Manual a Registration Form. Please use it when you register as it helps 
  235.       me to keep my records tidy. Fill it in, preferably adding comments, and 
  236.       post it to me. Don't forget your cheque for Eight Pounds. Write as much 
  237.       as you wish, I do take notice of comments and suggestions.
  238.  
  239.       Each assembler for the ARM processor will produce slightly different hex 
  240.       values for the same assembler mnemonics. SAsm leaves its 'fingerprints' 
  241.       on all the code produced. I can tell if a program was assembled using 
  242.       SAsm. I will take action against ANYONE who uses SAsm and distributes 
  243.       code WITHOUT REGISTRATION in breach of this licence
  244.  
  245.  
  246.              Advantages of Registration
  247.              --------------------------
  248.       The first advantage is that you will not, of course, be breaking the 
  249.       law. Registration costs just  8, so it's not exactly expensive. However 
  250.       there are some material advantages.
  251.  
  252.       When you register you will receive your personal copy of the latest 
  253.       version of SAsm which can use external Macro Libraries This enables SAsm 
  254.       to load Macros automatically during assembly. You will also receive the 
  255.       tools which will let you create Macro Libraries. This makes your code 
  256.       much simpler because you don't need to include all the macro definitions 
  257.       within it before you call them.
  258.  
  259.       You will also have the right to FREE UPDATES. Once you have registered 
  260.       you can send a disc to me with a stamped, self addressed label at any 
  261.       time for a copy of the latest version. To take advantage of this offer 
  262.       you MUST include on the disc a copy of your personal copy of SAsm.
  263.  
  264.       You will also be entitled to free or very low cost upgrades to any 
  265.       future assemblers for the Archimedes that I produce, even if these are 
  266.       not part of the SAsm 'family'. 
  267.  
  268.                                                                    Page 3 
  269.  
  270.                          -=O=-  LICENCE TO COPY  -=O=-
  271.  
  272.       If you are a Sysop or running a P.D. or Shareware library PLEASE READ 
  273.       THIS SECTION CAREFULLY.
  274.  
  275.  
  276.       1.   The Author retains full copyright to this program and all 
  277.            the material associated with it.
  278.  
  279.       2.   Any private individual is permitted to GIVE copies of SAsm 
  280.            to his/her friends. Only P.D. or Shareware libraries and BBS 
  281.            which have been given specific permission by the author to 
  282.            do so are permitted to distribute SAsm. Any distribution by 
  283.            any organisation or for any reward whatsoever whether in fee 
  284.            or in kind without this permission is strictly forbidden and 
  285.            will be treated as a Breach of Copyright, even if this fee 
  286.            is merely intended to cover media cost.
  287.  
  288.       3.   You may not make any changes to the program or documentation 
  289.            and you must include the Source directory and its contents 
  290.            and the Tutorial and Manual files.
  291.  
  292.       4.   You may not make any charge for this program or for any 
  293.            additional material you might supply. You may charge a 
  294.            reasonable fee to cover copying, media, postage etc.
  295.  
  296.       5.   You may not under any circumstances distribute copies of any 
  297.            version of SAsm which is available only to registered users 
  298.            who have paid the registration fee. This version can ALWAYS 
  299.            be distinguished because it displays the name of the 
  300.            registered user after the copyright message whereas the 
  301.            version which may be freely distributed displays the word 
  302.            'UNREGISTERED'.
  303.  
  304.       6.   You must not distribute any version of the 'MakeLib' 
  305.            application. This is for the use of Registered users ONLY.
  306.  
  307.  
  308.  
  309.  
  310.       If you have any problems or suggestions for improvements to SAsm please 
  311.       write or phone. If you write with an enquiry please enclose an SAE. If 
  312.       you prefer to telephone I am normally available on weekday evenings.
  313.  
  314.  
  315.                                David Holden
  316.                                39 Knighton Park Road
  317.                                Sydenham
  318.                                London SE26 5RN
  319.  
  320.                                081 778 2659
  321.                                                                    Page 4 
  322.  
  323.                                -=O=-  USING SASM  -=O=-
  324.  
  325.       SAsm is a 'Transient' program. This means that when it is invoked by 
  326.       typing it's name at the OS '*' prompt it is loaded from disc and Run. 
  327.       This is not normally a problem because SAsm is quite compact, about 
  328.       16K. If you have a hard disc put SAsm in your Library directory. If you 
  329.       have only a single floppy drive then copy SAsm to each working disc, it 
  330.       won't take up much disc space.
  331.  
  332.       From version 1.30 onward you will find two versions of SAsm on the 
  333.       distribution disc. One is the transient application and this is 
  334.       probably the best way to use SAsm if you have a hard disc as you can 
  335.       simply copy it to your Library directory and it will automatically Run 
  336.       whenever you type its name. The other version is a Relocatable Module 
  337.       called SAsmMod. This will be the preferred method if you don't have a 
  338.       hard disc. Just load the Module by double-clicking on it and it will 
  339.       then run from the RMA whenever you type 'SASM' in exactly the same way 
  340.       as the transient program runs from disc.
  341.  
  342.       Note that the Module version of SAsm does NOT actually run from the 
  343.       RMA. When you invoke it the program code is copied down to &8000 and 
  344.       run from there. It will therefore have the amount of RAM available that 
  345.       you have set for the 'Next Slot' in the Task window.
  346.  
  347.       The full syntax of the command string for SAsm is;
  348.  
  349.       SASM <source file list> [object filename] [error filename] [L] [X] [V]
  350.  
  351.       Only <source file list> is compulsory, the others are optional.
  352.  
  353.       This means after *SASM leave one or more spaces and then type the name 
  354.       of your source file(s). You can have as many as you like, separated by 
  355.       commas. The full meaning of <source file list> is quite complex and for 
  356.       the complete explanation read the section titled 'Source Filenames'.
  357.  
  358.       After the source file(s) leave a space then type the name of the Object 
  359.       File. This is the name that will be given to your assembled code when 
  360.       it is saved. If you don't type an Object Filename SAsm will assemble 
  361.       all the files but won't save the finished product. It may seem strange 
  362.       that you should wish to do this but if you just want to check for 
  363.       errors or find out how long the finished code is it can be useful.
  364.  
  365.       The next parameter is the name of the Error File. Unlike the Basic 
  366.       assembler SAsm will display an error message and try to continue if it 
  367.       finds an error in your code. If you have a lot of errors the first ones 
  368.       will soon scroll off the screen and get lost. If you type a name for an 
  369.       error file all these error messages will be sent to a file and you can 
  370.       load them into one window of your Editor with the source code in 
  371.       another so that you can easily find and correct them.
  372.  
  373.       If you type a letter 'X' after the error filename SAsm will cross 
  374.       reference (X-ref) all labels in your source as it loads the files and 
  375.       report any duplicates. If a duplicate is found a warning message will 
  376.       be displayed with the name of the label and the file and line number in 
  377.       which it occurs. You can include this parameter each time but normally 
  378.       it is only needed the first time you link all your files as sometimes a 
  379.       duplicate label is perfectly valid. For example I often use 'loop' or 
  380.                                                                    Page 5 
  381.  
  382.       'bak' repeatedly and don't want a screen full of warnings.
  383.  
  384.       If you type the letter 'L' then SAsm will NOT try to load any Macro 
  385.       definitions from the Library, even if one exists. See the section on 
  386.       the Macro Library for an explanation of this.
  387.  
  388.       The 'V' parameter is used to make SAsm 'verbose' when loading Expanded 
  389.       Macros from a Library. As each macro is loaded it's name will be 
  390.       displayed. This is not normally needed but the facility has been 
  391.       included in case you want to check whether SAsm is using a macro 
  392.       defined in the file or one in the Library.
  393.  
  394.       You can of course use both more than one of these separated by spaces.
  395.  
  396.       From version 1.40 all of these parameters (except of course the first 
  397.       file name) can be defined within the source file. You will normally 
  398.       therefore need only to type '*SASM <filename>' to assemble even the 
  399.       most complex project.
  400.  
  401.  
  402.                Null Parameters
  403.                ---------------
  404.       You will notice that these names must appear in order. So what do you 
  405.       do if you want an error file but no object file?, or a X-ref but no 
  406.       Error or Object file? If these are defined within the source there is 
  407.       no problem but for a simple single-file source you may not want to be 
  408.       bothered with this so SAsm accepts the ~ character or any filename 
  409.       beginning with ~ as the equivalent of no filename. For example, to 
  410.       assemble the source file 'My_Prog' without producing an object file but 
  411.       listing all the errors in the file 'Errors' you would type;
  412.  
  413.          *SASM  MyProg  ~  Errors
  414.  
  415.       I anticipate that a version of SAsm with a complete desktop 'front end' 
  416.       will appear in the near future but for the present can run it from 
  417.       within 'Task' window if you wish. This will be described later.
  418.  
  419.                                                                    Page 6 
  420.  
  421.  
  422.                Source Filenames
  423.                ----------------
  424.       The source filename list can be a single filename or a series of names 
  425.       separated by commas. Most users will probably use a 'make' file with 
  426.       'INCLUDE' filenames to assemble a complicated project but you should 
  427.       understand the full command line syntax ensure that you know exactly 
  428.       how SAsm operates with wildcarded filenames. 
  429.  
  430.       To assemble the files Start, Middle and End in that order into the 
  431.       object file Code you would use;
  432.  
  433.          *SASM  Start,Middle,End  Code
  434.  
  435.       This assumes the files are all in the Currently Selected Directory 
  436.       (CSD). Each filename can of course have a path as well. If you have 
  437.       some standard sub-routines called Subs in directory $.Source.Routines 
  438.       you could use;
  439.  
  440.          *SASM  Start,Middle,$.Source.Routines.Subs,End  Code
  441.  
  442.       SAsm loads the files in the order in which you type their names and 
  443.       treats them as if they were one big file. You can therefore break your 
  444.       source up into small chunks and sub routines which can be easily edited 
  445.       and tested. You will soon find you acquire lots of standard routines 
  446.       which you want to assemble with your program. The easiest way to avoid 
  447.       all this typing is to program a function key with the command. For the 
  448.       previous example if you type;
  449.  
  450.          *Key 5 *SASM Start,Middle,$.Source.Routines.Subs,End Code|M
  451.  
  452.       you need only press F5 to assemble your code. This saves the repetitive 
  453.       typing but as the length of this is limited to 255 characters by the OS 
  454.       it may not be enough to accommodate a list of path/filenames. SAsm 
  455.       therefore accepts wildcards in the source file list.
  456.  
  457.  
  458.                Reconciliation of Wildcards
  459.                ---------------------------
  460.       At first it might seem no 'filtering' of wildcards in filenames is 
  461.       necessary. If you put all the source files in sub-directory 'Source' of 
  462.       the CSD then typing  *SASM  Source.*  Code would assemble them all into 
  463.       the object file Code with no problems. In real life things aren't that 
  464.       simple. For example, suppose that you wish to make an alteration to one 
  465.       of your source files but keep the original in case the change doesn't 
  466.       work (always to be advised!). You make your alterations, change the 
  467.       name of your original, and then assemble the code. The only problem is 
  468.       that SAsm would assemble BOTH files, the original AND the new. You 
  469.       could of course avoid this problem by moving the original to another 
  470.       directory but this would soon become very tedious.
  471.  
  472.       SAsm has a rigid system of deciding which files to assemble. This was 
  473.       designed to work with the way I write my source files. If you don't 
  474.       like it let me know and I will try to accommodate your preferences but 
  475.       please try my way first, it's the result of a lot of experience and you 
  476.       might find you like it.
  477.                                                                    Page 7 
  478.  
  479.  
  480.       SAsm works it's way through the list in order. It first finds all the 
  481.       names which fit the wildcarded first name in your file list.
  482.  
  483.       SAsm now rejects any file that doesn't have a filetype of 'Text' (FFF) 
  484.       or 'Data' (FFD). This avoids trying to load a previous object file or 
  485.       other program file if this was saved to the same directory. As all text 
  486.       editors on the Archimedes save output as 'Text' by default this should 
  487.       not be a problem. Data files are accepted because I sometimes use other 
  488.       tools to create screens, sprites, etc. and when these are saved I set 
  489.       the filetype to Data so I know what they are. You may also wish to use 
  490.       window definitions created with !FormEd and these can be included in 
  491.       the same way. If you get a 'File not found' error but you can see the 
  492.       file exists it is probably because its filetype is not &FFF or &FFD.
  493.  
  494.       The remaining files which fit the wildcard name are then examined and 
  495.       loaded IN ALPHABETICAL ORDER. Any file which has a digit 0-9 at the end 
  496.       of its name is examined and if it has the same name as the previous 
  497.       file but with a different number it is ignored.
  498.  
  499.       What this means is that if you give all your source files a name ending 
  500.       in a number the file with the LOWEST number will be loaded and the rest 
  501.       ignored. This works because the lowest number is also the first 
  502.       alphabetically. I start out at 99 and work my way down, so each version 
  503.       is progressively called Name_99, Name_98, Name_97 etc. This system 
  504.       operates beautifully with TWIN (Acorns programmers text editor) because 
  505.       if I type 'Name*' as the filename to load into TWIN it will load the 
  506.       one with the lowest number, ie. the latest. If you use Edit to write 
  507.       source files then the latest version will always be the first file in 
  508.       the directory viewer.
  509.  
  510.       When all the files with names which fit a wildcarded filename have been 
  511.       loaded SAsm will get the next name on the list and so on until all the 
  512.       names have been dealt with.
  513.  
  514.  
  515.                Order of Assembly
  516.                -----------------
  517.       Remember that SAsm assembles the files which can be matched to each 
  518.       wildcarded name alphabetically. To return to the previous list with 
  519.       'Start, Middle and End' if you use '*' to match all of these files then 
  520.       they will be assembled in the order 'End, Middle, Start' which is not 
  521.       what is required. As it is normally only the first and sometimes last 
  522.       files whose order is important it is fairly easy to ensure that they 
  523.       are assembled in the correct order by placing an extra digit at the 
  524.       start of the name if necessary. For example renaming the files 'aStart, 
  525.       Middle, zEnd' would ensure that they are assembled in the correct order 
  526.       while retaining meaningful names.
  527.  
  528.       Since SAsm expands and reconciles wildcarded filenames in this way you 
  529.       don't need any complicated 'make' utilities to assemble a long list of 
  530.       source files. In fact the additional facilities offered by the INCLUDE 
  531.       directive make this even simpler.
  532.  
  533.                                                                    Page 8 
  534.  
  535.  
  536.                Length of Source Files
  537.                ----------------------
  538.       Because SAsm loads all the files into memory at once in might seem that 
  539.       the total length of these files could not exceed the usual 640K (or 
  540.       whatever you have set 'Next Slot' to) which is available when you press 
  541.       F12. In fact this is not the case. As SAsm loads each file it removes 
  542.       all the spare spaces and assembler comments. If, like me, you indent 
  543.       every line and use lots of comments you will probably find your source 
  544.       files shrink to about 50% of their original size. Even allowing for the 
  545.       memory required for variables, the assembler commands etc. you should 
  546.       find that SAsm can load over 1MB of source with the usual 640K slot. If 
  547.       you are writing programs which need more than this then perhaps you 
  548.       should be writing your own assembler and trying to sell it to me!
  549.  
  550.  
  551.                Line number space
  552.                -----------------
  553.       When the pre-processed code is passed to the Basic assembler it must be 
  554.       given line numbers so that Basic can understand it. This means that 3 
  555.       bytes must be added to the start of each line. If there is not enough 
  556.       room for this SAsm will attempt to relocate the file in memory, and a 
  557.       message to this effect will be displayed. This is unlikely to happen 
  558.       unless you are writing code with more than about 9000 lines.
  559.  
  560.       It is possible that there simply isn't enough RAM available for 
  561.       relocation and in this case SAsm will be unable to continue. If this 
  562.       happens there are two possible solutions. The simplest is to make more 
  563.       RAM available. Bring up the Task Manager window on the desktop and 
  564.       increase the size of the 'Next Task' allocation. On a 1Mb machine you 
  565.       may need to 'kill off' some tasks to be able to do this.
  566.  
  567.       If you cannot make more RAM available you will need to reduce the 
  568.       number of lines in your source file. There is no point in removing 
  569.       comments, column indents etc. because by the time this error occurs 
  570.       they will all have been stripped by SAsm anyway.
  571.  
  572.                                                                    Page 9 
  573.  
  574.                A short demonstration:
  575.  
  576.       Copy the file SAsm and the complete 'Source' directory to a blank disc 
  577.       in drive 0. Now press F12 to leave the desktop and type 'MOUNT 0' at 
  578.       the OS '*' prompt. To assemble the demonstration program type;
  579.  
  580.                SASM  Source.H*  Hello
  581.  
  582.       The disc drive will start and after the SAsm copyright line you should 
  583.       see the messages;
  584.  
  585.                Loading Source Files:
  586.                Source.Hello_A
  587.                Source.Hello_B
  588.                Source.Hello_C_50
  589.                Pre-processing completed - starting assembly
  590.  
  591.                Pass 1
  592.  
  593.                Pass 2
  594.                
  595.                0 Errors
  596.                Code &xx bytes - Saved as 'Hello'
  597.  
  598.  
  599.       If you now type 'CAT' you will find that a new file 'Hello' has 
  600.       appeared on the disc. To run this program, which simply displays a 
  601.       couple of messages, just type 'Hello'.
  602.  
  603.       If you examine the contents of the directory Sources you will find that 
  604.       as well as  Hello_A, Hello_B and Hello_C_50 (and several other files) 
  605.       there is Hello_C_52. Since this file has a higher number than 
  606.       Hello_C_50 it was ignored.
  607.  
  608.       Now repeat the exercise but hold down the SHIFT key when you press 
  609.       RETURN after entering the SAsm command line as previously. Everything 
  610.       will seem as before but this time when you type *Hello to RUN the 
  611.       Object code some of the messages will be different. This is a simple 
  612.       example of Conditional Assembly, some of the code being changed if the 
  613.       SHIFT key is held down during asssembly.
  614.  
  615.       I suggest that you load these three files into Edit and examine them. 
  616.       They are not a good example of compact or well written code but they do 
  617.       illustrate the layout of a multiple SAsm source file. You will notice 
  618.       the use of the Conditional Assembly section which produces the two 
  619.       different versions. Note also that branch instructions can be used to a 
  620.       label in another file demonstrating that labels are global.
  621.  
  622.       You will also see the use of a macro 'print_string'. This would be more 
  623.       efficiently coded using OS_Write0 but it illustrates how Macros are 
  624.       written and used.
  625.  
  626.       The other files 'Local' and 'Immed' are examples to illustrate the use 
  627.       of local labels, SAsm's simplified immediate 2nd operand instructions 
  628.       and Expanded Macro's. These may be assembled and examined in a similar 
  629.       manner.
  630.                                                                    Page 10 
  631.  
  632.                           -=O=-  THE SOURCE FILE  -=O=-
  633.  
  634.  
  635.                Source file Syntax
  636.                ------------------
  637.       I assume that the reader is familiar with the Basic Assembler. 
  638.       Reference will be made to it and attention drawn to differences between 
  639.       it and SAsm where they occur. Although the syntax used by SAsm is 
  640.       similar to the Basic Assembler this applies only to the actual assembly 
  641.       language itself. You can forget about square brackets, OPT, P%, O% and 
  642.       all the things that are necessary before you can use the Basic 
  643.       Assembler. The biggest change is that if you have previously used the 
  644.       Basic Editor the source files for SAsm, like all assemblers, are TEXT 
  645.       files and must NOT have line numbers.
  646.  
  647.       One of the nice features of SAsm is this similarity. This isn't an 
  648.       accident. Firstly SAsm actually uses the Basic assembler to do much of 
  649.       the work. Secondly it was designed from the start to be a 'step up' 
  650.       from the Basic assembler so even it's most advanced features will be 
  651.       very quickly mastered by anyone who is familiar with the Archimedes 
  652.       'built-in' assembler.
  653.  
  654.       You won't therefore need to spend ages learning a whole new language 
  655.       and you will be able to convert your old assembler programs into SAsm 
  656.       format very easily and quickly. Normally this takes only a few minutes 
  657.       with a straightforward program.
  658.  
  659.       Throughout this Manual reference will be made to the 'hash' character 
  660.       '#' which is the character on the key at the top right hand corner of 
  661.       the numeric keypad. If that appeared in your  printout as a  pound sign 
  662.       then your printer is set to the English character set so you will just 
  663.       have to read the file as if it had printed a hash. There are no pound 
  664.       characters in this Manual.
  665.  
  666.  
  667.                Warnings and Errors
  668.                -------------------
  669.       In the following sections reference will be made to Warnings, Errors 
  670.       and Fatal Errors.
  671.  
  672.       Warnings are issued if SAsm finds you have omitted or wrongly placed a 
  673.       directive. The code will still be assembled and saved. Warnings will 
  674.       not be written to the Error file.
  675.  
  676.       Errors are faults from which SAsm can recover but which make the code 
  677.       useless. Unlike the Basic assembler SAsm will try to continue after 
  678.       reporting an error as there may be others to report, but the assembled 
  679.       code will not be viable so no Object file will be produced.
  680.  
  681.       If SAsm reports an error in the first pass it will not attempt a second 
  682.       pass. You may therefore need two attempts to correct all the errors.
  683.  
  684.       A Fatal Error is an error from which SAsm cannot recover or which is so 
  685.       serious that there is no point in continuing. An error in a Macro 
  686.       Function or a missing file are examples of Fatal Errors.
  687.                                                                    Page 11 
  688.  
  689.                Comments
  690.                --------
  691.       SAsm defines a comment as EVERYTHING on a line after a semi-colon ';' 
  692.       or a backslash '\'. SAsm therefore conforms to the syntax used by most 
  693.       assemblers which differs from the Basic assembler. The Basic assembler 
  694.       is almost unique in using the colon ':' as a statement delimiter. While 
  695.       SAsm still recognises ':' and allows more than one mnemonic on a line 
  696.       Basic regards ':' as the end of a comment and tries to assemble 
  697.       anything on the line after a ':', even if the ':' is in a comment. For 
  698.       example the following line using the Basic assembler;
  699.  
  700.           mov r1,#0 : \ mov r1,#1 : mov r2,#2
  701.  
  702.       would be assembled as  mov r0,#0  followed by  mov r2,#2  The middle 
  703.       instruction would be ignored because Basic recognises the '\' and 
  704.       regards it as a comment but continues assembling when it finds the ':' 
  705.       later in the line. Using SAsm you would get ONLY  mov r1,#1  as 
  706.       everything on the line after the '\' is a comment.
  707.  
  708.       The exception to this is where a semi colon (;) is not preceded by a 
  709.       space in a line which is to be passed to Basic. This has been done so 
  710.       that you can use ';' in PRINT statements to display information during 
  711.       assembly. If you do use ';' in a Basic line to define a comment make 
  712.       sure that it is preceded by a space or it will cause an error.
  713.  
  714.  
  715.                Directives
  716.                ----------
  717.       It is possible to include 'Directives' in your source. In fact some 
  718.       directives are necessary for the proper operation of SAsm. Any line in 
  719.       which the first non-space character is '#' is a directive. This 
  720.       character was chosen because it will be familiar to most programmers 
  721.       who have used 'C'. If SAsm doesn't recognise what immediately follows 
  722.       the '#' it will assume it is a valid Basic statement and so the line 
  723.       after the '#' will be passed to Basic.
  724.  
  725.       You can use SAsm without any preliminary directives in your source 
  726.       file. Unlike the Basic assembler you can begin by writing mnemonics 
  727.       straight away. If you do this SAsm will start assembling your code to 
  728.       run from '0000'. This doesn't matter as SAsm will normally produce 
  729.       position independent code unless you have included specific references 
  730.       to addresses within your source.
  731.  
  732.       The '#' character can have spaces before and after it to improve 
  733.       legibility if you wish, they will be ignored by SAsm, but it MUST be 
  734.       the first non-space character on the line. Directives should be the 
  735.       only item on the line although you may include comments if you wish.
  736.  
  737.       All directives are case insensitive. Where a directive is to be passed 
  738.       to Basic it's case and syntax must conform to that required by Basic. 
  739.       Where a comment is included in a directive which is to be passed to 
  740.       Basic it can still be preceded by ';' or '\' rather than REM, but see 
  741.       the note under 'Comments' above.
  742.  
  743.       There must be at least one space after a directive where it is followed 
  744.       by one or more parameters.
  745.  
  746.                                                                    Page 12 
  747.  
  748.                #ORG
  749.  
  750.       This defines the address the code will be assembled to run at. The 
  751.       syntax is  # ORG <number> where <number> is a valid address. If 
  752.       <number> is in hex, as it normally will be, it should be preceded by 
  753.       the '&' character. If no #ORG directive is found assembly will start at 
  754.       location 0 and a warning message will be displayed.
  755.  
  756.       The #ORG directive must obviously appear BEFORE the first assembler 
  757.       statement. If an #ORG directive is found after the first assembler 
  758.       statement a warning message will be displayed and the code will be 
  759.       assembled to start at location 0.
  760.  
  761.       There must be at least one space between the word 'org' and the number 
  762.       which follows. This applies to all the following directives.
  763.  
  764.       Note - ORG replaces the ADDR directive used in early versions. ADDR is 
  765.       still supported for backwards compatibility but ORG should be used in 
  766.       all new work as ADDR may be dropped in the future.
  767.  
  768.  
  769.                #SIZE
  770.  
  771.       This advises SAsm of the expected size of the code so it can reserve a 
  772.       large enough buffer for the assembled code. The full syntax is #SIZE 
  773.       <number> where <number> is the estimated maximum size of the code. if 
  774.       <number> is in hex it should be preceded by a '&' character.
  775.  
  776.       If there is no #SIZE directive before the first assembler statement a 
  777.       warning will be given and 64K will be allocated for the code. Any #SIZE 
  778.       directives after the first assembler statement will be ignored.
  779.  
  780.  
  781.                #TYPE
  782.  
  783.       This defines the filetype you wish your assembled code to have. Syntax 
  784.       is #TYPE <filetype> where <filetype> is a valid Archimedes filetype. If 
  785.       <filetype> is a number it should be in hex, though it need not be 
  786.       preceded by a '&' character. If it is a text representation of a 
  787.       filetype it must be in quotes, for example;
  788.  
  789.                                # type FF8
  790.                                # type "Absolute"
  791.  
  792.       If you do not include #TYPE the assembled code will be saved as an 
  793.       absolute block of memory with no filetype.
  794.  
  795.       Unlike the previous examples #TYPE can appear anywhere in the source. 
  796.       If more than one #TYPE directive appears the last one will be used.
  797.  
  798.       The most common filetypes are &FFC for a position independent Utility, 
  799.       &FF8 for an Application to be loaded and Run at &8000 and &FFA for a 
  800.       Relocatable Module.
  801.  
  802.       The upper case versions of these, namely ORG, ADDR, TYPE and SIZE, are 
  803.       reserved words and must not be used as variables anywhere in your code.
  804.  
  805.                                                                    Page 13 
  806.  
  807.                #END
  808.  
  809.       This directive, which takes no parameters, should be placed at the end 
  810.       of your assembler and before any Macro Function definitions. Anything 
  811.       after #END will be passed to Basic without the need for a '#' at the 
  812.       beginning of the line. When SAsm finds #END it assumes it has reached 
  813.       the end of the code and everything else is Macro Function definitions
  814.  
  815.       If DEFFN is found at the start of a line indicating that a Macro 
  816.       Function definition has been found before an #END directive a warning 
  817.       will be given and all subsequent lines will be passed to Basic.
  818.  
  819.  
  820.                #INCLUDE
  821.  
  822.       This allows additional files to be 'included' as well as the ones 
  823.       specified at the command line. The word INCLUDE should be followed by 
  824.       at least one space and then a single filename. Unlike files loaded from 
  825.       the command line only the first file which matches the required name 
  826.       will be used and no checks will be made on its filetype.
  827.  
  828.       The INCLUDE directive in SAsm is different to its equivalent in 'C'. 
  829.       SAsm does NOT 'insert' the file at the point at which the directive 
  830.       occurs. Instead it creates a 'queue' of any INCLUDE filenames it finds. 
  831.       When it reaches the end of the current file it goes to this list and 
  832.       loads the first name in the queue. When that file has been dealt with 
  833.       it loads the next name and so on until the queue is empty. If one of 
  834.       the 'include' files contains more INCLUDE directives these names are 
  835.       added to the END of the queue. When the queue is empty SAsm returns to 
  836.       the filenames specified at the command line and carries on as before. 
  837.       INCLUDE files can therefore have further INCLUDE directives which files 
  838.       can contain their own INCLUDEs and so on.
  839.  
  840.       If you have a complex program which consists of a lot of small pieces 
  841.       of code and sub-routines you can create a 'master' file which will 
  842.       contain the #ORG, #TYPE etc. directives and then a list of #INCLUDE 
  843.       directives to define the files required to make up the program. This 
  844.       operates in the same way as 'Make' files for other assemblers and 
  845.       compilers. SAsm will simply load each INCLUDE file in your 'primary' 
  846.       file in the order in which you have listed them. As INCLUDE files are 
  847.       subject to similar discrimination to filenames typed at the command 
  848.       line the 'trailing number suffix' system can be used to assemble the 
  849.       latest versions.
  850.  
  851.       For example, a file containing just the following would assemble the 
  852.       named files with the lowest trailing numbers in the chosen order.
  853.  
  854.                                # org      &8000
  855.                                # type     "Absolute"
  856.                                # size     &1000
  857.                                # include  start_*
  858.                                # include  middle_*
  859.                                # include  end_*
  860.                                                                    Page 14 
  861.  
  862.  
  863.                #OBJ
  864.  
  865.       This defines the name of the Object file. The syntax is #OBJ <filename> 
  866.       where <filename> can be any valid path/filename. If you type an object 
  867.       name at the Command Line it will override any #OBJ directive. You can 
  868.       therefore include an #OBJ directive in the source but assemble a 
  869.       different version if you choose by typing an Object name at the CLI.
  870.  
  871.  
  872.                #LIB
  873.  
  874.       This defines the Library file to be used. It will override any Library 
  875.       defined in the SAsm$Lib variable. Using #LIB without a filename will 
  876.       force SAsm NOT to use a Library and so is equivalent to the 'L' switch.
  877.  
  878.  
  879.                #ERRFILE
  880.  
  881.       Defines the error filename to be used. Again any error filename typed 
  882.       at the command line will override this directive.
  883.  
  884.  
  885.                #CLI
  886.  
  887.       Anything on the line after this directive will be passed DIRECTLY to 
  888.       the Archimedes operating system CLI. It can be regarded as equivalent 
  889.       to a '*' command as used in a Basic program. It is not like the 'OSCLI' 
  890.       command in Basic as no substitution is carried out first. You should 
  891.       not put any comments on the line after a #CLI directive.
  892.  
  893.  
  894.                # VERBOSE
  895.  
  896.       Equivalent to the command line 'V' switch to force display of names of 
  897.       macros inserted from a Library. The advantage over the 'V' command line 
  898.       switch is that it can be inserted at any point and so need not show all 
  899.       the expanded macros, only those used after the directive is used.
  900.  
  901.  
  902.                # QUIET
  903.  
  904.       Switches off display of macro names. You can use this with 'verbose' as 
  905.       often as you wish to switch on and off display of expanded macro names.
  906.  
  907.  
  908.                #XREF
  909.  
  910.       Switches on label cross reference. Once again the advantage of this 
  911.       over the 'X' switch is that it only takes effect from the point at 
  912.       which it appears.
  913.  
  914.  
  915.                #NOXREF
  916.  
  917.       Switches off label cross reference. Can be used as often as required 
  918.       with the previous command to toggle x-ref on and off.
  919.                                                                    Page 15 
  920.  
  921.                Defining Registers etc
  922.                ----------------------
  923.       In order to simplify writing code it is normal to give the C.P.U. 
  924.       registers names. In Basic this is done by assigning the chosen name a 
  925.       number using the syntax  <name>=<number>. The same method is used with 
  926.       SAsm except that you must precede your definitions with '#'.
  927.  
  928.       For example, to define register 5 as 'count' and register 6 as 'flag'
  929.  
  930.                                # count = 5
  931.                                # flag = 6
  932.  
  933.       or alternatively
  934.  
  935.                                # count=5:flag=6
  936.  
  937.       You can use this method to define SWI's, offsets in a data area, in 
  938.       fact anything you wish. Since these are normal Basic variables you can 
  939.       use integer and string variables if required.
  940.  
  941.       R13,R14 and R15 are pre-defined as 'sp', 'link' and 'pc' in upper and 
  942.       lower case as these are the normal definitions for these registers.
  943.  
  944.       All registers are pre defined as their equivalent 'r' and 'R' numbers. 
  945.       Basic doesn't recognise a number like 'r4' as meaning register number 4 
  946.       except when it is an assembler operand. If you try to pass 'r4' as a 
  947.       parameter an error would be generated. With SAsm you can use r0-r15 or 
  948.       R0-R15 as they have been pre defined.
  949.  
  950.  
  951.                Conditional Assembly
  952.                --------------------
  953.       This works as with the Basic assembler, normally using  IF THEN, 
  954.       (ELSE), ENDIF.  If you are unfamiliar with this technique please read 
  955.       the 'Tutorial' file which explains it.
  956.  
  957.       With SAsm there is no need to bother with assembler brackets, etc. Just 
  958.       put '#' in front of the lines which form the conditional block.
  959.  
  960.                # IF <condition> THEN
  961.                   .........            ; some code
  962.                   .........
  963.                   .........
  964.                # ELSE
  965.                   .........            ; the alternative code
  966.                   .........
  967.                   .........
  968.                # ENDIF
  969.  
  970.       Don't forget the 'THEN' at the end of the 'IF' line. The 'ELSE' section 
  971.       is of course optional.
  972.  
  973.       If an error occurs in a conditional section you may find subsequent 
  974.       'ELSE found without IF' or 'ENDIF found without IF' errors occurring. 
  975.       This is not significant, it just means the assembler has 'forgotten' it 
  976.       was in a conditional section when the original error was discovered.
  977.  
  978.                                                                    Page 16 
  979.  
  980.  
  981.                Assembly Loops
  982.                --------------
  983.       When using the Basic assembler it is common to use FOR-NEXT loops to 
  984.       fill an area of memory, eg.
  985.  
  986.                ........            ;normal code
  987.                ]                   :REM exit assembler
  988.                FOR I%=0 TO 255
  989.                [ OPT PASS
  990.                EQUB &FF            ;fill 256 bytes with &FF
  991.                ]
  992.                NEXT
  993.                [ OPT PASS          ;back to assembler again
  994.                ........            ;normal code
  995.  
  996.       You could still use this method with SAsm if you wish but it is simpler
  997.  
  998.                ........            ;normal code
  999.                # FOR I%=0 TO 255
  1000.                EQUB &FF
  1001.                # NEXT
  1002.                ........            ;normal code again
  1003.  
  1004.       In fact SAsm has a much better way to fill an area of memory with a 
  1005.       value using the DB directive.
  1006.  
  1007.  
  1008.                Assembly Listing
  1009.                ----------------
  1010.       SAsm will not normally produce an assembly listing. Not only would this 
  1011.       obscure any Error or Warning messages it also slows down assembly. If 
  1012.       you need to see a part of your code to make sure that it being 
  1013.       correctly assembled then you can easily do so.
  1014.  
  1015.       Where you want the listing to begin insert a line in the source;
  1016.  
  1017.         # IF Q%=6 Q%=7
  1018.  
  1019.       and where you want the listing to end;
  1020.  
  1021.         # IF Q%=7 Q%=6
  1022.  
  1023.       This will produce a screen listing during the second pass between these 
  1024.       two lines.
  1025.  
  1026.                                                                    Page 17 
  1027.  
  1028.                                -=O=-  MACROS  -=O=-
  1029.  
  1030.       Sasm supports two types of Macros. Expanded Macros and Macro Functions. 
  1031.       There are advantages and disadvantages with each type. Both can be 
  1032.       included in your Macro Library.
  1033.  
  1034.  
  1035.                Macro Functions - Pro/Con
  1036.                -------------------------
  1037.       These are normal Basic Functions and their use and format is fully 
  1038.       described in the 'Tutorial'. They have two disadvantages. Firstly 
  1039.       because they are Basic Functions you must include assembler brackets, 
  1040.       OPT setting, etc. and forward branches are awkward. Secondly it is not 
  1041.       possible to use any of the special features of SAsm such as local 
  1042.       labels, db, adrl, movl, etc. within a Macro Function. Also you cannot 
  1043.       call or define an Expanded Macro from within a Macro Function.
  1044.  
  1045.       A serious disadvantage is that SAsm cannot recover from an error in a 
  1046.       Macro Function. Such errors are always Fatal and will produce an error 
  1047.       message giving a line number that does not exist in the file.
  1048.  
  1049.       The first advantage is that this type of macro is not 'expanded' by the 
  1050.       pre processor so that no matter how many times you call it it doesn't 
  1051.       take any more memory. The second advantage is a consequence of this and 
  1052.       will only apply if you use a Macro Library without a hard disc. This is 
  1053.       because a Macro Function only appears once, at the end of the code, and 
  1054.       so only one disc access to load it from the Library will be required.
  1055.  
  1056.  
  1057.                Expanded Macros - Pro/Con
  1058.                -------------------------
  1059.       These are short sections of code which are physically inserted into the 
  1060.       file each time the Macro is invoked. The big advantage with this method 
  1061.       is that you can use all the special features of SAsm, local labels, 
  1062.       etc. You can also call Macro Functions or other Expanded Macros from 
  1063.       within this type of macro.
  1064.  
  1065.       Because Expanded Macros become part of the normal code SAsm can 
  1066.       normally recover from errors in them in the same way as it can recover 
  1067.       from most other errors.
  1068.  
  1069.       The disadvantage is that an Expanded Macro must be defined before it is 
  1070.       used, although it can be defined in your Macro Library. Also as the 
  1071.       macro code is inserted into your source each time it is used more 
  1072.       memory is required although it is unlikely to be a problem in practice.
  1073.  
  1074.  
  1075.                Macro Names
  1076.                -----------
  1077.       Because Macro Functions and Expanded Macros are completely different 
  1078.       they can have the same name. You can even have Expanded Macros and 
  1079.       Macro Functions with the same name in your Library. SAsm will sort out 
  1080.       which to use.
  1081.  
  1082.                                                                    Page 18 
  1083.  
  1084.  
  1085.                        -=O=-  EXPANDED MACROS  -=O=-
  1086.  
  1087.  
  1088.       An Expanded Macro must be defined before it is used. If you are using a 
  1089.       Macro Library it can be defined in the Library and SAsm will then load 
  1090.       it from there.
  1091.  
  1092.       If you have defined a macro in your source file and one of the same 
  1093.       name exists in the Library then the macro in the source file will be 
  1094.       used in preference to the one in the Library.
  1095.  
  1096.  
  1097.                Defining Macros
  1098.                ---------------
  1099.       An expanded macro is defined as follows.
  1100.  
  1101.                                # SM  <name>
  1102.                                ........                \
  1103.                                ........                 > Normal SAsm code
  1104.                                ........                /
  1105.                                # EM
  1106.  
  1107.       and invoked by -
  1108.  
  1109.                                @ <name>
  1110.  
  1111.       In both cases <name> is the name given to the macro and, with any 
  1112.       parameters, is case sensitive. As with other SAsm directives the '#' 
  1113.       used by #SM (Start Macro) and #EM (End Macro) must be the first 
  1114.       non-space characters on the line. Similarly the '@' character must be 
  1115.       the first non-space character on the line.
  1116.  
  1117.       Whenever SAsm encounters a '@' it will match the following name with 
  1118.       any previously defined macros. When it finds one it will physically 
  1119.       insert a copy of the code into the file. If there are any LOCAL labels 
  1120.       in a macro they will be unique within that definition, but all 
  1121.       non-local labels will be global.
  1122.  
  1123.  
  1124.                Macro Parameters
  1125.                ----------------
  1126.       You can pass parameters of almost any type to an Expanded Macro. The 
  1127.       full syntax of the defining line of the start of a macro is -
  1128.  
  1129.           # sm  <name> <param name 1> , <param name 2> , <param name 3> ....
  1130.  
  1131.       and of the calling line -
  1132.  
  1133.           @ <name>  <param value 1> , <param value 2> , <param value 3> ....
  1134.  
  1135.       where <name> is the actual name given to the macro, <param name> is the 
  1136.       name given to each parameter and <param value> is the value that each 
  1137.       parameter will be given when the macro is expanded.
  1138.                                                                    Page 19 
  1139.  
  1140.  
  1141.       A parameter is actually a Global Variable and should conform to the 
  1142.       variable type that Basic would use for the type of value that it will 
  1143.       hold. It can be an Integer, String or Floating Point variable. 
  1144.       Similarly the parameter passed must be suitable for that type of 
  1145.       variable. It need not be a constant value. Any expression which can be 
  1146.       evaluated to the correct type of variable may be used.
  1147.  
  1148.       There must be at least one space between <name> and the first parameter 
  1149.       and parameters are separated by commas.
  1150.  
  1151.       In fact you will recognise that the syntax has deliberately been made 
  1152.       identical to the way that parameters are passed to Basic Functions and 
  1153.       Procedures except that there are no brackets.
  1154.  
  1155.  
  1156.                Local Labels in Expanded Macros
  1157.                -------------------------------
  1158.       You can use local labels in expanded macros and these should conform to 
  1159.       the syntax used elsewhere. You MUST start any local labels in a macro 
  1160.       definition with '00' to ensure that the labels used will be unique.
  1161.  
  1162.       When the macro expansion ends the 'flow' of local labels in the main 
  1163.       code before the macro was used will be restored. A macro, with its own 
  1164.       set of local labels, can therefore exist within the area of 'normal' 
  1165.       local labels without confusion. In practical terms this simply means 
  1166.       that provided you ensure that any local labels used in a macro start 
  1167.       with '00' you can ignore the fact that a macro exists for the purposes 
  1168.       of local labels in the main code.
  1169.  
  1170.       Similarly if expanded macros are 'nested' then any local labels defined 
  1171.       will be unique within that invocation and the labels in the 'calling' 
  1172.       macro will branch around labels in the called macro.
  1173.  
  1174.       Remember that, like all non local labels, any other labels defined in 
  1175.       an expanded macro will become global and will assume the value assigned 
  1176.       in the current invocation.
  1177.  
  1178.  
  1179.                Special features of Expanded macros
  1180.                -----------------------------------
  1181.       The most obvious advantage of expanded macros is that you can take 
  1182.       advantage of all the special features of SAsm when using them. The 
  1183.       ADRL, MOVL DB, DW and DD pseudo-ops can all be used if required.
  1184.  
  1185.       You can call Macro Functions and other Expanded Macros can be invoked 
  1186.       from within macros. Expanded Macros can be 'nested' to a maximum depth 
  1187.       of twenty. In theory this could be greater, but I couldn't think of any 
  1188.       possible (non-contrived) circumstance when I would need more than four 
  1189.       or five so I limited it to twenty.
  1190.  
  1191.       Expanded Macros must NOT be invoked recursively. This would obviously 
  1192.       set up an infinite loop which would cause all available memory to be 
  1193.       filled. This is another reason for limiting the nesting of macros 
  1194.       because if this is done by accident an error will be flagged before 
  1195.       this stage is reached.
  1196.  
  1197.                                                                    Page 20 
  1198.  
  1199.  
  1200.                Example
  1201.                -------
  1202.       This is an example of how you could use a macro to print a string at 
  1203.       any location on the screen. Note that as usual I have used more spaces 
  1204.       than are actually necessary to make things clearer.
  1205.  
  1206.           # SM   print_tab  x_pos , y_pos , display$
  1207.                  swi  256+31
  1208.                  swi  256+x_pos
  1209.                  swi  256+y_pos
  1210.                  swi  "OS_WriteS"
  1211.                  equs display$
  1212.                  equb 0
  1213.                  align    # EM
  1214.  
  1215.       The operation of the code should be obvious. Firstly there is the 
  1216.       equivalent of 'VDU 31, x_pos, y_pos' to position the text cursor where 
  1217.       required. SWI "OS_WriteS" is then used to print the text which is 
  1218.       placed in memory immediately after it.
  1219.  
  1220.       So, to print 'This is a test' at column 10, line 4 you would use
  1221.  
  1222.           @  print_tab  10,4,"This is a test"
  1223.  
  1224.       To illustrate nesting macros the following example splits this 
  1225.       procedure into two separate macros, one of which uses the other.
  1226.  
  1227.           # SM  do_tab  x , y
  1228.                 swi  256+31
  1229.                 swi  256+x
  1230.                 swi  256+y
  1231.           # EM
  1232.  
  1233.           # SM  print_tab  x_pos , y_pos , display$
  1234.                 do_tab  x_pos,y_pos
  1235.                 swi  "OS_WriteS"
  1236.                 equs display$
  1237.                 equb 0
  1238.                 align
  1239.           # EM
  1240.  
  1241.       This would be used in exactly the same way as the previous example, but 
  1242.       note that as 'print_tab' uses 'do_tab' then 'do_tab' must be defined 
  1243.       before it can be used in 'print_tab'.
  1244.  
  1245.           @  print_tab  10,4,"This is a test"
  1246.  
  1247.       Would give the same results, and in this instance the code actually 
  1248.       assembled, would be exactly the same. In fact, it could be split still 
  1249.       more. Leaving the macro 'do_tab' as previously defined;
  1250.                                                                     Page 21 
  1251.  
  1252.  
  1253.           # SM  print_string  string$
  1254.                 swi "OS_WriteS"
  1255.                 equs string$
  1256.                 equb 0
  1257.                 align
  1258.           # EM
  1259.  
  1260.           # SM  print_tab  x_pos , y_pos , display$
  1261.                 do_tab  x_pos,y_pos
  1262.                 print_string  display$
  1263.           # EM
  1264.  
  1265.       Once again exactly the same actual code would be assembled.
  1266.  
  1267.  
  1268.  
  1269.             Errors in Expanded macros
  1270.             -------------------------
  1271.       SAsm will normally be able to recover from errors in expanded macros. 
  1272.       In this case the error message will be slightly different from normal 
  1273.       and in the form;
  1274.  
  1275.       Error <error message> at line <number> in Macro <macro name> at line 
  1276.             <line number> in file <file name>
  1277.  
  1278.       The line number in the file will be the line where the macro was 
  1279.       invoked. The line number within the macro will be the offset from the 
  1280.       start of the macro where the error occurred. If this was the invoking 
  1281.       line then the error will be shown as having occurred in line 0.
  1282.  
  1283.       This can seem a bit strange if the macro invokes other macros. When the 
  1284.       error happens the macro has been expanded, so the line number may be 
  1285.       greater than the apparent size of the macro. For instance, in the final 
  1286.       example shown above if an error occurred in the line which invoked 
  1287.       'print_string' in the macro 'print_tab' the error would be shown as 
  1288.        having occurred not at line 2, but at line 5.
  1289.  
  1290.       This is not normally a problem is practice because the actual error can 
  1291.       usually be discovered by inspection but I may improve upon it in a 
  1292.       later version.
  1293.  
  1294.                                                                    Page 22 
  1295.  
  1296.  
  1297.                       -=O=-  MACRO FUNCTIONS  -=O=-
  1298.  
  1299.  
  1300.             General
  1301.             -------
  1302.       Macro Functions are defined and used exactly as in the Basic assembler. 
  1303.       If you don't know how this works I refer you to the 'Tutorial'.
  1304.  
  1305.       Briefly a Macro Function is a Basic Function who's definition, as with 
  1306.       functions in a normal Basic program, must appear after the #END 
  1307.       directive. You use it by simply writing  FN<name>, where <name> is the 
  1308.  
  1309.       name of your function, in your assembler source. Most Macro Functions 
  1310.       will require parameters and these are passed by being enclosed in 
  1311.       brackets after the function name in the usual way.
  1312.  
  1313.       You must remember when defining a Macro Function that when it is called 
  1314.       you have quit the assembler and are back in 'normal' Basic. As a macro 
  1315.       will probably include assembly code statements you will need to use the 
  1316.       square brackets and define the OPT setting to re-enter assembler.
  1317.  
  1318.       SAsm uses two variables to define the OPT setting, Q% and PASS. You can 
  1319.       therefore use either of these when defining Macro Functions. The only 
  1320.       time you need to depart from this is if you are using a forward branch 
  1321.       in the macro. In this case you will need to define a two-pass loop 
  1322.       within the macro and so you MUST define your own OPT variable. It is 
  1323.       therefore important that you should NOT modify or use in any way the 
  1324.       Basic Integer variable Q%. The only permitted use of this variable is 
  1325.       when you wish to see an assembler listing as previously described.
  1326.  
  1327.       WARNING - You cannot use the SAsm 'extra' mnemonics DB, DW, DD, DIV, 
  1328.       ADRL, MOVL or the enhanced immediate 2nd operands in Functions. These 
  1329.       are ONLY available in the main body of the code or within Expanded 
  1330.       Macros before the #END directive. You can call functions FNadr, FNmov, 
  1331.       FNdiv and FNset as alternatives if required. These will be retained in 
  1332.       later versions for this purpose.
  1333.  
  1334.       These restrictions will not be removed in later versions of SAsm since 
  1335.       whenever possible you are advised to use Expanded Macros instead.
  1336.  
  1337.                The Built-In Functions
  1338.                ----------------------
  1339.       SAsm has a number of pre-defined Macro Functions and the following 
  1340.       section describes them. Do not to use them in new work except when 
  1341.       called from within other Macro Functions as the extra mnemonics ADRL, 
  1342.       MOVL, DIV, DB, DW and DD should be used instead.
  1343.  
  1344.       As well as the functions described there are two others FNadrc and 
  1345.       FNmovc. These should not be used directly and so are not documented but 
  1346.       do not create your own functions with these names or conditional ADRL 
  1347.       and MOVL will not work correctly.
  1348.  
  1349.                                                                    Page 23 
  1350.  
  1351.                FNgap ( <size> )
  1352.                ----------------
  1353.       Defines a gap in the code for use as a data area of <size> bytes. The 
  1354.       memory is not pre set to any value. If <size> is not exactly divisible 
  1355.       by 4 and you intend to follow FNgap with an opcode you should use ALIGN 
  1356.       to ensure that further assembly occurs on a word boundry. Use 'DB' for 
  1357.       preference unless within a Macro Function.
  1358.  
  1359.  
  1360.                FNset ( <size>,<value> )
  1361.                ------------------------
  1362.       Similar to FNgap except that the memory is preset to <value>. Use the 
  1363.       DB mnemonic in preference wherever possible.
  1364.  
  1365.  
  1366.                FNadr ( <register>,<location> )
  1367.                -------------------------------
  1368.       FNadr is an expansion of the ADR pseudo-opcode. Its syntax is the same 
  1369.       except that the parameters must be enclosed in brackets. It can reach 
  1370.       any byte within 64K or within 256K if <location> falls on a word 
  1371.       boundry. If <location> is a forward reference FNadr always assembles 
  1372.       two instruction. If a backward reference FNadr assembles a single 
  1373.       instruction if possible and two only if absolutely necessary.
  1374.  
  1375.       This is equivalent to the ADRL expanded mnemonic which should be used 
  1376.       in preference.
  1377.  
  1378.  
  1379.                FNdw and FNdd
  1380.                -------------
  1381.       FNdw and FNdd (Define Word and Define Doubleword) are expansions of 
  1382.       EQUW and EQUD respectively. They preset consecutive words or double 
  1383.       words of memory with values passed as a comma separated list. The 
  1384.       syntax in each case is identical. FNdw like EQUW works with two byte 
  1385.       chunks or 'words' and FNdd like EQUD with four byte chunks or 'double 
  1386.       words'. As the Archimedes is a 32 bit computer a 'word' is really 4 
  1387.       bytes but I have retained the 'old' definitions to avoid confusion.
  1388.  
  1389.       The full syntax is FNdx ( "<value>,<value>,<value>...." ) where <value> 
  1390.       is any valid number which can be placed in the memory location. For 
  1391.       example, to place the numbers 1 to 5 in 5 consecutive double words you 
  1392.       would use;
  1393.  
  1394.         FNdd ("1,2,3,4,5")
  1395.  
  1396.       Note that the list is passed as a STRING and so must be enclosed in 
  1397.       quotes. If more than about 25 numbers are passed in a single macro a 
  1398.       'Line Too Long' error may be generated. If you use FNdw and wish the 
  1399.       following code to be word aligned you should follow it with ALIGN.
  1400.  
  1401.                                                                    Page 24 
  1402.  
  1403.  
  1404.                FNdb
  1405.                ----
  1406.       At is simplest FNdb (Define Byte) is to EQUB what FNdw and FNdd are to 
  1407.       EQUW and EQUD. You can use it to simply preset a consecutive series of 
  1408.       bytes with values. However it also doubles as an equivalent to EQUS and 
  1409.       by combining the two into a single function makes it much simpler to 
  1410.       define strings of mixed text and control codes.
  1411.  
  1412.       Like the two previous functions FNdb takes a string as it's parameter. 
  1413.       However in this case as well as comma separated values the string can 
  1414.       contain a 'string' enclosed in SINGLE quotes. For example;
  1415.  
  1416.         FNdb ("7,'This is a beep.',13,10,'This is on a new line',13,10")
  1417.  
  1418.       The normal equivalent of this would be
  1419.  
  1420.         EQUB 7
  1421.         EQUS "This is a beep"
  1422.         EQUB 13
  1423.         EQUB 10
  1424.         EQUS "This is on a new line"
  1425.         EQUB 13
  1426.         EQUB 10
  1427.  
  1428.       Naturally neither single or double quotation marks are permitted in the 
  1429.       string. If you wish them to appear in text you must use the ASCII code 
  1430.       as with control codes in the example above.
  1431.  
  1432.  
  1433.                FNmov ( <register>,<value> )
  1434.                ----------------------------
  1435.       This is an expansion of the MOV opcode to load a register with an 
  1436.       immediate value. Unlike the normal MOV this will generate sufficient 
  1437.       ADD opcodes after the initial MOV to load any 32 bit number. If <value> 
  1438.       is a negative number then MVN and SUB will be used. Note that when 
  1439.       using negative numbers you do not need to subtract 1 as you do with 
  1440.       MVN. eg. to load r3 with -123456 just use  FNmov (3,-123456)
  1441.  
  1442.       Use the MOVL mnemonic for preference unless within a Macro Function.
  1443.  
  1444.                                                                    Page 25 
  1445.  
  1446.  
  1447.                          -=O=-  EXTRA MNEMONICS  -=O=-
  1448.  
  1449.  
  1450.       These are not actually mnemonics but are macros which are expanded by 
  1451.       the preprocessor. They are written into the code just like normal 
  1452.       opcodes and so this distinction can normally be ignored. One important 
  1453.       difference is that unlike normal mnemonics they must NOT have 
  1454.       conditional suffixes.
  1455.  
  1456.       Some of them call the built-in macro functions and reference should be 
  1457.       made to these for further clarification if required.
  1458.  
  1459.       They may all be written in upper or lower case like normal assembler 
  1460.       mnemonics.
  1461.  
  1462.  
  1463.                DW and DD
  1464.                ---------
  1465.       These are expansions of the normal EQUD and EQUW codes and in fact are 
  1466.       translated into these when expanded. The main advantage is that DW and 
  1467.       DD can be used to reserve a series of words or double words and not 
  1468.       just one at a time. These follow the mnemonic as a comma separated 
  1469.       list. For example -
  1470.  
  1471.           DD 1,2,3,4,5,6
  1472.  
  1473.       would be expanded by the preprocessor to -
  1474.  
  1475.           EQUD 1:EQUD 2:EQUD 3:EQUD 4:EQUD 5:EQUD 6
  1476.  
  1477.       which can save a lot of typing.
  1478.  
  1479.       Because the line will actually become longer, which is obvious from 
  1480.       looking at the above example, it is possible for these codes (and the 
  1481.       DB mnemonic which follows) to cause the line to expand beyond the 
  1482.       permitted limit of 255 characters. You should therefore avoid putting 
  1483.       too many items on a single line.
  1484.  
  1485.  
  1486.       If any of the numbers begin with a zero SAsm will assume that the 
  1487.       number is in hex format, whether or not it is preceded by an '&' 
  1488.       character. for example '20' would be decimal 20 but '020' would be 
  1489.       translated as &20, eg. hex 20 which is decimal 32.
  1490.  
  1491.                                                                    Page 26 
  1492.  
  1493.                DB
  1494.                --
  1495.       This is a general purpose macro which replaces the EQUB and EQUS 
  1496.       directives and also allows an area of memory to be reserved for data 
  1497.       and preset to any value if required.
  1498.  
  1499.       In it's simplest form DB acts exactly like DW and DB but with byte 
  1500.       sized sections as a multiple EQUB. However if the parameter is a string 
  1501.       enclosed in double quotes it acts like EQUS. These can be mixed in the 
  1502.       same DB macro which makes defining strings mixed with control codes 
  1503.       much easier. For example -
  1504.  
  1505.           DB 7,"This is some text",10,13,"A new line",0
  1506.  
  1507.       would be expanded to -
  1508.  
  1509.       EQUB 7:EQUS"This is some text":EQUB 10:EQUB 13: EQUS"A new line":EQUB 0
  1510.  
  1511.       As with DW and DD beware of allowing the line to become too long.
  1512.  
  1513.       Again numbers beginning with a zero will be regarded as hexadecimal.
  1514.  
  1515.       DB can be used with a multiplier to reserve an area of memory and set 
  1516.       it to any value. If a parameter begins with '*' then the following 
  1517.       number is taken as a multiplier and the number after that as the value 
  1518.       to be inserted. For example -
  1519.  
  1520.           DB *100,32           (which could also be written as DB *100," " )
  1521.  
  1522.       would reserve the next 100 bytes of memory as a data area and load them 
  1523.       with the value 32, a space character.
  1524.  
  1525.       This can be mixed in with strings and single bytes and can be used 
  1526.       rather like SPC or STRING$ in Basic.
  1527.  
  1528.       For example -
  1529.  
  1530.           DB "1",*10,32,*8,".",*10,32,"First Menu Item",0
  1531.  
  1532.       would be expanded to the zero terminated string -
  1533.  
  1534.           1          ........          First Menu Item
  1535.  
  1536.       One advantage of this is that the multiplier need not be an actual 
  1537.       number but could be an expression. This makes it a lot easier to change 
  1538.       the size of data areas or the length of strings by simply altering the 
  1539.       value of the variable.
  1540.  
  1541.       If you just wish to reserve an area of memory and do not need it to be 
  1542.       set to any particular value then using a question mark as the value 
  1543.       after the multiplier will do so. For example
  1544.  
  1545.           DB  *100,?
  1546.  
  1547.       would reserve 100 bytes but leave the area set to whatever random data 
  1548.       already existed there.
  1549.                                                                    Page 27 
  1550.  
  1551.  
  1552.                ADRL
  1553.                ----
  1554.       This is a two instruction 16 bit ADR directive. It takes the same 
  1555.       parameters as the normal ADR directive, that is the syntax is -
  1556.  
  1557.           ADRL <register>,<location>
  1558.  
  1559.       ADRL will always assemble two instructions when <location> is greater 
  1560.       then the current address. This is because the exact position of 
  1561.       <location> will not be determined until the second pass. However if 
  1562.       <location> is before the current address it's position will already be 
  1563.       known and so a single instruction will be assembled whenever possible.
  1564.  
  1565.       If code length or speed is important you could use the ADR instruction 
  1566.       until you get an 'out of range' error to ensure that no superfluous 
  1567.       instructions are included.
  1568.  
  1569.       Note that there MUST be a space between ADRL and <register> and that 
  1570.       the it CAN now be made conditional
  1571.  
  1572.  
  1573.                MOVL
  1574.                ----
  1575.       This is a method of loading a large immediate number into a register. A 
  1576.       series of ADD or SUB instructions will be assembled to load the value.
  1577.  
  1578.       The syntax is MOVL <register>,<number>. If <number> begins with a zero 
  1579.       it will be regarded as hexadecimal. <number> can of course be positive 
  1580.       or negative. If it is negative then MVN instructions may be used by the 
  1581.       macro but DO NOT adjust the number to allow for this as is required by 
  1582.       the normal MVN instruction. The macro will make all the adjustments 
  1583.       necessary so just write the actual number you require.
  1584.  
  1585.       This macro is fairly simple and does not always produce the most 
  1586.       efficient code for loading a given value. If speed or code length is 
  1587.       paramount it may often be possible to reduce the number of operations 
  1588.       by hand coding.
  1589.  
  1590.       Note that there MUST be a space between MOVL and <register> and that it 
  1591.       CAN now be made conditional
  1592.  
  1593.                                                                    Page 28 
  1594.  
  1595.  
  1596.                DIV
  1597.                ---
  1598.  
  1599.         --** DIV is not included in the Unregistered version of SAsm **--
  1600.  
  1601.       This macro will perform a 32 bit integer division. The full syntax is;
  1602.  
  1603.           DIV <dividend reg>,<divider reg>,<quotient reg>,<temp reg>
  1604.  
  1605.       It therefore requires four DIFFERENT registers as its parameters and 
  1606.       you are responsible for loading the correct values into the registers 
  1607.       before using DIV. The results returned are;
  1608.  
  1609.           <quotient reg> = <dividend reg> DIV <divider reg>
  1610.           <dividend reg> = <dividend reg> MOD <divider reg>
  1611.  
  1612.       The <temp reg> is used for working only and will be corrupted.
  1613.  
  1614.       For example, to divide a number in R0 by a number in R1 and return the 
  1615.       result in R2 using R3 as temporary workspace use;
  1616.  
  1617.           div r0,r1,r2,r3
  1618.  
  1619.       On exit r1 will be unchanged and r0 will contain the remainder if the 
  1620.       number did not divide exactly.
  1621.  
  1622.       Note that there MUST be a space between DIV and <register> and that 
  1623.       because it expands to a large section of code it CANNOT be made 
  1624.       conditional.
  1625.  
  1626.  
  1627.                                                                    Page 29 
  1628.  
  1629.                        -=O=-  ENHANCED 2nd OPERAND  -=O=-
  1630.  
  1631.       This operates on the second operand of instructions CMP, MOV and TEQ. 
  1632.       It will work whether or not the instruction is conditional but it can 
  1633.       NOT be used with CMN or MVN (yet!). For it to work there must be a 
  1634.       space between the opcode and the first operand.
  1635.  
  1636.       The aim is to make it easier when the second operand is an immediate 
  1637.       value rather than another register. The Basic assembler requires the 
  1638.       second operand to have a leading '#' character for it to be recognised 
  1639.       as an immediate value. SAsm will accept this but will also recognise 
  1640.       most immediate numeric operands.
  1641.  
  1642.       If the second operand begins with a digit 0-9, an '&', a '%' or is 
  1643.       enclosed in double quotation marks SAsm will assume that it is an 
  1644.       immediate value whether or not it is preceded by '#'. There is also no 
  1645.       need to use the Basic 'ASC' prefix if a character is enclosed in double 
  1646.       quotation marks. For example -
  1647.  
  1648.             SAsm                   Basic Assembler equivalent
  1649.  
  1650.           cmp r0,"A"                    cmp r0,#ASC"A"
  1651.           mov r0,020                    mov r0,#&20
  1652.           mov r2,"z"+1                  mov r2,#ASC"z"+1
  1653.           mov r2,1+"z"  !Error - won't recognize "z" as an ascii value
  1654.           cmpne r0,13                   cmpne r0,#13
  1655.           teq r0,"m"                    teq r0,#ASC"m"
  1656.           cmp r0,%110                   cmp r0,#%110
  1657.           mov r0,&A4                    mov r0,#&A4
  1658.           mov r0,0A4                    mov r0,#&A4
  1659.           mov r0,A4   !Error - A4 won't be recognised as an immediate number
  1660.  
  1661.       As you can see this makes the code easier to read and also avoids 
  1662.       strange errors when you forget to include the '#'.
  1663.  
  1664.       Note that you can ONLY use these shortcuts when the number is obviously 
  1665.       an immediate value. If it is a variable you must still use the '#'.
  1666.  
  1667.       WARNING - Because a number in the second operand position will always 
  1668.       be regarded as an immediate value if you really DO mean a register you 
  1669.       will have problems. For example, the instruction 'mov 1,3' would be 
  1670.       interpreted by the Basic assembler as 'copy the contents of register 3 
  1671.       into register 1' but by SAsm as 'load register 1 with the immediate 
  1672.       number 3'.
  1673.  
  1674.       To avoid this sort of ambiguity it is usual when writing ARM code to 
  1675.       always prefix register numbers with 'r' or 'R', but this is not 
  1676.       compulsory and the Basic assembler doesn't require it. If you have 
  1677.       fallen into bad habits and just use a simple register number then you 
  1678.       will have problems. There are two possible solutions. Firstly you could 
  1679.       mend your ways and refer to registers properly like everyone else. 
  1680.       Secondly you could write to me and I might include an assembler 
  1681.       directive to instruct SAsm not to use the second operand enhancements.
  1682.                                                                    Page 30 
  1683.  
  1684.                                -=O=-  LABELS  -=O=-
  1685.  
  1686.                Global Labels
  1687.                -------------
  1688.       All labels are common throughout all the files. It is important to 
  1689.       remember this or some very strange things can happen. With SAsm you 
  1690.       don't need to declare labels as 'global', they are ALWAYS global.
  1691.  
  1692.       Adding the suffix 'X' to the command line invokes the label cross 
  1693.       reference function. This will check all labels and report any multiple 
  1694.       definitions.
  1695.  
  1696.       For reasons previously explained multiple definitions of a label are 
  1697.       classed as Warnings only and not Errors. If like me you repeatedly use 
  1698.       labels like 'loop' or 'back' to form short loops you will need to 
  1699.       visually check the list of duplicates for 'foreign' names. To make this 
  1700.       easier it is best to press CTRL-N when typing the SAsm command line. 
  1701.       This will stop the screen scrolling until you press SHIFT. When I get 
  1702.       time I shall include a routine to write the duplicate label list to the 
  1703.       Error File so you can examine it at leisure.
  1704.  
  1705.  
  1706.                Local Labels
  1707.                ------------
  1708.       Since it could become tedious to invent names for all the labels you 
  1709.       need to make short jumps and loops a system of 'Local Labels' has been 
  1710.       included. These are defined in exactly the same way as normal labels, 
  1711.       ie. by preceding the label with a full stop. Local labels MUST be 
  1712.       defined at the start of the line, which is good practice anyway, and 
  1713.       consist of a two digit decimal number 00-99.
  1714.  
  1715.  
  1716.                Local label scope
  1717.                -----------------
  1718.       You start each 'set' of local labels with a label '00'  When SAsm finds 
  1719.       label 00 if 'forgets' all previous local labels. You can therefore use 
  1720.       the numbers 00 to 99 repeatedly and each local label will only apply 
  1721.       within its own section. Each time you start a new section of code or 
  1722.       sub-routine make the first label in that section 00  You can use label 
  1723.       00 even where it is not necessary to ensure that the scope of the 
  1724.       current set of local labels is ended.
  1725.  
  1726.       You will soon find that you will use local labels for all the loops and 
  1727.       short jumps in a section, using meaningful labels where appropriate. 
  1728.       This makes the code much easier to follow because the 'real' labels 
  1729.       which define entry points and complete routines stand out.
  1730.  
  1731.       Local labels can ONLY be used with Branch (or BL) instructions, with or 
  1732.       without conditions, and with the ADR or ADRL pseudo-opcode. They cannot 
  1733.       be used within Macro Functions.
  1734.  
  1735.                                                                    Page 31 
  1736.  
  1737.                Local Label Example
  1738.                -------------------
  1739.       Any Branch instruction will only reach back to the last 00 label and 
  1740.       forward to (but not including) the next. The following example should 
  1741.       make this clear.
  1742.  
  1743.  
  1744.         .00    ........        ; some code
  1745.                ........
  1746.                ........
  1747.         .01    ........
  1748.                ........
  1749.         .02    BNE 01          ; This will branch BACK to the last 01
  1750.                ........
  1751.                ........
  1752.         .00    ........        ; This starts a new section of labels
  1753.                BGT 01          ; Branch FORWARD to 01 in this section
  1754.                ........
  1755.         .01    ........
  1756.                BEQ 02          ; This will produce an error as 02 is not
  1757.              ........          ; defined in this section
  1758.                BLT 00          ; Branch BACK to the last 00
  1759.         .00    ........        ; Start another section
  1760.                ADR r1,00       ; Put address of the LAST 00 in R1
  1761.                ADR r2,01       ; put address of the NEXT 01 in R2
  1762.                ........
  1763.         .01    ........
  1764.  
  1765.  
  1766.       The maximum number of 'sets' of local labels allowed is 2700 sets, 
  1767.       which should be enough for any eventuality.
  1768.  
  1769.  
  1770.                Forward branch to 00
  1771.                --------------------
  1772.       Consider this short piece of code;
  1773.  
  1774.                cmp r0,#32
  1775.                bne 00
  1776.                ........        ;code to be skipped if r0 not 32
  1777.                ........
  1778.         .00    ........        ;rest of code
  1779.  
  1780.       This won't work. The branch would go BACKWARDS to the last 00. You can 
  1781.       NEVER branch FORWARD to a 00 label. You must insert a 'dummy' label 
  1782.       somewhere before the branch instruction to 'reset' the local label 
  1783.       system. The correct way to write the previous example is;
  1784.  
  1785.         .00    cmp r0,#32
  1786.                bne 01
  1787.                ........        ;code to be skipped if r0 not 32
  1788.                ........
  1789.         .01    ........        ;rest of code
  1790.  
  1791.       The 00 label is not used but it resets the local label system so that 
  1792.       the branch is correctly interpreted.
  1793.                                                                    Page 32 
  1794.  
  1795.                         -=O=- THE MACRO LIBRARY  -=O=-
  1796.  
  1797.          --** This facility is available only to REGISTERED users **--
  1798.  
  1799.  
  1800.                Using the Macro Library
  1801.                -----------------------
  1802.       The Registered version of SAsm can record every Macro Function or 
  1803.       Expanded Macro call in your source file. 
  1804.  
  1805.       If it is an Expanded Macro and it has not been previously defined 
  1806.       somewhere in your code then it can be loaded from a special Library 
  1807.       file and inserted in the source.
  1808.  
  1809.       If it is a Macro Function it will be checked against the definitions 
  1810.       found after the #END directive. If one or more definitions cannot be 
  1811.       found it will try to load the missing definitions from a Library file.
  1812.  
  1813.       For Macro Functions the Library is only checked after all the source 
  1814.       files have been loaded so a Macro Function in a source file will 
  1815.       'override' a macro of the same name in the Library. 
  1816.  
  1817.       If an Expanded Macro is defined in the source file it will be used in 
  1818.       preference to one of the same name in the Library. If a macro is 
  1819.       defined part way through the source files then any calls to that macro 
  1820.       before it is defined will be loaded from the Library and those after 
  1821.       will use the version in the source file.
  1822.  
  1823.  
  1824.                The 'L' parameter
  1825.                -----------------
  1826.       If you are using a hard disc this operation is so fast that the only 
  1827.       way you know it is happening is that SAsm will tell you that it is 
  1828.       loading Macro Functions or that the Library isn't required. If you are 
  1829.       using a single floppy drive you may have your Library file on another 
  1830.       disc. When you know that no Library macros are required it is annoying 
  1831.       to have to change discs and allow SAsm to satisfy itself that the 
  1832.       (probably misspelt) missing Macro isn't in the Library. You can 
  1833.       therefore add the suffix 'L' to your command line to tell SAsm NOT to 
  1834.       use the Library, even if SAsm$Lib (see later) is defined.
  1835.  
  1836.  
  1837.                Use of the 'V' parameter
  1838.                ------------------------
  1839.       If you have used the 'V' (verbose) parameter then as each Expanded 
  1840.       Macro is being searched for a message is displayed. Normally this takes 
  1841.       the form -
  1842.  
  1843.           Searching Library for Macro <macro name> - Loaded
  1844.  
  1845.       But if the macro cannot be found in the Library it will say -
  1846.  
  1847.           Searching Library for Macro <macro name> - Not found in Library
  1848.  
  1849.       At this stage a missing macro will not be classed as an error but it 
  1850.       will become one during assembly because the macro will be missing.
  1851.  
  1852.                                                                    Page 33 
  1853.  
  1854.  
  1855.                The SAsm$Lib OS variable
  1856.                ------------------------
  1857.       To tell SAsm that a Library exists you should either create an OS 
  1858.       variable 'SAsm$Lib' with the path/file name of the Library or use the 
  1859.       #LIB directive within the source file. To use the SAsm$Lib variable 
  1860.       type at the OS '*' prompt 'Set SAsm$Lib <filename>' where <filename> is 
  1861.       the path/file name of your Macro Library or put this command in your 
  1862.       !Boot file. You can of course have more than one Macro Library and just 
  1863.       change SAsm$Lib to refer to the one in current use.
  1864.  
  1865.       When SAsm can't find a macro definition in the source files it has 
  1866.       loaded it will check to see if a Library has been defined. If it is it 
  1867.       will extract the 'index' which MakeLib has created. This will be 
  1868.       checked against any missing definition and if these appear in the 
  1869.       Library they will be included.
  1870.  
  1871.       If SAsm can't find the definition of a macro in the source files and 
  1872.       the 'L' parameter hasn't been used but a Library hasn't been defined 
  1873.       then an Error message will be displayed. If you are sure that all the 
  1874.       required macros exist in the source it is best to use the 'L' parameter 
  1875.       to ensure that this doesn't happen.
  1876.  
  1877.  
  1878.                Preparing a Macro Library
  1879.                -------------------------
  1880.       First create a source file of Macro Functions and/or Expanded Macros. 
  1881.       These are macro definitions definitions exactly like the ones you would 
  1882.       normally use in your source files.
  1883.  
  1884.       Each Expanded Macro should begin with the #SM directive and end with 
  1885.       the #EM directive.
  1886.  
  1887.       In earlier versions of SAsm it was stated that each Macro Function 
  1888.       definition should end with an '=' as the first character on a line but 
  1889.       this is no longer required.
  1890.  
  1891.       On your program disc you will find an application called 'MakeLib'. 
  1892.       Copy this to a blank disc and *MOUNT the disc or copy it to the Library 
  1893.       directory of your hard disc. Now at the OS '*' prompt type;
  1894.  
  1895.         *MakeLib  <source filename>  <Library filename>
  1896.  
  1897.       where <source filename> is the full path/file name of your Macro 
  1898.       definition file and <Library filename> is the path/file name that you 
  1899.       wish to call the actual Library file that SAsm will use.
  1900.  
  1901.       MakeLib will load your Macro source file and prepare it for use by 
  1902.       SAsm. Once MakeLib has created the Library file the original source is 
  1903.       no longer required but you should of course keep it so that you can add 
  1904.       new macros and update your Library in the future.
  1905.  
  1906.       The present version of MakeLib can only accept a single source file but 
  1907.       I intend to improve it to accept wildcards in a similar manner to SAsm.
  1908.                                                                    Page 34 
  1909.  
  1910.  
  1911.  
  1912.                Length of Library file
  1913.                ----------------------
  1914.       The source for your Library file can be any length and can have as many 
  1915.       comments ay you like. As with normal SAsm source files these will all 
  1916.       be stripped before the routines are added to the actual Library.
  1917.  
  1918.       The Library file can hold about 200 Macro definitions which should be 
  1919.       enough for anyone. I suggest that in practice you only put the macros 
  1920.       you frequently require in your Library and use INCLUDE files for those 
  1921.       only rarely needed. This will make the search time shorter and also 
  1922.       probably allow you to put your Library on your normal working disc if 
  1923.       you are using a single floppy.
  1924.  
  1925.                                                                    Page 35 
  1926.  
  1927.                        -=O=-  SASM AND THE DESKTOP  -=O=-
  1928.  
  1929.       SAsm was originally intended to be used for the OS command line prompt. 
  1930.       However the introduction of good text editors such as !Zap and other 
  1931.       tools now make it possible to to develop programs within the Archimedes 
  1932.       desktop. Although SAsm is still not integrated into the desktop 
  1933.       environment Versions after 1.40 have features which help them to be 
  1934.       used in this way.
  1935.  
  1936.  
  1937.                The new features
  1938.                ----------------
  1939.       The changes which have been introduced are described in the section on 
  1940.       directives. They enable all of the parameters which previously had to 
  1941.       be typed at the command line (and more) to be inluded in the file as 
  1942.       Directives. This should mean that only the name of a single 'make' file 
  1943.       needs to be typed and this file can contain all other data needed to 
  1944.       assemble the program. The next step is to write a desktop 'front end' 
  1945.       for SAsm which will enable programs to be assembled within the desktop 
  1946.       in a similar manner to Acorns (unbelievably expensive) DDE and this 
  1947.       will be appearing soon.
  1948.  
  1949.       Even without the 'front end' you can now use SAsm within the desktop 
  1950.       very easily and assemble projects by clicking on a single 'Obey' file. 
  1951.       You will not now need to set the CSD as you will be able to use the 
  1952.       <Obey$Dir> OS variable to define the 'start point' of your project 
  1953.       directory structure.
  1954.  
  1955.  
  1956.                Using SAsm from the Desktop
  1957.                ---------------------------
  1958.       Ou can now include everything needed to assemble an extensive project 
  1959.       in a single short 'make' file. This would normally be a text file and 
  1960.       will contain all the preliminary directives (org, size, type, etc) plus 
  1961.       directives to define the object and error filenames and the library to 
  1962.       be used. Following these will come a list of Include files to be 
  1963.       assembled.
  1964.  
  1965.       The main advantage of this system for desktop use is that it enables an 
  1966.       Obey file to run SAsm. For example, to assemble a desktop project you 
  1967.       should set up a directory structure as shown.
  1968.  
  1969.                                     root
  1970.                                      |
  1971.                                      |
  1972.                        ----------------------------
  1973.                       |                            |
  1974.                    source                        !app
  1975.  
  1976.  
  1977.       The 'root' directory would contain your 'make' file and the Obey file 
  1978.       which will run it. It need not, of course, be the actual root directory 
  1979.       of a disc, it is just the root directory of your project. The !App 
  1980.       directory will be the RiscOS application directory for your project. 
  1981.       The 'Source' directory will contain all of your source files. You 
  1982.       could, of course, also have other directories to hold special library 
  1983.       files, error files, notes, etc. if required.
  1984.                                                                    Page 36 
  1985.  
  1986.  
  1987.       Assuming the Make file is simply called 'Make' the Obey file would 
  1988.       contain just two lines -
  1989.  
  1990.              Set   Project$Dir <Obey$Dir>
  1991.              Sasm  <Project$Dir>.Make
  1992.  
  1993.       When you double-click on this file it will atomatically create an OS 
  1994.       variable 'Project$Dir (or whatever you want) and set it to 'Obey$Dir', 
  1995.       ie. to the 'root' directory of your project. It will then Run SAsm 
  1996.       (either from the RMA if you have loaded the Module version or from 
  1997.       disc) with the filename of the Make file.
  1998.  
  1999.       The Make file should define the various parameters to assemble the 
  2000.       program using the <Project$Dir> variable. Alternatively you could set 
  2001.       the OS variable using the CLI directive from within the Make file. It 
  2002.       would also contain directives to define the error file, library and 
  2003.       object file, for example -
  2004.  
  2005.              # errfile <Project$Dir>.err
  2006.              # obj     <Project$Dir>.!App.!Runimage
  2007.  
  2008.       and the files to be assembled would be -
  2009.  
  2010.             # include <Project$Dir>.source.first_*
  2011.             # include <Project$Dir>.source.second_*
  2012.             # include <Project$Dir>.source.third_*
  2013.  
  2014.       or whatever they are called. Note that you can still use the 
  2015.       'descending trailing digits' wildcard to assemble the latest version.
  2016.  
  2017.       Your Make file need not, of course, be in the 'root' directory, it 
  2018.       could be in the source directory if you prefer, (it is, technically, 
  2019.       just another source file).
  2020.  
  2021.       If you don't have a hard disc you will probably prefer to have your 
  2022.       source files (and certainly the error file) on the RAM disc. As SAsm 
  2023.       doesn't create any temporary files you don't need much spare space.
  2024.  
  2025.       To assemble a project in this way just double-click on the Obey file. 
  2026.       You will have to wait for the new 'front end' to have messages trapped 
  2027.       in a desktop window, at present they'll just appear in a Command 
  2028.       window. You can, of course, use SAsm in a 'Task' window but this means 
  2029.       you will need to define directories and type filenames again.
  2030.  
  2031.  
  2032.               IMPORTANT
  2033.               ---------
  2034.       I'm continually trying to improve SAsm. PLEASE tell me if you have any 
  2035.       problems, even if you haven't registered. It's only by acting on your 
  2036.       bug reports and suggestions that I can continue to improve SAsm.
  2037.  
  2038.       If possible send a copy of the source code that cause the problem, 
  2039.       preferably all the files, not just the one that caused the error, plus 
  2040.       any error files generated or any other information. Especially I need 
  2041.       to know exactly how the program failed, 'it wouldn't work with this' 
  2042.       isn't very helpful!
  2043.                                                                    Page 37 
  2044.  
  2045.                        -=O=-  PROBLEMS and QUESTIONS  -=O=-
  2046.  
  2047.  
  2048.       The questions I am most often asked about SAsm are 'what language is it 
  2049.       written in?' and 'how fast is it?'.
  2050.  
  2051.       These two questions can most easily be answered together. SAsm is 
  2052.       written in machine code using SAsm. Each version is assembled using the 
  2053.       previous version. The source code is then changed to take advantage of 
  2054.       any new features and re-assembled. I therefore test SAsm by 'self 
  2055.       assembling' the distributed version.
  2056.  
  2057.       The source for SAsm consists of more than 4000 lines split over eight 
  2058.       files. These are loaded from disc, assembled, and the source file saved 
  2059.       to disc in less than six seconds on an A400 series using an ARM 2 
  2060.       processor or about two seconds on an A5000. I think this is fast enough 
  2061.       for most purposes. Naturally if you didn't have a hard disc the time 
  2062.       taken would be quite a bit longer but as SAsm can easily use a RAM disc 
  2063.       this shouldn't be a serious problem unless you are trying to write long 
  2064.       programs on a 1Mb machine. Unlike most assemblers and compilers SAsm 
  2065.       doesn't use much memory for its own purposes.
  2066.  
  2067.       At present SAsm is entirely Command Line driven and doesn't have a 
  2068.       desktop 'front end'. There is no reason why this can't be done. As soon 
  2069.       as I feel that the basic program is 'stable' I shall write one so that 
  2070.       you can work entirely within the desktop if you wish.
  2071.  
  2072.  
  2073.       There are a couple of 'features' of SAsm which can cause trouble. Some 
  2074.       are minor bugs which are not important once you know about them and 
  2075.       will be fixed when I have time. Others are errors which can occur 
  2076.       because of changes in the syntax used by SAsm. I will record some of 
  2077.       the queries which have been raised by users in the hope that it will 
  2078.       avoid others experiencing the same problems.
  2079.  
  2080.  
  2081.       1.  There MUST be a space between the mnemonic and the first operand for 
  2082.           many of SAsm's functions to work correctly. This is not always 
  2083.           essential with the Basic assembler but it is good practice so I make 
  2084.           no apologies for it.
  2085.  
  2086.       2.  MOVL, ADRL and DIV are actually macro's and not assembler mnemonics. 
  2087.           ADRL and MOVL can be made conditional but because DIV expands to 
  2088.           several lines of code with internal compare instructions it cannot.
  2089.  
  2090.       3.  Make sure that you have started every set of local labels with '00'.
  2091.  
  2092.       4.  You cannot use local labels, DB, DW, DD, ADRL, MOVL, DIV or any of 
  2093.           the enhanced second operator functions after the #END directive, 
  2094.           This means you can't use them within Macro Functions. You can, 
  2095.           however, use them within Expanded Macros because these are defined 
  2096.           before the #END statement.
  2097.  
  2098.       5.  Because DB, DW and DD instructions may expand considerably they can 
  2099.           cause a 'line too long' error if you put too much on one line.
  2100.                                                                    Page 38 
  2101.  
  2102.  
  2103.       6.  SAsm removes redundant spaces and comments as it is processing a 
  2104.           file but other operations expand it. Normally the contraction is 
  2105.           greater than the expansion so the file shrinks. As each file is 
  2106.           loaded a 16K 'overhead' is allowed in case the file does grow. 
  2107.           Normally this is adequate but in extreme cases of large individual 
  2108.           files and no redundant spaces and comments the program could crash. 
  2109.           I will add functions to guard against this when I get time but I do 
  2110.           not regard it as a serious fault because the whole purpose of SAsm 
  2111.           is to enable you to split up and spread out your source files.
  2112.  
  2113.       7.  Because SAsm regards a ';' as defining a comment if you insert a 
  2114.           line of Basic which has a PRINT statement that includes the ';' 
  2115.           character with a preceding space it will be 'cut off'.
  2116.  
  2117.       8.  At present there must be a CR or LF at the end of each file. Once 
  2118.           again I will correct this when I get time.
  2119.  
  2120.       9.  It is possible for the program to abort giving an error message with 
  2121.           a line number which is much greater than the length of the file in 
  2122.           which the error occurred. This normally means that the error 
  2123.           actually occurred inside a Macro Function. This is always a problem 
  2124.           with Basic Functions and Procedures and there is no simple solution. 
  2125.           Often the only way of discovering the actual error is to examine 
  2126.           every FN call in the file in which the error occurred.
  2127.  
  2128.       10. SAsm can abort with an error if there is not enought space for line 
  2129.           numbers. This is because after SAsm has finished with the files 
  2130.           Basic will need to add 3 bytes to each line for the line number and 
  2131.           length byte. The only solution is to make more memory available.
  2132.  
  2133.                                                                    Page 39 
  2134.  
  2135.                          -=O=-  RELEASE HISTORY  -=O=-
  2136.  
  2137.  
  2138.               1.0      Oct. 91     First release
  2139.  
  2140.               1.1      Nov. 91     Functionally as 1.0
  2141.                                    Bug fixes
  2142.                                    X-ref and Macro Library functions re-written 
  2143.                                    and much faster, delays now imperceptible 
  2144.                                    with hard disc.
  2145.  
  2146.               1.2      Nov. 91     Bug fixes
  2147.                                    Much improved error handling
  2148.                                    INCLUDE directive added
  2149.  
  2150.               1.21     Jan 92      Restrictions on INCLUDE directive with 
  2151.                                    Shareware version removed.
  2152.  
  2153.               1.22     Mar 92      Improved error handler
  2154.       
  2155.               1.23     May 92      Minor bug fixes
  2156.  
  2157.               1.24     June 92     Line numbering system rewritten, dramatic 
  2158.                                    speed increase for large files
  2159.                                    Line number space relocation added
  2160.  
  2161.               1.25     July 92     adrl, movl, div, db, dw, dd, added
  2162.                                    enhanced immediate 2nd operand
  2163.  
  2164.               1.26     Feb 93      Bug in adrl in some examples of 1.25 fixed. 
  2165.                                    No public release of this version.
  2166.  
  2167.               1.30     Mar 93      Expanded macros introduced.
  2168.                                    db *xx,? to reserve area without setting 
  2169.                                    New Makelib tool for expanded macros
  2170.                                    Module provided so SAsm can now be run from 
  2171.                                    the RMA for floppy disc users.
  2172.  
  2173.               1.31     Apr 93      ADRL and MOVL can be conditional
  2174.  
  2175.               1.32     Jun 93      Bug fixed in expanded macro stack.
  2176.        
  2177.               1.41     Aug 93      #obj, #lib, #errfile, #cli, #verbose, #quiet, 
  2178.                                    #xref and #noxref directives introduced.
  2179.                                    Tab characters accepted as delimiters.
  2180.  
  2181.               1.42     Sep 93      Bug with DB, DD and DW in upper case fixed.
  2182.                                    Bug with comment on Macro call line fixed.
  2183.                                    'Line Too Long' trapped during preprocessing
  2184.  
  2185.               1.43     Oct 93      Bug with DB, DD and DW in upper case fixed.
  2186.                                    (Honest, it's fixed, really....)
  2187.  
  2188.  
  2189.  
  2190.  
  2191.                        Registration Form for SAsm
  2192.  
  2193.  
  2194.       Please complete this and post it with your cheque for Eight Pounds to;
  2195.  
  2196.       David Holden,  39 Knighton Park Road,  Sydenham,  London SE26 5RN
  2197.       ____________________________________________________________________
  2198.       Name and Address:
  2199.  
  2200.  
  2201.  
  2202.  
  2203.  
  2204.  
  2205.  
  2206.       ____________________________________________________________________
  2207.       Where did you obtain SAsm:
  2208.  
  2209.  
  2210.  
  2211.  
  2212.  
  2213.  
  2214.  
  2215.       ____________________________________________________________________
  2216.       Have you had any problems:
  2217.  
  2218.  
  2219.  
  2220.  
  2221.  
  2222.  
  2223.  
  2224.  
  2225.  
  2226.  
  2227.       ____________________________________________________________________
  2228.       What additional features would you like:
  2229.