Instruction Set for the COS 111 Processor

Each instruction is two bytes long.

The first byte of each instruction contains an "opcode" (a number saying which instruction to execute) and a register number.  The register number is the last (base-10) digit of the first byte, and the opcode is everything else (all but the first digit).  For example, if the first byte is "135", then the opcode is 13 and the register number is 5.

The second byte of each instruction gives a one-byte value.  This is used in different ways depending on what the opcode is.
 

Instruction Set Examples

 
Opcode Name Example What the example does Use of second byte
0 Halt 0 0 Halts the machine none
1 SetReg 13 74 R3 <== 74 one-byte value
2 MemToReg 25 81 R5 <== Memory[81] memory address
3 RegToMem 30 197 Memory[197] <== R0 memory address
4 MemToRegIndirect 42 4 R2 <== Memory[R4] register number
5 RegToMemIndirect 57 6 Memory[R6] <== R7 register number
6 Add 60 12 R0 <== R1 + R2 pair of register numbers
7 Subtract 73 42 R3 <== R4 - R2 pair of register numbers
8 And 81 52 R1 <== R5 and R2 pair of register numbers
9 Or 94 60 R4 <== R6 or R0 pair of register numbers
10 Not 103 2 R3 <== not R2 register number
11 SetPc 110 78 PC <== 78 instruction address
12 RegToPc 124 0 PC <== R4 none
13 SetPcIfZero 134 99 if (R4=0) then    PC <== 99 instruction address
14 Input 142 0 R2 <== input none
15 Output 153 0 output <== R3 none