Instruction set

A complete reference for the Z80 and Z80N (ZX Spectrum Next) instruction set as supported by FantASM, with encodings and T-state timings. See the notation key at the end for the symbols used in the Encoding column.

Standard instructions

MnemonicEncodingT-StatesDescription
ADC A, r10001fff4Add with carry register r to Acc.
ADC A, nCE nn7Add with carry immediate n to Acc.
ADC A, (HL)8E7Add with carry (HL) to Acc.
ADC A, (IX+d)DD 8E dd19Add with carry (IX+d) to Acc.
ADC A, (IY+d)FD 8E dd19Add with carry (IY+d) to Acc.
ADC HL, rrED 01ss101015Add with carry register pair rr to HL.
ADD A, r10000fff4Add register r to Acc.
ADD A, nC6 nn7Add immediate n to Acc.
ADD A, (HL)867Add (HL) to Acc.
ADD A, (IX+d)DD 86 dd19Add (IX+d) to Acc.
ADD A, (IY+d)FD 86 dd19Add (IY+d) to Acc.
ADD HL, rr00ss100111Add register pair rr to HL.
ADD IX, rrDD 00ss100115Add register pair rr to IX.
ADD IY, rrFD 00ss100115Add register pair rr to IY.
AND r10100fff4Logical AND register r with Acc.
AND nE6 nn7Logical AND immediate n with Acc.
AND (HL)A67Logical AND (HL) with Acc.
AND (IX+d)DD A6 dd19Logical AND (IX+d) with Acc.
AND (IY+d)FD A6 dd19Logical AND (IY+d) with Acc.
BIT b, rCB 01bbbfff8Test bit b of register r.
BIT b, (HL)CB 01bbb11012Test bit b of (HL).
BIT b, (IX+d)DD CB dd 01bbb11020Test bit b of (IX+d).
BIT b, (IY+d)FD CB dd 01bbb11020Test bit b of (IY+d).
CALL nnCD nn nn17Unconditional call to nn.
CALL cc, nn11ccc100 nn nn10/17Conditional call to nn.
CCF3F4Complement Carry Flag.
CP r10111fff4Compare register r with Acc.
CP nFE nn7Compare immediate n with Acc.
CP (HL)BE7Compare (HL) with Acc.
CP (IX+d)DD BE dd19Compare (IX+d) with Acc.
CP (IY+d)FD BE dd19Compare (IY+d) with Acc.
CPDED A916Compare Acc with (HL), decrement HL and BC.
CPDRED B916/21CPD repeated until BC=0 or match.
CPIED A116Compare Acc with (HL), increment HL, decrement BC.
CPIRED B116/21CPI repeated until BC=0 or match.
CPL2F4Complement Acc (1’s complement).
DAA274Decimal Adjust Acc.
DEC r00fff1014Decrement register r.
DEC rr00ss10116Decrement register pair rr.
DEC (HL)3511Decrement (HL).
DEC (IX+d)DD 35 dd23Decrement (IX+d).
DEC (IY+d)FD 35 dd23Decrement (IY+d).
DIF34Disable Interrupts.
DJNZ d10 dd8/13Decrement B, jump if not zero.
EIFB4Enable Interrupts.
EX (SP), HLE319Exchange (SP) with HL.
EX (SP), IXDD E323Exchange (SP) with IX.
EX (SP), IYFD E323Exchange (SP) with IY.
EX AF, AF’084Exchange AF with alternate AF’.
EX DE, HLEB4Exchange DE with HL.
EXXD94Exchange BC, DE, HL with alternates.
HALT764Halt CPU.
IM 0ED 468Set interrupt mode 0.
IM 1ED 568Set interrupt mode 1.
IM 2ED 5E8Set interrupt mode 2.
IN A, (C)ED 7812Input from port C to Acc.
IN A, (n)DB nn11Input from port n to Acc.
IN r, (C)ED 01fff00012Input from port C to register r.
INC r00fff1004Increment register r.
INC rr00ss00116Increment register pair rr.
INC (HL)3411Increment (HL).
INC (IX+d)DD 34 dd23Increment (IX+d).
INC (IY+d)FD 34 dd23Increment (IY+d).
INDED AA16Input from port C to (HL), decrement HL and B.
INDRED BA16/21IND repeated until B=0.
INIED A216Input from port C to (HL), increment HL, decrement B.
INIRED B216/21INI repeated until B=0.
JP nnC3 nn nn10Unconditional jump to nn.
JP cc, nn11ccc010 nn nn10Conditional jump to nn.
JP (HL)E94Jump to address in HL.
JP (IX)DD E98Jump to address in IX.
JP (IY)FD E98Jump to address in IY.
JR d18 dd12Unconditional relative jump.
JR cc, d001cc000 dd7/12Conditional relative jump.
LD r, r’01fffggg4Load register r with r'.
LD r, n00fff110 nn7Load register r with immediate n.
LD r, (HL)01fff1107Load register r with (HL).
LD r, (IX+d)DD 01fff110 dd19Load register r with (IX+d).
LD r, (IY+d)FD 01fff110 dd19Load register r with (IY+d).
LD (HL), r01110fff7Load (HL) with register r.
LD (HL), n36 nn10Load (HL) with immediate n.
LD (IX+d), rDD 01110fff dd19Load (IX+d) with register r.
LD (IY+d), rFD 01110fff dd19Load (IY+d) with register r.
LD (IX+d), nDD 36 dd nn19Load (IX+d) with immediate n.
LD (IY+d), nFD 36 dd nn19Load (IY+d) with immediate n.
LD A, (BC)0A7Load Acc with (BC).
LD A, (DE)1A7Load Acc with (DE).
LD A, (nn)3A nn nn13Load Acc with (nn).
LD (BC), A027Load (BC) with Acc.
LD (DE), A127Load (DE) with Acc.
LD (nn), A32 nn nn13Load (nn) with Acc.
LD A, IED 579Load Acc with I register.
LD A, RED 5F9Load Acc with R register.
LD I, AED 479Load I register with Acc.
LD R, AED 4F9Load R register with Acc.
LD rr, nn00ss0001 nn nn10Load register pair rr with nn.
LD IX, nnDD 21 nn nn14Load IX with immediate nn.
LD IY, nnFD 21 nn nn14Load IY with immediate nn.
LD HL, (nn)2A nn nn16Load HL with (nn).
LD rr, (nn)ED 01ss1011 nn nn20Load register pair rr with (nn).
LD IX, (nn)DD 2A nn nn20Load IX with (nn).
LD IY, (nn)FD 2A nn nn20Load IY with (nn).
LD (nn), HL22 nn nn16Load (nn) with HL.
LD (nn), rrED 01ss0011 nn nn20Load (nn) with register pair rr.
LD (nn), IXDD 22 nn nn20Load (nn) with IX.
LD (nn), IYFD 22 nn nn20Load (nn) with IY.
LD SP, HLF96Load SP with HL.
LD SP, IXDD F910Load SP with IX.
LD SP, IYFD F910Load SP with IY.
LDDED A816Load (DE) with (HL), decrement HL, DE, BC.
LDDRED B816/21LDD repeated until BC=0.
LDIED A016Load (DE) with (HL), increment HL, DE, decrement BC.
LDIRED B016/21LDI repeated until BC=0.
NEGED 448Negate Acc (2’s complement).
NOP004No Operation.
OR r10110fff4Logical OR register r with Acc.
OR nF6 nn7Logical OR immediate n with Acc.
OR (HL)B67Logical OR (HL) with Acc.
OR (IX+d)DD B6 dd19Logical OR (IX+d) with Acc.
OR (IY+d)FD B6 dd19Logical OR (IY+d) with Acc.
OTDRED BB16/21OUTD repeated until B=0.
OTIRED B316/21OUTI repeated until B=0.
OUT (n), AD3 nn11Output Acc to port n.
OUT (C), rED 01fff00112Output register r to port C.
OUT (C)ED 7112Output 0 to port C (Undocumented).
OUTDED AB16Output (HL) to port C, decrement HL and B.
OUTIED A316Output (HL) to port C, increment HL, decrement B.
POP rr11ss000110Pop register pair rr from stack.
POP IXDD E114Pop IX from stack.
POP IYFD E114Pop IY from stack.
PUSH rr11ss010111Push register pair rr onto stack.
PUSH IXDD E515Push IX onto stack.
PUSH IYFD E515Push IY onto stack.
RES b, rCB 10bbbfff8Reset bit b of register r.
RES b, (HL)CB 10bbb11015Reset bit b of (HL).
RES b, (IX+d)DD CB dd 10bbb11023Reset bit b of (IX+d).
RES b, (IY+d)FD CB dd 10bbb11023Reset bit b of (IY+d).
RETC910Unconditional return.
RET cc11ccc0005/11Conditional return.
RETIED 4D14Return from interrupt.
RETNED 4514Return from non-maskable interrupt.
RL rCB 00010fff8Rotate register r left through carry.
RL (HL)CB 1615Rotate (HL) left through carry.
RL (IX+d)DD CB dd 1623Rotate (IX+d) left through carry.
RL (IY+d)FD CB dd 1623Rotate (IY+d) left through carry.
RLA174Rotate Acc left through carry.
RLC rCB 00000fff8Rotate register r left circular.
RLC (HL)CB 0615Rotate (HL) left circular.
RLC (IX+d)DD CB dd 0623Rotate (IX+d) left circular.
RLC (IY+d)FD CB dd 0623Rotate (IY+d) left circular.
RLCA074Rotate Acc left circular.
RLDED 6F18Rotate BCD digit left and through Acc.
RR rCB 00011fff8Rotate register r right through carry.
RR (HL)CB 1E15Rotate (HL) right through carry.
RR (IX+d)DD CB dd 1E23Rotate (IX+d) right through carry.
RR (IY+d)FD CB dd 1E23Rotate (IY+d) right through carry.
RRA1F4Rotate Acc right through carry.
RRC rCB 00001fff8Rotate register r right circular.
RRC (HL)CB 0E15Rotate (HL) right circular.
RRC (IX+d)DD CB dd 0E23Rotate (IX+d) right circular.
RRC (IY+d)FD CB dd 0E23Rotate (IY+d) right circular.
RRCA0F4Rotate Acc right circular.
RRDED 6718Rotate BCD digit right and through Acc.
RST p11ppp11111Restart at fixed address p.
SBC A, r10011fff4Subtract with carry register r from Acc.
SBC A, nDE nn7Subtract with carry immediate n from Acc.
SBC A, (HL)9E7Subtract with carry (HL) from Acc.
SBC A, (IX+d)DD 9E dd19Subtract with carry (IX+d) from Acc.
SBC A, (IY+d)FD 9E dd19Subtract with carry (IY+d) from Acc.
SBC HL, rrED 01ss001015Subtract with carry register pair rr from HL.
SCF374Set Carry Flag.
SET b, rCB 11bbbfff8Set bit b of register r.
SET b, (HL)CB 11bbb11015Set bit b of (HL).
SET b, (IX+d)DD CB dd 11bbb11023Set bit b of (IX+d).
SET b, (IY+d)FD CB dd 11bbb11023Set bit b of (IY+d).
SLA rCB 00100fff8Shift register r left arithmetic.
SLA (HL)CB 2615Shift (HL) left arithmetic.
SLA (IX+d)DD CB dd 2623Shift (IX+d) left arithmetic.
SLA (IY+d)FD CB dd 2623Shift (IY+d) left arithmetic.
SRA rCB 00101fff8Shift register r right arithmetic.
SRA (HL)CB 2E15Shift (HL) right arithmetic.
SRA (IX+d)DD CB dd 2E23Shift (IX+d) right arithmetic.
SRA (IY+d)FD CB dd 2E23Shift (IY+d) right arithmetic.
SRL rCB 00111fff8Shift register r right logical.
SRL (HL)CB 3E15Shift (HL) right logical.
SRL (IX+d)DD CB dd 3E23Shift (IX+d) right logical.
SRL (IY+d)FD CB dd 3E23Shift (IY+d) right logical.
SUB r10010fff4Subtract register r from Acc.
SUB nD6 nn7Subtract immediate n from Acc.
SUB (HL)967Subtract (HL) from Acc.
SUB (IX+d)DD 96 dd19Subtract (IX+d) from Acc.
SUB (IY+d)FD 96 dd19Subtract (IY+d) from Acc.
XOR AAF4Logical XOR Acc with Acc (zero Acc, clear Carry).
XOR r10101fff4Logical XOR register r with Acc.
XOR nEE nn7Logical XOR immediate n with Acc.
XOR (HL)AE7Logical XOR (HL) with Acc.
XOR (IX+d)DD AE dd19Logical XOR (IX+d) with Acc.
XOR (IY+d)FD AE dd19Logical XOR (IY+d) with Acc.

