


                     Part 2 :- SWIs and data-shifting
                              BY DF0: / NFA

Having  got  the  basics of setting up a machine code program,I will now
detail  some  data-shifting  commands.Note  that  this  is  all  for the
Archimedes computer!  See <<LAST MONTHS>> Issue for the preface to this!

-----------------------------------------------------------------------

Basic  movment command :- LDR <destination> , <source> This can be moved
for transfer between registers and memory locations.

Address   command   :   ADR  <destination>,<label>  .   This  loads  the
destination ( often a register with the address of a label,IE:-

ADR R0,poopoo

Would  give  R0  the  value  of wherever .poopoo is in memory.  See last
issues file for more on this and branches.

Mathmatical operations:-
-------------------------
ADD : Addition       : ADD {Suffix} <destination>,<operand1>,<operand2>
ADC : Add with carry : ADC {Suffix} <destination>,<operand1>,<operand2>
SUB : Subtract       : SUB {Suffix} <destination>,<operand1>,<operand2>
SBC : Sub with carry : SBC {Suffix} <destination>,<operand1>,<operand2>
RSB : Reverse Sub    : RSB {Suffix} <destination>,<operand1>,<operand2>
RSC : RSB with carry : RSC {Suffix} <destination>,<operand1>,<operand2>
MOV : Move data 2 reg: MOV {Suffix} <destination>,<operand2>
MVN : MOV inverted   : MVN {Suffix} <destination>,<operand2>
CMP : Compare        : CMP {Suffix} <operand1>,<operand2>
AND : Logical AND    : AND {Suffix} <destination>,<operand1>,<operand2>
ORR : Logical OR     : ORR {Suffix} <destination>,<operand1>,<operand2>
EOR : Logical EOR    : EOR {Suffix} <destination>,<operand1>,<operand2>
BIC : Bit clear      : BIC {Suffix} <destination>,<operand1>,<operand2>
TST : Test bits      : TST {Suffix} <operand1>,<operand2>
MUL : Multiply       : MUL {Suffix} <destination>,<operand1>,<operand2>

Where {Suffix} is is one of the following :-

EQ  : Equal to
NE  : Not equal
VS  : Overfolow set
VC  : Overfolw clear
PL  : Plus
MI  : Minus
CS  : Carry set
CC  : Carry clear
AL  : Always
NV  : Never
HI  : Higher              - Unsigned -
LS  : Lower than or same  - Unsigned -
LT  : Less than           - Signed   -
GT  : Greater than        - Signed   -
LE  : Lessthan or equal   - Signed   -

Example code   :
----------------

.Start

CMP    R0,R1       ; Compare registers R0 and R1.
MOVEQ  PC,R14      ; If they are EQual,then end program 
ADDNE  R0,R0,#1    ; If Not EQual,add a value of 1 to R0
B      .Start      ; Branch back to beginning to start again.

I  have  introduced  you  to a new command there,the B command.This will
jump  to  any  label  specified  after it.If you use a BL,this acts as a
Branched sub-routine.Example :-

  +----- BL      .Subthing  ; Branch to .Subthing label.
  |        <-+              ; Now back from sub-routine.
  |      ..  |
  |      ..  +------------------------------------------------------+
  |      ..                                                         |
  |                                                                 |
  +-----> .Subthing                                                 |
                                                                    |
                            ; A completley pointless sub-routine    |
                                                                    |
          MOV R15,R14       ; Equivalent of RTS return call --------+

                 New topic Thingy - Software Interrupts
                 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Software  interrupts,when  called cause the computer to halt the current
program,switch   to  supervisor  mode,and  to  execute  the  named  SWI.
Examples  are  the  write  text  SWI,  "OS_WriteC",which  prints out the
character  in  register R0.I am now going to cover some common SWIs.They
are all called with the SWI command,like so:

               SWI "OS_WriteC"

Note  that  the  SWI  has to be in "" marks,and will not work unless the
case  is exactly correct.  SWI "OS_writec" is wrong.You can also use the
numerical value,so

               SWI "OS_WriteC" and
               SWI &00

both do the same thing.

                                 SWIs:
                                 -----
Note  that all text strings must be terminated in a zero,unless they are
CLI strings,in which case they must end in a &0D.

OS_WriteC         : Writes an ASCII character 
Numerical value   : &00
Entry             : R0 holds ASCII value
Exit              : No information returned

OS_ReadC          : Reads a key from the keyboard
Numerical value   : &04
Entry             : Nothing passed
Exit              : R0 holds ASCII value of key

OS_Write0         : Prints a string of text 
Numerical value   : &02
Entry             : R0 holds address of string loaded with ADR
Exit              : No information returned

OS_WriteS         : Prints a string
Numerical value   : &01
Entry             : Nothing passed
Exit              : Nothing passed
--[ This may sound a bit wierd,but it works like this :
    EQUS ("This is a string printed with OS_WriteS...")
    EQUB &0
    SWI "OS_WriteS"  ]--

OS_ReadLine       : Reads a line of text
Numerical value   : &0E
Entry             : R0 = Address of buffer to hold string
                    R1 = Maximum length for string
                    R2 = Lowest ASCII code allowed in buffer
                    R3 = Highest ASCII code allowed in buffer
Exit              : R1 = Length of buffer

OS_NewLine        : Outputs an enter character
Numerical value   : &03
Entry             : Nothing passed
Exit              : Nothing passed

OS_CLI            : Executes a CLI string.
Numerical value   : &05
Entry             : R0 = Address of command string
Exit              : Depends on command being run...

Example of OS_CLI :-

ADR R0,CommandString  ; Load address of label into R0 
SWI "OS_CLI"          ; Call SWI
MOV PC,R14            ; End program
.CommandString        ; Label of string
EQUS "*DIR"           ; Actual string
EQUB &0D              ; Terminated in &0D

An example program that covers the topics I have written down here
would be :-

         ; Reads keypresses and loops around until a 'Z' is pressed
         ; Example program by DF0: of NFA in 1994

         .Start                ; Identify programs start label
         LDR    R3,#0          ; Load R3 with 0
         LDR    R1,#ASC("Z")   ; Load R1 with ASCII value of 'Z'
         SWI    "OS_ReadC"     ; Read a character from the Keyboard
         BL     Checkchar      ; Branch to sub routine
         CMP    R3,#1          ; Compare R3 with 1 value
         BNE    Start          ; If not 1 hen loop back to Start   
         MOVEQ	PC,R14         ; If equal then exit program
         .Checkchar            ; CheckChar sub-routine
         CMP    R0,R1          ; Compare key press with 'Z'          
         LDREQ  R3,#1          ; If the same then load R3 with 1   
         MOV    R15,R14        ; Return from sub-routine

Well,thats about it for now! Until next time.....

                                   BYE!

                              From DF0: / NFA

**PLUG**PLUG**PLUG**PLUG**PLUG**PLUG**PLUG**PLUG**PLUG**PLUG**PLUG**PL

   Hey,folks!  An important message for all you Archimedes owners!
   Coming soon to an ADFS disk near you is the miraculous program,
   -> NFADesk <-  Liven up your Desktop! Have lots of cool 3-D 
   icons! Have music in the background! Load 24-bit images as 
   backdrops ( If you have a RISC PC ) ! Generally cock about!
   Give money to me!

   Yes,you heard that right! I am releasing a PD program
   that jazzes up your boooring Desktop no end! At the moment,
   features to be included are :----

   -*- New Icons for windows and ROMApps
   -*- New system modules for extended commands
   -*- Backdrop loader for RISC-OS 3 and greater
   -*- System$Paths set up for all major applications
   -*- Virus protection
   -*- Choice of pre-made configurations
   -*- Module utility to unplug all modules you dont want!
   -*- ARM BASIC editor
   -*- Support for Amiga Soundtracker and MusMod files
   -*- And a damn sight more !

   It'll probably be finished early 1995,as I have far more important
things to do in the interim,namely study like hell.....
When it does come though,itll be a bit damn kicking!!

*****************************END OF PLUG******************************

End. (honest)
