Zilog Z80 instruction set: Difference between revisions
m (→LD r, r') |
|||
(8 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
__FORCETOC__ | __FORCETOC__ | ||
The '''Zilog Z80 instruction set''' is a simple set of instructions. There are several extensions which provides an | The '''Zilog Z80 instruction set''' is a simple set of instructions originating with the [[Zilog Z80|Z80]] and based upon the [[Intel 8080 instruction set]]. There are several extensions which provides an additional set of instructions, some of which are only available on the [[Zilog Z180|Z180]] and newer or may be undocumented instructions introduced by other manufacturers than [[Zilog]]. | ||
== OpCode Tables == | == OpCode Tables == | ||
Line 25: | Line 25: | ||
|- | |- | ||
|{{Rh}}|0 | |{{Rh}}|0 | ||
|nop | |[[Zilog Z80 instruction set#nop|nop]] | ||
|ld bc,''nn'' | |ld bc,''nn'' | ||
|ld (bc),a | |ld (bc),a | ||
|inc bc | |inc bc | ||
|inc b | |[[Zilog Z80 instruction set#incr|inc b]] | ||
|dec b | |[[Zilog Z80 instruction set#decr|dec b]] | ||
|[[Zilog Z80 instruction set#ld-rn|ld b,''n'']] | |[[Zilog Z80 instruction set#ld-rn|ld b,''n'']] | ||
|rlca | |rlca | ||
|ex af,af' | |[[Zilog Z80 instruction set#ex-af|ex af,af']] | ||
|add hl,bc | |add hl,bc | ||
|ld a,(bc) | |ld a,(bc) | ||
|dec bc | |dec bc | ||
|inc c | |[[Zilog Z80 instruction set#incr|inc c]] | ||
|dec c | |[[Zilog Z80 instruction set#decr|dec c]] | ||
|[[Zilog Z80 instruction set#ld-rn|ld c,''n'']] | |[[Zilog Z80 instruction set#ld-rn|ld c,''n'']] | ||
|rrca | |rrca | ||
Line 47: | Line 47: | ||
|ld (de),a | |ld (de),a | ||
|inc de | |inc de | ||
|inc d | |[[Zilog Z80 instruction set#incr|inc d]] | ||
|dec d | |[[Zilog Z80 instruction set#decr|dec d]] | ||
|[[Zilog Z80 instruction set#ld-rn|ld d,''n'']] | |[[Zilog Z80 instruction set#ld-rn|ld d,''n'']] | ||
|rla | |rla | ||
Line 55: | Line 55: | ||
|ld a,(de) | |ld a,(de) | ||
|dec de | |dec de | ||
|inc e | |[[Zilog Z80 instruction set#incr|inc e]] | ||
|dec e | |[[Zilog Z80 instruction set#decr|dec e]] | ||
|[[Zilog Z80 instruction set#ld-rn|ld e,''n'']] | |[[Zilog Z80 instruction set#ld-rn|ld e,''n'']] | ||
|rra | |rra | ||
Line 65: | Line 65: | ||
|ld (''nn''),hl | |ld (''nn''),hl | ||
|inc hl | |inc hl | ||
|inc h | |[[Zilog Z80 instruction set#incr|inc h]] | ||
|dec h | |[[Zilog Z80 instruction set#decr|dec h]] | ||
|[[Zilog Z80 instruction set#ld-rn|ld h,''n'']] | |[[Zilog Z80 instruction set#ld-rn|ld h,''n'']] | ||
|daa | |daa | ||
Line 73: | Line 73: | ||
|ld hl,(''nn'') | |ld hl,(''nn'') | ||
|dec hl | |dec hl | ||
|inc l | |[[Zilog Z80 instruction set#incr|inc l]] | ||
|dec l | |[[Zilog Z80 instruction set#decr|dec l]] | ||
|[[Zilog Z80 instruction set#ld-rn|ld l,''n'']] | |[[Zilog Z80 instruction set#ld-rn|ld l,''n'']] | ||
|cpl | |cpl | ||
Line 85: | Line 85: | ||
|inc (hl) | |inc (hl) | ||
|dec (hl) | |dec (hl) | ||
|ld (hl),''n'' | |[[Zilog Z80 instruction set#ld-hln|ld (hl),''n'']] | ||
|scf | |scf | ||
|jr c,d | |jr c,d | ||
Line 91: | Line 91: | ||
|ld a,(''nn'') | |ld a,(''nn'') | ||
|dec sp | |dec sp | ||
|inc a | |[[Zilog Z80 instruction set#incr|inc a]] | ||
|dec a | |[[Zilog Z80 instruction set#decr|dec a]] | ||
|[[Zilog Z80 instruction set#ld-rn|ld a,''n'']] | |[[Zilog Z80 instruction set#ld-rn|ld a,''n'']] | ||
|ccf | |ccf | ||
Line 241: | Line 241: | ||
|- | |- | ||
|{{Rh}}|C | |{{Rh}}|C | ||
|ret nz | |[[Zilog Z80 instruction set#retcc|ret nz]] | ||
|pop bc | |pop bc | ||
|jp nz,''nn'' | |[[Zilog Z80 instruction set#jpccnn|jp nz,''nn'']] | ||
|jp nn | |[[Zilog Z80 instruction set#jpnn|jp nn]] | ||
|call nz,''nn'' | |[[Zilog Z80 instruction set#callccnn|call nz,''nn'']] | ||
|push bc | |push bc | ||
|add a,''n'' | |add a,''n'' | ||
|rst 00h | |[[Zilog Z80 instruction set#rst|rst 00h]] | ||
|ret z | |[[Zilog Z80 instruction set#retcc|ret z]] | ||
|ret | |[[Zilog Z80 instruction set#ret|ret]] | ||
|jp z,''nn'' | |[[Zilog Z80 instruction set#jpccnn|jp z,''nn'']] | ||
|{{optional|[[#ext-bit|''Bit Ext.'']]}} | |{{optional|[[#ext-bit|''Bit Ext.'']]}} | ||
|call z,''nn'' | |[[Zilog Z80 instruction set#callccnn|call z,''nn'']] | ||
|call nn | |[[Zilog Z80 instruction set#call-nn|call ''nn'']] | ||
|adc a,''n'' | |adc a,''n'' | ||
|rst 08h | |[[Zilog Z80 instruction set#rst|rst 08h]] | ||
|- | |- | ||
|{{Rh}}|D | |{{Rh}}|D | ||
|ret nc | |[[Zilog Z80 instruction set#retcc|ret nc]] | ||
|pop de | |pop de | ||
|jp nc,''nn'' | |[[Zilog Z80 instruction set#jpccnn|jp nc,''nn'']] | ||
|out (''n''),a | |out (''n''),a | ||
|call nc,''nn'' | |[[Zilog Z80 instruction set#callccnn|call nc,''nn'']] | ||
|push de | |push de | ||
|sub n | |sub n | ||
|rst 10h | |[[Zilog Z80 instruction set#rst|rst 10h]] | ||
|ret c | |[[Zilog Z80 instruction set#retcc|ret c]] | ||
|exx | |[[Zilog Z80 instruction set#exx|exx]] | ||
|jp c,''nn'' | |[[Zilog Z80 instruction set#jpccnn|jp c,''nn'']] | ||
|in a,(''n'') | |in a,(''n'') | ||
|call c,''nn'' | |[[Zilog Z80 instruction set#callccnn|call c,''nn'']] | ||
|{{optional|[[#ext-ix|''IX Ext.'']]}} | |{{optional|[[#ext-ix|''IX Ext.'']]}} | ||
|sbc a,''n'' | |sbc a,''n'' | ||
|rst 18h | |[[Zilog Z80 instruction set#rst|rst 18h]] | ||
|- | |- | ||
|{{Rh}}|E | |{{Rh}}|E | ||
|ret po | |[[Zilog Z80 instruction set#retcc|ret po]] | ||
|pop hl | |pop hl | ||
|jp po,''nn'' | |[[Zilog Z80 instruction set#jpccnn|jp po,''nn'']] | ||
|ex (sp),hl | |ex (sp),hl | ||
|call po,''nn'' | |[[Zilog Z80 instruction set#callccnn|call po,''nn'']] | ||
|push hl | |push hl | ||
|and n | |and n | ||
|rst 20h | |[[Zilog Z80 instruction set#rst|rst 20h]] | ||
|ret pe | |[[Zilog Z80 instruction set#retcc|ret pe]] | ||
|jp (hl) | |jp (hl) | ||
|jp pe,''nn'' | |[[Zilog Z80 instruction set#jpccnn|jp pe,''nn'']] | ||
|ex de,hl | |ex de,hl | ||
|call pe,''nn'' | |[[Zilog Z80 instruction set#callccnn|call pe,''nn'']] | ||
|{{optional|[[#exit-misc|''Misc.'']]}} | |{{optional|[[#exit-misc|''Misc.'']]}} | ||
|xor n | |xor n | ||
|rst 28h | |[[Zilog Z80 instruction set#rst|rst 28h]] | ||
|- | |- | ||
|{{Rh}}|F | |{{Rh}}|F | ||
|ret p | |[[Zilog Z80 instruction set#retcc|ret p]] | ||
|pop af | |pop af | ||
|jp p,''nn'' | |[[Zilog Z80 instruction set#jpccnn|jp p,''nn'']] | ||
|di | |[[Zilog Z80 instruction set#di|di]] | ||
|call p,''nn'' | |[[Zilog Z80 instruction set#callccnn|call p,''nn'']] | ||
|push af | |push af | ||
|or n | |or n | ||
|rst 30h | |[[Zilog Z80 instruction set#rst|rst 30h]] | ||
|ret m | |[[Zilog Z80 instruction set#retcc|ret m]] | ||
|ld sp,hl | |ld sp,hl | ||
|jp m,''nn'' | |[[Zilog Z80 instruction set#jpccnn|jp m,''nn'']] | ||
|ei | |[[Zilog Z80 instruction set#ei|ei]] | ||
|call m,''nn'' | |[[Zilog Z80 instruction set#callccnn|call m,''nn'']] | ||
|{{optional|[[#exit-iy|''IY Ext.'']]}} | |{{optional|[[#exit-iy|''IY Ext.'']]}} | ||
|cp n | |cp n | ||
|rst 38h | |[[Zilog Z80 instruction set#rst|rst 38h]] | ||
|} | |} | ||
== Instruction Details == | == Instruction Details == | ||
{{Collapse top|title=Instruction notations}} | |||
{{Collapse top}} | |||
{| class="wikitable" | {| class="wikitable" | ||
!Notation | !Notation | ||
Line 371: | Line 369: | ||
{{Collapse bottom}} | {{Collapse bottom}} | ||
=== 8-bit Load | === 8-bit Load Operations === | ||
{{Further|topic=Zilog Z80 Load Details}} | |||
==== LD ''r'', ''r''' {{Anchor|ld-rr}} ==== | ==== LD ''r'', ''r''' {{Anchor|ld-rr}} ==== | ||
Line 735: | Line 734: | ||
M Cycles: 5, T States: 19 (4, 4, 3, 5, 3) | M Cycles: 5, T States: 19 (4, 4, 3, 5, 3) | ||
==== LD ''(IY+d)''''', '' | ==== LD ''(IY+d)''''',''' ''r''{{Anchor|ld-iydr}} ==== | ||
{| class="wikitable defaultcenter" | {| class="wikitable defaultcenter" | ||
!7 | !7 | ||
Line 794: | Line 793: | ||
M Cycles: 5, T States: 19 (4, 4, 3, 5, 3) | M Cycles: 5, T States: 19 (4, 4, 3, 5, 3) | ||
=== 16-bit Load and Stack Operations === | |||
{{Expand section}} | |||
=== Exchange Operations === | |||
{{Expand section}} | |||
=== Block Transfer Operations === | |||
{{Expand section}} | |||
=== Block Search Operations === | |||
{{Expand section}} | |||
=== 8-bit Arithmetic Operations === | |||
{{Expand section}} | |||
=== 16-bit Arithmetic Operations === | |||
{{Expand section}} | |||
=== Bit Manipulation Operations === | |||
{{Expand section}} | |||
=== Branching and Routine Operations === | |||
{{Expand section}} | |||
=== Input/Output Operations === | |||
{{Expand section}} |
Latest revision as of 03:44, 19 March 2024
The Zilog Z80 instruction set is a simple set of instructions originating with the Z80 and based upon the Intel 8080 instruction set. There are several extensions which provides an additional set of instructions, some of which are only available on the Z180 and newer or may be undocumented instructions introduced by other manufacturers than Zilog.
OpCode Tables
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | nop | ld bc,nn | ld (bc),a | inc bc | inc b | dec b | ld b,n | rlca | ex af,af' | add hl,bc | ld a,(bc) | dec bc | inc c | dec c | ld c,n | rrca |
1 | djnz d | ld de,nn | ld (de),a | inc de | inc d | dec d | ld d,n | rla | jr d | add hl,de | ld a,(de) | dec de | inc e | dec e | ld e,n | rra |
2 | jr nz,d | ld hl,nn | ld (nn),hl | inc hl | inc h | dec h | ld h,n | daa | jr z,d | add hl,hl | ld hl,(nn) | dec hl | inc l | dec l | ld l,n | cpl |
3 | jr nc,d | ld sp,nn | ld (nn),a | inc sp | inc (hl) | dec (hl) | ld (hl),n | scf | jr c,d | add hl,sp | ld a,(nn) | dec sp | inc a | dec a | ld a,n | ccf |
4 | ld b,b | ld b,c | ld b,d | ld b,e | ld b,h | ld b,l | ld b,(hl) | ld b,a | ld c,b | ld c,c | ld c,d | ld c,e | ld c,h | ld c,l | ld c,(hl) | ld c,a |
5 | ld d,b | ld d,c | ld d,d | ld d,e | ld d,h | ld d,l | ld d,(hl) | ld d,a | ld e,b | ld e,c | ld e,d | ld e,e | ld e,h | ld e,l | ld e,(hl) | ld e,a |
6 | ld h,b | ld h,c | ld h,d | ld h,e | ld h,h | ld h,l | ld h,(hl) | ld h,a | ld l,b | ld l,c | ld l,d | ld l,e | ld l,h | ld l,l | ld l,(hl) | ld l,a |
7 | ld (hl),b | ld (hl),c | ld (hl),d | ld (hl),e | ld (hl),h | ld (hl),l | halt | ld (hl),a | ld a,b | ld a,c | ld a,d | ld a,e | ld a,h | ld a,l | ld a,(hl) | ld a,a |
8 | add a,b | add a,c | add a,d | add a,e | add a,h | add a,l | add a,(hl) | add a,a | adc a,b | adc a,c | adc a,d | adc a,e | adc a,h | adc a,l | adc a,(hl) | adc a,a |
9 | sub b | sub c | sub d | sub e | sub h | sub l | sub (hl) | sub a | sbc a,b | sbc a,c | sbc a,d | sbc a,e | sbc a,h | sbc a,l | sbc a,(hl) | sbc a,a |
A | and b | and c | and d | and e | and h | and l | and (hl) | and a | xor b | xor c | xor d | xor e | xor h | xor l | xor (hl) | xor a |
B | or b | or c | or d | or e | or h | or l | or (hl) | or a | cp b | cp c | cp d | cp e | cp h | cp l | cp (hl) | cp a |
C | ret nz | pop bc | jp nz,nn | jp nn | call nz,nn | push bc | add a,n | rst 00h | ret z | ret | jp z,nn | Bit Ext. | call z,nn | call nn | adc a,n | rst 08h |
D | ret nc | pop de | jp nc,nn | out (n),a | call nc,nn | push de | sub n | rst 10h | ret c | exx | jp c,nn | in a,(n) | call c,nn | IX Ext. | sbc a,n | rst 18h |
E | ret po | pop hl | jp po,nn | ex (sp),hl | call po,nn | push hl | and n | rst 20h | ret pe | jp (hl) | jp pe,nn | ex de,hl | call pe,nn | Misc. | xor n | rst 28h |
F | ret p | pop af | jp p,nn | di | call p,nn | push af | or n | rst 30h | ret m | ld sp,hl | jp m,nn | ei | call m,nn | IY Ext. | cp n | rst 38h |
Instruction Details
Instruction notations
| ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
8-bit Load Operations
Error: no page names specified (help).
LD r, r'
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|
0 | 1 | ← r → | ← r' → |
The contents of any register r' is loaded to any other register r. r, r' identifies any of the registers A, B, C, D, E, H or L, as follows:
A | B | C | D | E | H | L |
---|---|---|---|---|---|---|
111 | 000 | 001 | 010 | 011 | 100 | 101 |
Flags affected
None.
Timings
M Cycles: 1, T States: 4
LD r, n
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|
0 | 0 | ← r → | 1 | 1 | 0 | ||
← n → |
The 8-bit integer n is loaded in to any register r, in which r identifies any of the registers A, B, C, D, E, H or L, as follows:
A | B | C | D | E | H | L |
---|---|---|---|---|---|---|
111 | 000 | 001 | 010 | 011 | 100 | 101 |
Flags affected
None.
Timings
M Cycles: 2, T States: 7 (4, 3)
LD r, (HL)
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|
0 | 1 | ← r → | 1 | 1 | 0 |
The 8-bit contents of the memory location HL is loaded in to register r, in which r identifies any of the registers A, B, C, D, E, H or L, as follows:
A | B | C | D | E | H | L |
---|---|---|---|---|---|---|
111 | 000 | 001 | 010 | 011 | 100 | 101 |
Flags affected
None.
Timings
M Cycles: 2, T States: 7 (4, 3)
LD r, (IX+d)
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |
---|---|---|---|---|---|---|---|---|
1 | 1 | 0 | 1 | 1 | 1 | 0 | 1 | DD |
0 | 1 | ← r → | 1 | 1 | 0 | |||
← d → |
The (IX+d) operand (ie: the contents of Index Register IX summed with the two's complement displacement integer d) is loaded in to register r, in which r identifies any of the registers A, B, C, D, E, H or L, as follows:
A | B | C | D | E | H | L |
---|---|---|---|---|---|---|
111 | 000 | 001 | 010 | 011 | 100 | 101 |
Flags affected
None.
Timings
M Cycles: 5, T States: 19 (4, 4, 3, 5, 3)
LD r, (IY+d)
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |
---|---|---|---|---|---|---|---|---|
1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | FD |
0 | 1 | ← r → | 1 | 1 | 0 | |||
← d → |
The (IY+d) operand (ie: the contents of Index Register IY summed with the two's complement displacement integer d) is loaded in to register r, in which r identifies any of the registers A, B, C, D, E, H or L, as follows:
A | B | C | D | E | H | L |
---|---|---|---|---|---|---|
111 | 000 | 001 | 010 | 011 | 100 | 101 |
Flags affected
None.
Timings
M Cycles: 5, T States: 19 (4, 4, 3, 5, 3)
LD (HL), r
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|
0 | 1 | 1 | 1 | 0 | ← r → |
The contents of the register r is loaded in to the memory location HL, in which r identifies any of the registers A, B, C, D, E, H or L, as follows:
A | B | C | D | E | H | L |
---|---|---|---|---|---|---|
111 | 000 | 001 | 010 | 011 | 100 | 101 |
Flags affected
None.
Timings
M Cycles: 2, T States: 7 (4, 3)
LD (IX+d), r
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |
---|---|---|---|---|---|---|---|---|
1 | 1 | 0 | 1 | 1 | 1 | 0 | 1 | DD |
0 | 1 | 1 | 1 | 0 | ← r → | |||
← d → |
The contents of register r is loaded to the memory address specified by (IX+d) operand (ie: the contents of Index Register IX summed with the two's complement displacement integer d), in which r identifies any of the registers A, B, C, D, E, H or L, as follows:
A | B | C | D | E | H | L |
---|---|---|---|---|---|---|
111 | 000 | 001 | 010 | 011 | 100 | 101 |
Flags affected
None.
Timings
M Cycles: 5, T States: 19 (4, 4, 3, 5, 3)
LD (IY+d), r
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |
---|---|---|---|---|---|---|---|---|
1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | FD |
0 | 1 | 1 | 1 | 0 | ← r → | |||
← d → |
The contents of register r is loaded to the memory address specified by (IY+d) operand (ie: the contents of Index Register IY summed with the two's complement displacement integer d), in which r identifies any of the registers A, B, C, D, E, H or L, as follows:
A | B | C | D | E | H | L |
---|---|---|---|---|---|---|
111 | 000 | 001 | 010 | 011 | 100 | 101 |
Flags affected
None.
Timings
M Cycles: 5, T States: 19 (4, 4, 3, 5, 3)
16-bit Load and Stack Operations
![]() | This section needs expansion. You can help by adding to it. |
Exchange Operations
![]() | This section needs expansion. You can help by adding to it. |
Block Transfer Operations
![]() | This section needs expansion. You can help by adding to it. |
Block Search Operations
![]() | This section needs expansion. You can help by adding to it. |
8-bit Arithmetic Operations
![]() | This section needs expansion. You can help by adding to it. |
16-bit Arithmetic Operations
![]() | This section needs expansion. You can help by adding to it. |
Bit Manipulation Operations
![]() | This section needs expansion. You can help by adding to it. |
Branching and Routine Operations
![]() | This section needs expansion. You can help by adding to it. |
Input/Output Operations
![]() | This section needs expansion. You can help by adding to it. |