# The Z80 Instruction Set

A B C D E H I J L N O P R S X

- ADC ADD AND
- BIT
- CALL CCF CP CPD CPDR CPI CPIR CPL
- DAA DEC DI DJNZ
- EI EX EXX
- HALT
- IM IN INC IND INDR INI INIR
- JP JR
- LD LDD LDDR LDI LDIR
- NEG NOP
- OR OTDR OTIR OUT OUTD OUTI
- POP PUSH
- RES RET RETI RETN RL RLA RLC RLCA RLD RR RRA RRC RRCA RRD RST
- SBC SCF SET SLA SLL SRA SRL SUB
- XOR

The lists contains all the normal machine code instructions for the microprocessor, plus a number of undocumented ones. The latter comprise those which operate on the high or low bytes of the Index registets (IX and lY) which are notated here as HIX, LIX, HIY and LIY - some assemblers may use the form IXH, etc - and a set of rotation instructions complementary to SRL, which are designated SLL.

### The Opcodes and T states

Within the tables of instructions, a number of abbreviations are used:

d | displacement (a value from -128 (&80) to +127 (&7F))
n | a single byte value (from 0 (&00) to 255 (&FF))
hilo | a double byte value (from -32768 (&8000) via 0 to 32767 (&7FFF))
addr | an address value (from 0 (&0000) to 65535 (&FFFF))

(in the sequence of opcode bytes, `addr' and `hilo' are entered low byte first)

The next two columns detail the number of bytes applicable to each instruction, and the number of T states (clock pulses) that each requires - some have two figures which are distinguised as follows:

f | means `the number of T states required when the condition is false'
t | means `the number of T states needed when the condition is true'
= | means `the number of T states needed when either BC=0 and/or A matches the contents of HL'
# | means `the number of T states required when both the above conditions are false'
z | means `the number of T states needed when B=0'
nz | means `the number of T states requrred when B<>0'

### The Flag Register

The last columns give the effect on the flag bits which each instruction causes:

? | means the setting of the bit is unpredictable
- | means the setting of the bit is unchanged
0 | means that the flag bit is reset to zero
1 | means that the flag bit is set to one.
POP | means that the flag bit is determined by whatever is taken from the stack.
In addition, the Sign flag (bit 7) is also set:
7 | if bit 7 of the A register is set
15 | if bit 15 of the HL register pair (ie bit 7 of the H register) is set
=7 | if bit 7 of the A register would be set by subtraction in lieu of CP
The Zero flag (bi6 6) is also set:
z | if the A register or the HL register pair equals zero
= | if the A register matches the compared register or value
=A | if the A register matches the contents of the address pointed to by HL
<>B | if the B register holds zero
<>b | if the bit tested is zero
The Parity/Overflow flag (bit 2) is also set:
p | if the register concemed contains an even number of set bits
v | if an overflow has occured in Two's Complement arithmetic
BC | if BC is not zero
A80 | if the A register was &80 before this instruction was performed
i | to the contents of the microprocessor's internal interrupt register
The Carry flag (bit 0) is also set:
c | if an addition resulted in a carry out of bit 7 (for a register) or bit 15 (for a register pair)
b | if a subtraction required a borrow from bit 7 (for a register) or bit 15 (for a register pair)
< | if the A register is less than the value or register that is being compared
r0 | by the bit rotated in from bit 0 of the register concerned
r7 | by the bit rotated in from bit 7 of the register concerned
x | if the Carry was reset (ie zero) before this instruction was performed
A0 | if tbe A register was &00 before this instruction was performed

The flag register is bit significant, and the bits are defined as follows:

- 7 - Sign
- 6 - Zero
- 5 - unused
- 4 - Half Carry (cannot test)
- 3 - unused
- 2 - Parity/Overflow
- 1 - Add/Subtract (cannot test)
- 0 - Carry