Detailed Z80 Instruction Set
Detailed Z80 Instruction Set
COM
Page 1
Table of Contents 1- 8-bit Load Instructions 2- 16-bit Load Instructions 3- Exchange, Block Transfer and Search Instructions 4- 8-bit Arithmetic and Logical Instructions 5- 16-bit Arithmetic Instructions 6- General Purpose Arithmetic and CPU Control Instructions 7- Rotate and Shift Instructions 8- Bit Manipulation Instructions 9- Input and Output (I/O) Instructions 10- Jump Instructions 11- Call and Return Instructions
Page 2 3 4 5 6 6 7 8 9 10 11
Page 1 of 11
EE422
2009/2010
INELECSHARE.ICR38.NET INELEC.COMXA.COM
Page 2
p, p Reg. 000 001 010 011 100 101 111 q, q 000 001 010 011 100 101 111 B C D E IXH IXL A Req. B C D E IYH IYL A
LD q, n* LD r, (HL) LD r, (IX + d)
11 7 19
19 7 19
19 10
LD (IX + d), n
19
Notes:
Flag Notation:
Page 2 of 11
EE422
2009/2010
INELECSHARE.ICR38.NET INELEC.COMXA.COM
Page 3
LD IX, nn
IX nn
DD 21
14
LD IY, nn
IY nn L (nn) H (nn+1) ddL (nn) ddH (nn+1) IXL (nn) IXH (nn+1) IYL (nn) IYH (nn+1) (nn) L (nn+1) H (nn) ddL (nn+1) ddH (nn) IXL (nn+1) IXH (nn) IYL (nn+1) IYH SP HL SP IX SP IY
FD 21
14
LD HL, (nn)
2A
16
LD dd, (nn)
ED
20
LD IX, (nn)
DD 2A
20
LD IY, (nn)
FD 2A
20
LD (nn), HL
22
16
LD (nn), dd
DD
20
LD (nn), IX
DD 22
20
FD 22 F9 DD F9 FD F9
4 1 2 2
6 1 2 2
20 6 10 10
PUSH qq
PUSH IX
PUSH IY
POP qq
POP IX
POP IY
SP SP 1 (SP) qqH 11 qq0 101 1 3 11 SP SP 1 (SP) qqL SP SP 1 11 011 101 DD (SP) IXH 2 4 15 11 100 101 E5 SP SP 1 (SP) IXL SP SP 1 11 111 101 FD (SP) IYH 2 4 15 11 100 101 E5 SP SP - 1 (SP) IYL (SP) qqL SP SP + 1 11 qq0 001 1 3 10 (SP) qqH SP SP + 1 (SP) IXL 11 011 101 DD SP SP + 1 2 4 14 11 100 001 E1 (SP) IXH SP SP + 1 (SP) IYL 11 111 101 FD SP SP + 1 2 4 14 11 100 001 E1 (SP) IYH SP SP + 1 dd is any of the register pair BC, DE, HL, SP. qq is any of the register pair BC, DE, HL, AF. = flag is not affected, 0 = flag is reset, 1 = flag is set, b = flag is set according to the result of the operation.
qq 00 01 10 11
Pair BC DE HL AF
Page 3 of 11
EE422
2009/2010
INELECSHARE.ICR38.NET INELEC.COMXA.COM
Page 4
LDI
LDIR
if BC 0 if BC = 0
LDD
LDDR
if BC 0 if BC = 0
CPI
CPIR
CPD
CPDR
Notes:
Flag Notation:
Page 4 of 11
EE422
2009/2010
INELECSHARE.ICR38.NET INELEC.COMXA.COM
Page 5
ADD A, (IY + d) ADC A, s SUB A, s SBC A, s AND s OR s XOR s CP s INC r INC p* INC q* INC (HL) INC (IX + d)
V V V V P P P V V V V V V
0 0 1 1 0 0 0 1 0 0 0 0 0
FD
19 s is any of r, n, (HL), (IX+d), (IY+d), p, q as shown for the ADD instruction. The underlined bits replace the underlined bits in the ADD set.
1 DD FD 2 2 1 DD 3
1 2 2 3 6
4 8 8 11 23 q 000 001 010 011 100 101 111 Reg. B C D E IYH IYL A
b b b b b b b b b b
INC (IY + d)
FD
23 m is any of r, p, q, (HL), (IX+d), (IY+d), as shown for the INC instruction. DEC same format and states as INC. Replace 100 with 101 in opcode.
DEC m
mm1
b b
101
Notes:
Flag Notation:
F5 and F3 are copied from the operand (s), not from the result of (A s). The V symbol in the P/V flag column indicates that the P/V flag contains the overflow of the operation. Similarly the P symbol indicates parity. r means any of the registers A, B, C, D, E, H, L. p means any of the registers A, B, C, D, E, IXH, IXL. q means any of the registers A, B, C, D, E, IYH, IYL. ddL, ddH refer to high order and low order eight bits of the register respectively. CY means the carry flip-flop. * means unofficial instruction. = flag is not affected, 0 = flag is reset, 1 = flag is set, b = flag is set according to the result of the operation.
Page 5 of 11
EE422
2009/2010
INELECSHARE.ICR38.NET INELEC.COMXA.COM
Page 6
Notes:
Flag Notation:
DAA
CPL NEG
4
IM 0 IM 1 IM 2
Notes:
Flag Notation:
Page 6 of 11
EE422
2009/2010
INELECSHARE.ICR38.NET INELEC.COMXA.COM
Page 7
b b b b b b
RLC (IX + d)
23
Reg. B C D E H L A
b b
FD CB
23
b b
DD CB
23
LD r,RLC (IY + d)* RL m RRC m RR m SLA m SLL m* SRA m SRL m RLD RRD
b b b b b b b b b b b b b b b b
b b b b b b b b b b
0 0 0 0 0 0 0 0 0 0
b b b b b b b b b b
P P P P P P P P P P
0 0 0 0 0 0 0 0 0 0
b b b b b b b b
FD CB
23
Instruction format and states are the same as RLC. Replace 000 with new number.
b b b b
ED 6F
18
11 101 101 ED 2 5 18 01 100 111 67 The P symbol in the P/V flag column indicates that the P/V flag contains the parity of the result. r means any of the registers A, B, C, D, E, H, L. * means unofficial instruction. CY means the carry flip-flop. = flag is not affected, 0 = flag is reset, 1 = flag is set, b = flag is set according to the result of the operation.
Page 7 of 11
EE422
2009/2010
INELECSHARE.ICR38.NET INELEC.COMXA.COM
Page 8
Flags S Z F5 H F3 P/V N C b b b b b b
1 1 1
b b b
1 1
b b b
b b b
0 0
BIT b, (IX + d)
BIT b, (IY + d)
b b
Opcode 76 543 210 11 001 011 01 b r 11 001 011 01 b 110 11 011 101 11 001 011 d 01 b 110 11 111 101 11 001 011 d 01 b 110 11 001 011 11 b r 11 001 011 11 b 110 11 011 101 11 001 011 d 11 b 110 11 111 101 11 001 011 d 11 b 110 11 011 101 11 001 011 d 11 b r 11 111 101 11 001 011 d 11 b r
Opcode Hex CB CB DD CB
# of Bytes 2 2
# of ~ 2 3
No. of T States 8 12
20
FD CB CB CB
2 2
2 4
8 15
SET b, (IX + d)
(IX + d)b 1
DD CB
23
SET b, (IY + d)
FD CB
23
DD CB
23
FD CB
23 To form new opcode replace 11 of SET b, s with 10. Flags and states are the same.
RES b, m
10
Notes:
Flag Notation:
The notation mb indicates bit b (0 to 7) of location m. BIT instructions are performed by an bitwise AND. 1 S is set if b = 7 and Z = 0 2 F5 is set if b = 5 and Z = 0 3 F3 is set if b = 3 and Z = 0 4 P/V is set like the Z flag 5 This instruction has other unofficial opcodes * means unofficial instruction. = flag is not affected, 0 = flag is reset, 1 = flag is set, b = flag is set according to the result of the operation.
Page 8 of 11
EE422
2009/2010
INELECSHARE.ICR38.NET INELEC.COMXA.COM
Page 9
0 0 b
3
b b b
1
P P X
0 0 b
2
b
3
b b b b b b
1 1
Opcode 76 543 210 11 011 011 n 11 101 101 01 r 000 11 101 101 01 110 000 11 101 101 10 100 010
Opcode Hex DB ED ED 70 ED A2
# of Bytes 2 2 2 2
# of ~ 3 3 3 4
No. of T States 11 12 12 16
INIR
0 1
ED B2
2 2
5 4
21 16
if B 0 if B = 0
IND
b b
ED AA
16
INDR
0 1
11 101 101 10 111 010 11 010 011 n 11 101 101 01 r 001 11 101 101 01 110 001
ED BA
2 2
5 4
21 16
if B 0 if B = 0
D3 ED ED 71
2 2 2
3 3 3
11 12 12
OTIR
OUTD
OTDR
Notes:
Flag Notation:
(C) (HL) 11 101 101 ED 1 1 1 1 2 4 16 HL HL + 1 b b b X b X X X 10 100 011 A3 BB-1 (C) (HL) HL HL + 1 21 11 101 101 ED 2 5 if B 0 0 1 0 X 0 X X X BB1 10 110 011 B3 2 4 16 if B = 0 Repeat until B=0 (C) (HL) 11 101 101 ED 1 1 1 1 2 4 16 HL HL 1 b b b X b X X X 10 101 011 AB BB1 (C) (HL) HL HL 1 21 11 101 101 ED 2 5 if B 0 0 1 0 X 0 X X X BB1 10 111 011 BB 2 4 16 if B = 0 Repeat until B=0 The V symbol in the P/V flag column indicates that the P/V flags contain the overflow of the operation. Similarly the P symbol indicates parity. r means any of the registers A, B, C, D, E, H, L. 1 flag is affected by the result of B B 1 as in DEC B. 2 N is a copy bit 7 of the last value from the input (C). 3 this flag contains the carry of ( ( (C + 1) AND 255) + (C) ) 4 this flag contains the carry of ( ( (C 1) AND 255) + (C) ) * means unofficial instruction. = flag is not affected, 0 = flag is reset, 1 = flag is set, X = flag is unknown, b = flag is set according to the result of the operation.
Page 9 of 11
EE422
2009/2010
INELECSHARE.ICR38.NET INELEC.COMXA.COM
Page 10
Jump Instructions
Mnemonic JP nn Symbolic Operation PC nn Flags S Z F5 H F3 P/V N C Opcode 76 543 210 11 000 011 n n Opcode Hex C3 # of Bytes 3 # of ~ 3 No. of T States 10 ccc 000 001 010 011 100 101 110 Condition NZ Z NC C PO PE P Comments
JP cc, nn
if cc is true, PC nn
11 ccc 010 n n
10
PC PC + e if ss is true PC PC + e PC HL PC IX PC IY
00 011 000 e 2 00 sss 000 e 2 11 101 001 11 011 101 11 101 001 11 111 101 11 101 001
18
2 2 2 1 2 2
3 3 2 1 2 2
12 12 7 4 8 8
E9 DD E9 FD E9
BB1 00 010 000 2 2 8 10 if B 0 2 3 13 e 2 PC PC + e e is a signed twos-complement number in the range <126, 129> e 2 in the opcode provides an effective number of PC + e as PC incremented by 2 prior to the addition of e. = flag is not affected, 0 = flag is reset, 1 = flag is set, b = flag is set according to the result of the operation.
EE422
2009/2010
INELECSHARE.ICR38.NET INELEC.COMXA.COM
Page 11
Mnemonic Symbolic Operation SP SP 1 (SP) PCH SP SP 1 (SP) PCL PC nn if cc is true, SP SP 1 (SP) PCH SP SP 1 (SP) PCL PC nn PCL (SP) SP SP + 1 PCH (SP) SP SP + 1 if cc is true, PCL (SP) SP SP + 1 PCH (SP) SP SP + 1 PCL (SP) SP SP + 1 PCH (SP) SP SP + 1 PCL (SP) SP SP + 1 PCH (SP) SP SP + 1 IFF1 IFF2 SP SP 1 (SP) PCH SP SP 1 (SP) PCL PC p
1
Flags S Z F5 H F3 P/V N C
Opcode Hex
# of Bytes
# of ~
No. of T States
Comments
CALL nn
CD
17
CALL cc, nn
11 ccc 100 n n
3 3
3 5
10 17
if cc is false if cc is true
RET
11 001 001
C9
10
RET cc
11 ccc 000
1 1
1 3
5 11
if cc is false if cc is true ccc 000 001 010 011 100 101 110 111 t 000 001 010 011 100 101 110 111 Condition NZ Z NC C PO PE P M p 0h 8h 10h 18h 20h 28h 30h 38h
RETI
ED 4D
14
RETN
1,2
ED 45
14
RST p
11 t 111
11
This instruction has other unofficial opcodes, see Opcode list. Instruction also IFF1 IFF2
= flag is not affected, 0 = flag is reset, 1 = flag is set, b = flag is set according to the result of the operation.
Page 11 of 11
EE422
2009/2010