TSK3000A Core Instruction - SUB
Instruction: | Subtract Word |
Assembler Format: | sub rC, rA, rB |
Example: | sub $3, $4, $5 |
Description: | Subtracts the contents of GPR rB from GPR rA and puts the result in GPR rC. |
Operation: | rC <-- rA - rB |
Instruction Type: | R-Type |
Instruction Fields: | rA = Register index of operand A rB = Register index of operand B rC = Register index of destination |
Encoding:
31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | rA | rB | rC | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 |
Latency: 1
Notes:
The following code example illustrates how overflow detection can be handled, in software, when subtracting two signed operands:
sub rC, rA, rB
xor rD, rA, rB -----compare sign of operand rA with operand rB
xor rE, rA, rC -----compare sign of operand rA and the difference
and rD, rD, rE -----bitwise logically AND the comparison values
slt rD, rD, $0 -----if result less than '0', flag overflow
rD will be set to '1' if an overflow occurred, otherwise it will be set to '0'