Sial Specification

Sial is a machine independent target code for BCPL. It consists
of a stream of directives and instructions each starting with an opcode
and operands. Both opcodes and operands and encoded by integers. Each
integer is prefixed by a letter specifying what kind of value it 
represents. The prefixes are as follows:

F    An opcode or directive
P    A stack offset, 0 to #xFFFFFF
G    A global variable number, 0 to 65535
K    A 24 bit unsigned constant, often small in value
W    A 32 bit signed integer, used for static data and large constants
C    A string character in range 0..255
L    A label generated by TRN
M    A label generated by CG

The instructions are for an abstract machine with internal registers

a    The main accumulator, function first arg and result register
b    The second accumulator used in dyadic operations
c    Register used by pbyt and xpbyt, possibly currupted by
              some other instructions, eg mul, div, rem, xdiv and xrem.
P    Pointer to the base of the current stack frame
G    Pointer to the base of the Global Vector
PC   Set by jump and call instrunctions

The opcodes and directives are as follows:

Fcode Mnemonic  Operand(s)   Meaning

  1   lp        Pn           a := P!n
  2   lg        Gn           a := G!n
  3   ll        Ln           a := !Ln

  4   llp       Pn           a := @ P!n
  5   llg       Gn           a := @ G!n
  6   lll       Ln           a := @ !Ln
  7   lf        Ln           a := byte address of entry point Ln

 10   l         Kn           a := n
 11   lm        Kn           a := - n 

 12   sp        Pn           P!n := a
 13   sg        Gn           G!n := a
 14   sl        Ln           !Ln := a

 15   ap        Pn           a := a + P!n
 16   ag        Gn           a := a + G!n
 17   a         Kn           a := a + n
 18   s         Kn           a := a - n

 20   lkp       Kk Pn        a := P!n!k
 21   lkg       Kk Gn        a := G!n!k
 22   rv                     a := ! a
 23   rvp       Pn           a := P!n!a
 24   rvk       Kn           a := a!k
 25   st                     !a := b
 26   stp       Pn           P!n!a := b
 27   stk       Kn           a!n := b
 28   stkp      Kk Pn        P!n!k := a
 29   skg       Kk Gn        G!n!k := a
 30   xst                    !b := a

 35   k         Pn           Call  a(b,...) incrementing P by n leaving b in a
 36   kpg       Pn Gg        Call Gg(a,...) incrementing P by n

 37   neg                    a := - a
 38   not                    a := ~ a
 39   abs                    a := ABS a

 46   xdiv                   a := a / b;    c := ?
 47   xrem                   a := a REM b;  c := ?
 48   xsub                   a := a - b;    c := ?

 45   mul                    a := b * a;    c := ?
 46   div                    a := b / a;    c := ?
 47   rem                    a := b REM a;  c := ?
 48   add                    a := b + a
 49   sub                    a := b - a

 50   eq                     a := b = a
 51   ne                     a := b ~= a
 52   ls                     a := b < a
 53   gr                     a := b > a
 54   le                     a := b <= a
 55   ge                     a := b >= a
 56   eq0                    a := a = 0
 57   ne0                    a := a ~= 0
 58   ls0                    a := a < 0
 59   gr0                    a := a > 0
 60   le0                    a := a <= 0
 61   ge0                    a := a >= 0

 65   lsh                    a := b << a
 66   rsh                    a := b >> a
 67   and                    a := b & a
 68   or                     a := b | a
 69   xor                    a := b NEQV a
 70   eqv                    a := b EQV a
 
 74   gbyt                   a := b % a
 75   xgbyt                  a := a % b
 76   pbyt                   b % a := c
 77   xpbyt                  a % b := c

 78   swb       Kn Ld K1 L1 ... Kn Ln   Binary chop switch, Ld default
 79   swl       Kn Ld L1 ... Ln         Label vector switch, Ld default

 80   xch                    swap a and b
 81   atb                    b := a
 82   atc                    c := a
 83   bta                    a := b
 84   btc                    c := b
 85   atblp     Pn           b := a; a := P!n
 86   atblg     Gn           b := a; a := G!n
 87   atbl      Kk           b := a; a := k

 90   j         Ln           jump to Ln
 91   rtn                    procedure return
 92   goto

 93   ikp       Kk Pn        a := P!n + k; P!n := a
 94   ikg       Kk Gn        a := G!n + k; G!n := a
 95   ikl       Kk Ln        a := !Ln + k; !Ln := a
 96   ip        Pn           a := P!n + a; P!n := a
 96   ig        Gn           a := G!n + a; G!n := a
 96   il        Ln           a := !Ln + a; !Ln := a

100   jeq       Ln           Jump to Ln if b = a
101   jne       Ln           Jump to Ln if b ~= a
102   jls       Ln           Jump to Ln if b < a
103   jgr       Ln           Jump to Ln if b > a
104   jle       Ln           Jump to Ln if b <= a
105   jge       Ln           Jump to Ln if b >= a
106   jeq0      Ln           Jump to Ln if a = 0
107   jne0      Ln           Jump to Ln if a ~= 0
108   jls0      Ln           Jump to Ln if a < 0
109   jgr0      Ln           Jump to Ln if a > 0
110   jle0      Ln           Jump to Ln if a <= 0
111   jge0      Ln           Jump to Ln if a >= 0
112   jge0m     Mn           Jump to Mn if a >= 0

120   brk                    Breakpoint instruction
121   nop                    No operation
122   chgco                  Change coroutine
123   mdiv                   a := Muldiv(P!3, P!4, P!5)
124   sys                    System function

130   section   Kn C1 ... Cn         Name of section
131   modstart                       Start of module 
132   modend                         End of module
133   global    Kn G1 L1 ... Gn Ln   Global initialisation data
134   string    Ml Kn C1 ... Cn      String constant
135   const     Mn Ww                Large integer constant
136   static    Ln Kk W1 ... Wk      Static variable or table
137   mlab      Mn                   Destination of jge0m
138   lab       Lm                   Program label
139   lstr      Mn                   a := Mn   (pointer to string)
140   entry     Kn C1 ... Cn         Start of a function