Undocumented instructions

The index-half registers (IXH, IXL, IYH, IYL) and a handful of other opcodes are undocumented but widely supported.

MnemonicEncodingT-StatesDescription
XOR IXH/IXLDD AC/AD8XOR high/low byte of IX with Acc.
XOR IYH/IYLFD AC/AD8XOR high/low byte of IY with Acc.
OR IXH/IXLDD B4/B58OR high/low byte of IX with Acc.
OR IYH/IYLFD B4/B58OR high/low byte of IY with Acc.
AND IXH/IXLDD A4/A58AND high/low byte of IX with Acc.
AND IYH/IYLFD A4/A58AND high/low byte of IY with Acc.
CP IXH/IXLDD BC/BD8Compare high/low byte of IX with Acc.
CP IYH/IYLFD BC/BD8Compare high/low byte of IY with Acc.
ADD A, IXH/IXLDD 84/858Add high/low byte of IX to Acc.
ADD A, IYH/IYLFD 84/858Add high/low byte of IY to Acc.
ADC A, IXH/IXLDD 8C/8D8Add with carry high/low byte of IX to Acc.
ADC A, IYH/IYLFD 8C/8D8Add with carry high/low byte of IY to Acc.
SUB IXH/IXLDD 94/958Subtract high/low byte of IX from Acc.
SUB IYH/IYLFD 94/958Subtract high/low byte of IY from Acc.
SBC A, IXH/IXLDD 9C/9D8Subtract with carry high/low byte of IX from Acc.
SBC A, IYH/IYLFD 9C/9D8Subtract with carry high/low byte of IY from Acc.
SLL rCB 00110fff8Shift Left Logical register r.
SLL (HL)CB 3615Shift Left Logical (HL).
SLL (IX+d)DD CB dd 3623Shift Left Logical (IX+d).
SLL (IY+d)FD CB dd 3623Shift Left Logical (IY+d).
INC IXH/IXLDD 24/2C8Increment high/low byte of IX.
DEC IXH/IXLDD 25/2D8Decrement high/low byte of IX.
INC IYH/IYLFD 24/2C8Increment high/low byte of IY.
DEC IYH/IYLFD 25/2D8Decrement high/low byte of IY.
LD IXH/IXL, nDD 26/2E nn11Load high/low byte of IX with immediate n.
LD IYH/IYL, nFD 26/2E nn11Load high/low byte of IY with immediate n.
LD r, IXH/IXLDD 01fffggg8Load register r with IX high/low byte.
LD r, IYH/IYLFD 01fffggg8Load register r with IY high/low byte.
OUT (C), 0ED 7112Output 0 to port C.
IN (C)ED 7012Input from port C, set flags, value discarded.

