ADC
8-bit Arithmetic Group | 16-Bit Arithmetic Group
Expansion:
ADd with Carry
Usage:
adc {r|rr}, {r|rr}
The ADC operation adds two 8-bit or 16-bit registers together. It sets the carry bit if it exceeds 255 in the calculation otherwise it is reset.
| Mnemonic | Opcode |
|---|---|
| ABC A, (HL) | 8E |
| ABC A, (IX + ±??) | DD 8E ?? |
| ABC A, (IY + ±??) | FD 8E ?? |
| ABC A, A | 8F |
| ABC A, B | 88 |
| ABC A, C | 89 |
| ABC A, D | 8A |
| ABC A, ?? | CE ?? |
| ABC A, E | 8B |
| ABC A, H | 8C |
| ABC A, L | 8D |
| ABC HL, BC | ED 4A |
| ABC HL, DE | ED 5A |
| ABC HL, HL | ED 6A |
| ABC HL, SP | ED 7A |
Example
; Example
ld a, $04 ; move the value 5 to reg A
ld b, $03 ; move the value 3 to reg B
adc a, b ; add B and A resulting in 07 being in reg A
Carry operation
; Example
ld a, $FF ; move the value 255 to reg A
ld b, $03 ; move the value 3 to reg B
adc a, b ; add B and A resulting in 0x02 being in reg A
If we do not use SCF (set carry flag) then we are performing a (255 + 3 + 0 = 258) 258 mod 256 = 2
Carry operation with SCF
; Example
ld a, $FF ; move the value 255 to reg A
ld b, $03 ; move the value 3 to reg B
SCF ; set the carry flag
adc a, b ; add B and A resulting in 3 being in reg A
If we do SCF (set carry flag) then we are performing a (255 + 3 + 1 = 258) 258 mod 256 = 3