SUB Subtract without Carry
Subtraction without Carry
\(A \longleftarrow A - s\)
This s operand is any of r, n, (HL), (IX+d), or (IY+d).
These possible op code/operand combinations are assembled as follows in the object code:
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |
---|---|---|---|---|---|---|---|---|
SUB r | ||||||||
1 | 0 | 0 | 1 | 0 | r | |||
SUB n | ||||||||
1 | 1 | 0 | 1 | 0 | 1 | 1 | 0 | D6 |
n | ||||||||
SUB (HL) | ||||||||
1 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 96 |
SUB (IX+d) | ||||||||
1 | 1 | 0 | 1 | 1 | 1 | 0 | 1 | DD |
1 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 96 |
d | ||||||||
SUB (IX+d) | ||||||||
1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | FD |
1 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 96 |
d |
Register | r |
---|---|
B | 000 |
C | 001 |
D | 010 |
E | 011 |
H | 100 |
L | 101 |
A | 111 |
Flags Affected
Flags |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
s | set if result negative | ||||||||
z | set if result is 0 | ||||||||
h | set if borrow from bit 4 | ||||||||
p/v | set if overflow | ||||||||
c | set if borrow |
Opcode Matrix
A | B | C | D | E | H | L | (HL) | (IX+d) | (IY+d) | n | |
---|---|---|---|---|---|---|---|---|---|---|---|
A |
SUB A,A
9714 |
SUB A,B
9014 |
SUB A,C
9114 |
SUB A,D
9214 |
SUB A,E
9314 |
SUB A,H
9414 |
SUB A,L
9514 |
SUB A,(HL)
9617 |
SUB A,(IX+d)
DD96nn319 |
SUB A,(IY+d)
FD96nn319 |
SUB A,n
D6nn27 |
Instruction
Opcode hexSize bytesCycle count
| Register | Memory | Implicit |
Last modified November 16, 2021: Add flags to math operations (63d34c2)