Z80N instructions (ZX Spectrum Next)

Requires Z80N to be enabled (!target zxnext or !opt z80n on). Flag notation: * affected, - unaffected, 0 reset, 1 set, ? undefined; order S Z H P/V N C.

MnemonicEncodingT-StatesFlagsDescription
ADD BC, AED 338- - - - - -Add Acc to BC.
ADD DE, AED 328- - - - - -Add Acc to DE.
ADD HL, AED 318- - - - - -Add Acc to HL.
ADD BC, nnED 36 lo hi16- - - - - -Add immediate 16-bit nn to BC.
ADD DE, nnED 35 lo hi16- - - - - -Add immediate 16-bit nn to DE.
ADD HL, nnED 34 lo hi16- - - - - -Add immediate 16-bit nn to HL.
BRLC DE, BED 2C8- - - - - -Barrel roll DE left circular by B bits.
BSLA DE, BED 288- - - - - -Barrel shift DE left arithmetic by B bits.
BSRF DE, BED 2B8- - - - - -Barrel shift DE right filling 1s by B bits.
BSRA DE, BED 298- - - - - -Barrel shift DE right arithmetic (signed) by B bits.
BSRL DE, BED 2A8- - - - - -Barrel shift DE right logical by B bits.
LDDXED AC16- - - - - -Extended LDD: if (HL) != A then (DE) := (HL); DE++, HL–, BC–.
LDDRXED BC21/16- - - - - -LDDX repeated until BC=0.
LDIXED A416- - - - - -Extended LDI: if (HL) != A then (DE) := (HL); DE++, HL++, BC–.
LDIRXED B421/16- - - - - -LDIX repeated until BC=0.
LDPIRXED B721/16- - - - - -Pattern fill from (HL & $FFF8 + E & 7); if != A then (DE) := t; DE++, BC–; until BC=0.
LDWSED A514- 0 * S S SLayer 2 byte copy: (DE) := (HL); INC L; INC D.
MIRROR AED 248- - - - - -Reverse the bits in Acc.
MUL D, EED 308- - - - - -Unsigned 8×8 multiply of D and E; 16-bit result in DE.
NEXTREG n, n’ED 91 nn nn20- - - - - -Set Next hardware register n to n'.
NEXTREG n, AED 92 nn17- - - - - -Set Next hardware register n to Acc.
OUTINBED 9016? ? ? ? ? ?OUT (BC), (HL); HL++. B is not decremented.
PIXELADED 948- - - - - -Set HL to the ULA pixel address from D (Y) and E (X).
PIXELDNED 938- - - - - -Advance HL to the pixel address one line below.
PUSH nnED 8A hi lo23- - - - - -Push 16-bit immediate nn (big-endian in stream, little-endian on stack).
SETAEED 958- - - - - -Set A to the pixel bit mask $80 >> (E & 7).
SWAPNIBED 238- - - - - -Swap the nibbles in Acc.
TEST nED 27 nn11S ? H P 0 0AND Acc with n, flags only; A unchanged.

CSpect pseudo-instructions

Requires CSpect support (-c or !opt cspect on).

MnemonicEncodingDescription
BREAKFD 00CSpect breakpoint.
EXITDD 00Exit the CSpect emulator.

Notation key

  • r — 8-bit register (A, B, C, D, E, H, L).
  • rr — 16-bit register pair (BC, DE, HL, SP, IX, IY, AF).
  • n / nn — 8-bit / 16-bit immediate value.
  • d — 8-bit signed displacement.
  • b — bit index (0–7).
  • cc — condition code (Z, NZ, C, NC, PE, PO, P, M).
  • p — restart address (00h, 08h, 10h, 18h, 20h, 28h, 30h, 38h).
  • (HL) / (nn) — memory at the address in HL / at immediate address nn.

Encoding fields: fff 3-bit register (B=000, C=001, D=010, E=011, H=100, L=101, (HL)=110, A=111); ggg second register in LD r, r'; ss register pair (BC=00, DE=01, HL=10, SP/AF=11); ccc condition code; bbb bit index; dd signed displacement or immediate byte. Standard Z80 constants are little-endian; Z80N big-endian cases are noted.