Arithmetic Instructions

How to decode arithmetic instructions from binary

Opcodes with bits 7…5 set to 100 are the arithmetic instructions ADD, ADC, SUB and SBC. As are those starting with 7…6 set to 11 but ending with bits 2…0 set to 110. These instructions take an additional numeric operand after the opcode and use that instead of a register as the source.

Those with 7…5 set to 101 are the logic instructions AND, XOR, OR and CP.

Opcode format
76543210
 
Arithmetic with register as source, e.g. ADD A
100AFr
 
Logic with register as source, e.g. OR A
101AFr
 
8 bit number as source, e.g. SUB 5
11XAF110
n
Lookup for A and F bits
765AFInstructionr
10000 ADC r register or
110 = (HL)
1 ADD r
10 SBC r
1 SUB r
100 AND r
1 XOR r
10 OR r
1 CP r
1000 ADC n Always set to 110
1 ADD n
10 SBC n
1 SUB n
100 AND n
1 XOR n
10 OR n
1 CP n
Registers
Registerr
B000
C001
D010
E011
H100
L101
A111