
This material supplements SAM2.DOC

Instruction Codes for MACC2

IN    0
IA    1
IS    2
IM    3
ID    4
FN    5
FA    6
FS    7
FM    8
FD    9
BI   10
BO   11
BA   12
IC   13
FC   14
JSR  15
BKT  16
LD   17
STO  18
LDA  19
FLT  20
FIX  21
J    22   ALL JUMP INSTRUCTIONS EXCEPT JSR
SR   23 *
SL   24 *
RD   25
WR   26  INCLUDING WRNL
TRNG 27
HALT 31

   * = one word instructions
       all others require one or two words depending on the operands

The length of an instruction depends on the mode of the second operand.
For Register Direct and Register Indirect modes only one word is required.

Format of (most) two word instructions
First word:
  bits   function
 15-11  the 5 bit opcode as above
 10-7   the first register operand
 6-4    the mode of address of the second operand
        bit 6  is the indirect bit (* appears in the address)
        bit 5  is the indexed bit ( parentheses in the address)
        bit 4  is the memory bit
          On page 4 of SAM2.DOC the order of listing the modes gives the
          contents of bits 6-4 as a binary 3 bit number in range 0-7.
 3-0    the register for the second operand
Second word is an offset or address depending on bits 6-0 of first word.

              Name                 Symbolic Form   Effective Address
              ----                 -------------   -----------------
0   000       Register Direct      Rr              Rr
1   001       Memory Direct        w               w
2   010       Indexed              w(Rr)           (Rr) + w
3   011       Immediate            #w              (PC) - 1
4   100       Register Indirect    *Rr             (Rr)
5   101       Memory Indirect      *w              (w)
6   110       Indexed Indirect     *w(Rr)          ((Rr) + w)
7   111       PC Relative          &w              (PC) + w

The formats of some instructions vary.

For the JUMP instructions the register bits, 10-7, give the jump mode:
  JMP = 0
  JLT   1
  JLE   2
  JEQ   3
  JNE   4
  JGE   5
  JGT   6
  NOP   7

The WR commands use the register bits to give the kind of data being written.
  WRI =  0
  WRF    1
  WRBD   2
  WRB2   3
  WROD   4     Write Octal Digit/ not implemented
  WROW   5     Write Octal Word/ not implemented
  WRHD   6
  WRHW   7
  WRCH   8
  WRST   9
  WRNL  11
The RD instructions are similar.

The SHIFT instructions use the mode bits to give the type of shift.
  SLZ  = 0
  SLO    1
  SLE    2
  SLC    3
  SLCZ   4
  SLCO   5
  SLCE   6
  SLCC   7
  And similarly for right shifts.
They use the four low bits, 3-0, to save the amount of the shift.

The program TRANS.PAS may be used to decode an OBJ file produced by SAM2 and
create a file named MEM which contains a readable listing of the machine
code, along with some information to help with the fields described above.

To run TRANS you must have a file named OBJ produced by SAM2.  This file is
read by TRANS.  TRANS will create a file named MEM, which may be read with
any editor, or listed or printed.

For example, for the input file (CODEFILE) to SAM2:

      LD   R1, A
      IC   R1, B
      JGE  SKIP
      LD   R1, A
      JMP  DONE
LABEL SKIP
      LD  R1, B
LABEL DONE
      STO R1, ARSLT
      WRI ARSLT
      WRNL
      HALT
LABEL A
      INT 3
LABEL B
      INT 5
LABEL ARSLT
      SKIP 2

 an OBJ file will be produced but it is not readable.  TRANS will create the
 file MEM with the following information.








  num   binary        opcode:15-11  reg:10-7   6-4  3-0      raw Hi  raw Lo
    0 1000100010010000     17         1         1    0       136    16
    2 0000000000100100      0         0         2    4         0    36
    4 0110100010010000     13         1         1    0       104    16
    6 0000000000100110      0         0         2    6         0    38
    8 1011001010010000     22         5         1    0       178    16
   10 0000000000010100      0         0         1    4         0    20
   12 1000100010010000     17         1         1    0       136    16
   14 0000000000100100      0         0         2    4         0    36
   16 1011000000010000     22         0         1    0       176    16
   18 0000000000011000      0         0         1    8         0    24
   20 1000100010010000     17         1         1    0       136    16
   22 0000000000100110      0         0         2    6         0    38
   24 1001000010010000     18         1         1    0       144    16
   26 0000000000101000      0         0         2    8         0    40
   28 1101000000010000     26         0         1    0       208    16
   30 0000000000101000      0         0         2    8         0    40
   32 1101010110000000     26        11         0    0       213     0
   34 1111100000000000     31         0         0    0       248     0
   36 0000000000000011      0         0         0    3         0     3
   38 0000000000000101      0         0         0    5         0     5
   40 0000000000000000      0         0         0    0         0     0

 The first column gives the location in memory of MACC2.  Operations take two
 or four bytes (one or two words), so an instruction is one or two lines in
 this listing.  The second field is the raw bits of the memory.  The next four
 fields decode the various pieces of the instruction as defined above.  The
 last two fields give the contents of the separate bytes of the word as a
 decimal number in the range 0-255.