Add, subtract, negate
| Instruction | Encoding | Chip | What it does |
|---|---|---|---|
add Rm,Rnadd #imm,Rn | 0011 nnnn mmmm 11000111 nnnn iiiiiiii | SH-1 | Rn = Rn + Rm, or Rn + the sign-extended immediate. T is not changed. add #imm,r15 adjusts the stack pointer. |
addc Rm,Rn | 0011 nnnn mmmm 1110 | SH-1 | Rn = Rn + Rm + T; T = the carry out. Used for multiword addition. |
addv Rm,Rn | 0011 nnnn mmmm 1111 | SH-1 | Rn = Rn + Rm; T = 1 on signed overflow. |
sub Rm,Rn | 0011 nnnn mmmm 1000 | SH-1 | Rn = Rn - Rm. T is not changed. |
subc Rm,Rn | 0011 nnnn mmmm 1010 | SH-1 | Rn = Rn - Rm - T; T = the borrow. |
subv Rm,Rn | 0011 nnnn mmmm 1011 | SH-1 | Rn = Rn - Rm; T = 1 on signed underflow. |
neg Rm,Rn | 0110 nnnn mmmm 1011 | SH-1 | Rn = 0 - Rm. |
negc Rm,Rn | 0110 nnnn mmmm 1010 | SH-1 | Rn = 0 - Rm - T; T = the borrow. |
dt Rn | 0100 nnnn 0001 0000 | SH-2 | Rn = Rn - 1; T = 1 when the result is 0. The loop counter of a dt and bf pair. |
Compare
Compares set the T bit and change nothing else; bt and bf test it.
In cmp/xx Rm,Rn the comparison is "Rn xx Rm".
| Instruction | Encoding | Chip | T = 1 when |
|---|---|---|---|
cmp/eq Rm,Rncmp/eq #imm,R0 | 0011 nnnn mmmm 00001000 1000 iiiiiiii | SH-1 | Rn = Rm; R0 = the sign-extended immediate. |
cmp/hs Rm,Rn | 0011 nnnn mmmm 0010 | SH-1 | Rn >= Rm, unsigned. |
cmp/ge Rm,Rn | 0011 nnnn mmmm 0011 | SH-1 | Rn >= Rm, signed. |
cmp/hi Rm,Rn | 0011 nnnn mmmm 0110 | SH-1 | Rn > Rm, unsigned. |
cmp/gt Rm,Rn | 0011 nnnn mmmm 0111 | SH-1 | Rn > Rm, signed. |
cmp/pl Rn | 0100 nnnn 0001 0101 | SH-1 | Rn > 0, signed. |
cmp/pz Rn | 0100 nnnn 0001 0001 | SH-1 | Rn >= 0, signed. |
cmp/str Rm,Rn | 0010 nnnn mmmm 1100 | SH-1 | any one of the four bytes of Rn equals the byte in the same place of Rm (used to find a zero byte in a string). |
Multiply and multiply-accumulate
| Instruction | Encoding | Chip | What it does |
|---|---|---|---|
mul.l Rm,Rn | 0000 nnnn mmmm 0111 | SH-2 | MACL = Rn * Rm, the low 32 bits. |
muls.w Rm,Rn | 0010 nnnn mmmm 1111 | SH-1 | MACL = the signed low word of Rn times the signed low word of Rm. |
mulu.w Rm,Rn | 0010 nnnn mmmm 1110 | SH-1 | The same, unsigned. |
dmuls.l Rm,Rn | 0011 nnnn mmmm 1101 | SH-2 | MACH:MACL = Rn * Rm, signed 64-bit result. |
dmulu.l Rm,Rn | 0011 nnnn mmmm 0101 | SH-2 | MACH:MACL = Rn * Rm, unsigned 64-bit result. |
mac.w @Rm+,@Rn+ | 0100 nnnn mmmm 1111 | SH-1 | Multiply the signed words at Rm and Rn, add the 32-bit product to MACL (saturating to 32 bits when the S bit is 1; with S = 0 the sum is 64 bits in MACH:MACL); both pointers advance by 2. |
mac.l @Rm+,@Rn+ | 0000 nnnn mmmm 1111 | SH-2 | Multiply the signed longwords at Rm and Rn, add the 64-bit product to MACH:MACL (saturating to 48 bits when S = 1); both pointers advance by 4. |
Division
There is no divide instruction: a 32-bit division is a div0s or div0u setup followed by 32 div1 steps (each with a
rotcl to collect the quotient bit), using the Q, M and T bits.
| Instruction | Encoding | Chip | What it does |
|---|---|---|---|
div0s Rm,Rn | 0010 nnnn mmmm 0111 | SH-1 | Signed setup: Q = the sign of Rn, M = the sign of Rm, T = Q xor M. |
div0u | 0000 0000 0001 1001 | SH-1 | Unsigned setup: M = Q = T = 0. |
div1 Rm,Rn | 0011 nnnn mmmm 0100 | SH-1 | One step: shifts Rn left through T, then adds Rm or subtracts it depending on Q and M, and updates Q and T. |
Extend
| Instruction | Encoding | Chip | What it does |
|---|---|---|---|
exts.b Rm,Rn | 0110 nnnn mmmm 1110 | SH-1 | Rn = the low byte of Rm, sign-extended. |
exts.w Rm,Rn | 0110 nnnn mmmm 1111 | SH-1 | Rn = the low word of Rm, sign-extended. |
extu.b Rm,Rn | 0110 nnnn mmmm 1100 | SH-1 | Rn = the low byte of Rm, zero-extended. |
extu.w Rm,Rn | 0110 nnnn mmmm 1101 | SH-1 | Rn = the low word of Rm, zero-extended. |
Not described
Known, not yet covered
- Reference and viewer: the SH-2A
divs,divu,mulr,clips,clipuand the DSP multiply instructions.
Unknown
- Reference: the exact saturation limits of
mac.wandmac.land the cycle counts were not checked against a manual.