|
Each instruction is 2 bytes (= 16 bits)
The first 2 bits encodes the instruction type:
OpCode
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| x | x | | | | | | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
x x Instruction Type
---------------------------------------------------------------
0 0 ALU (2 registers or 1 register,1 constant operand)
0 1 Load (memory)
1 0 Store (memory)
1 1 Branch
|
Syntax:
add destReg, srcReg1, srcReg2 sub destReg, srcReg1, srcReg2
add destReg, srcReg1, #const sub destReg, srcReg1, #const ... etc
Endcoding:
Dest Reg OpCode I Src Reg1 Src Reg2
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| 0 | 0 | D | D | D | P | 0 | | | | S | S | S | R | R | R |
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
OpCode P: (1 update PSR, 0 do not update PSR)
----------------------- I: (1 use Src 2 as constant, 0 reg num)
0 0 Add
0 1 Subtract
1 0 AND
1 1 OR
Examples:
Dest Reg P OpCode I Src Reg1 Src Reg2
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| 0 | 0 | 0 | 0 | 1 | P | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | sub r1,r2,r3
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| 0 | 0 | 0 | 0 | 1 | P | 0 | 0 | 1 | 1 | 0 | 1 | 0 | 0 | 1 | 1 | sub r1,r2,#3
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
|
Syntax: add destReg, srcReg1, srcReg2 sub destReg, srcReg1, srcReg2 add destReg, srcReg1, #const sub destReg, srcReg1, #const ... etc Endcoding: Dest Reg OpCode I Src Reg1 Src Reg2 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | 0 | 0 | D | D | D | P | 0 | | | | S | S | S | R | R | R | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ OpCode P: (1 update PSR, 0 do not update PSR) ----------------------- I: (1 use Src 2 as constant, 0 reg num) 0 0 Add 0 1 Subtract 1 0 AND 1 1 OR Examples: Dest Reg P OpCode I Src Reg1 Src Reg2 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | 0 | 0 | 0 | 0 | 1 | P | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | sub r1,r2,r3 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | 0 | 0 | 0 | 0 | 1 | P | 0 | 0 | 1 | 1 | 0 | 1 | 0 | 0 | 1 | 1 | sub r1,r2,#3 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ |
Syntax:
LDR destReg, [srcReg1, constant]
LDR destReg, [srcReg1, srcReg2]
Encoding:
Dest Reg P OpCode I Src Reg1 Src Reg2
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| 0 | 1 | D | D | D | x | 0 | 0 | 0 | x | S | S | S | R | R | R |
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
OpCode P: (1 update PSR, 0 do not)
----------------------- I: (1 use Src 2 as constant, 0 reg num)
0 0 Add
0 1 Subtract
1 0 AND
1 1 OR
Examples:
Dest Reg P OpCode I Src Reg1 Src Reg2
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | ldr r6,[r3,r2]
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 1 | 0 | ldr r6,[r3,#2]
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
|
Syntax: LDR destReg, [srcReg1, #const] LDR destReg, [srcReg1, srcReg2] Encoding: Dest Reg P OpCode I Src Reg1 Src Reg2 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | 0 | 1 | D | D | D | x | 0 | 0 | 0 | x | S | S | S | R | R | R | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ OpCode P: (1 update PSR, 0 do not) ----------------------- I: (1 use Src 2 as constant, 0 reg num) 0 0 Add 0 1 Subtract 1 0 AND 1 1 OR Examples: Dest Reg P OpCode I Src Reg1 Src Reg2 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | ldr r6,[r3,r2] +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 1 | 0 | ldr r6,[r3,#2] +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ |
Syntax:
STR destReg, [srcReg1, #const]
STR destReg, [srcReg1, srcReg2]
Encoding:
Dest Reg P OpCode I Src Reg1 Src Reg2
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| 1 | 0 | D | D | D | x | 0 | 0 | 0 | x | S | S | S | R | R | R |
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
OpCode P: (1 update PSR, 0 do not)
----------------------- I: (1 use Src 2 as constant, 0 reg num)
0 0 Add
0 1 Subtract
1 0 AND
1 1 OR
Examples:
Dest Reg P OpCode I Src Reg1 Src Reg2
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| 1 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | str r6,[r3,r2]
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| 1 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 1 | 0 | str r6,[r3,#2]
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
|
Syntax: STR destReg, [srcReg1, #const] The destReg is used as a source reg in STR !! STR destReg, [srcReg1, srcReg2] (The destination of STR instr is memory !) Encoding: Dest Reg P OpCode I Src Reg1 Src Reg2 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | 1 | 0 | D | D | D | x | 0 | 0 | 0 | x | S | S | S | R | R | R | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ OpCode P: (1 update PSR, 0 do not) ----------------------- I: (1 use Src 2 as constant, 0 reg num) 0 0 Add 0 1 Subtract 1 0 AND 1 1 OR Examples: Dest Reg P OpCode I Src Reg1 Src Reg2 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | 1 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | str r6,[r3,r2] +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | 1 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 1 | 0 | str r6,[r3,#2] +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ |
Syntax:
BRA label
BEQ label ... etc
Encoding:
Branch
condition <------- relative branch offset ----------->
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| 1 | 1 | B | B | B | | | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
B B B Branch condition
---------------------------------------------------------------
0 0 0 Branch always
0 0 1 BEQ
0 1 0 BNE
0 1 1 BLT
1 0 0 BLE
1 0 1 BGT
1 1 0 BGE
1 1 1 not used
Example:
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 |
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
branch always to the address PC + 3
|
Syntax:
BRA label and: the PC is always a source operand in branch !!
BEQ label
Encoding:
Branch
condition <------- relative branch offset ----------->
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| 1 | 1 | B | B | B | | | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
B B B Branch condition
---------------------------------------------------------------
0 0 0 Branch always
0 0 1 BEQ
0 1 0 BNE
0 1 1 BLT
1 0 0 BLE
1 0 1 BGT
1 1 0 BGE
1 1 1 not used
Example:
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | and the PC
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
branch always to the address PC + 3
|