Skip to content

Appendices08

Appendix 8 — Z80 Instruction Reference

This appendix is a searchable support table for the classic Z80 instruction set.

It includes:

  • the standard documented instruction families
  • the classic undocumented forms most programmers still treat as part of the real Z80 machine model

It does not include:

  • host-, firmware-, or emulator-specific ED aliases
  • non-Z80 extensions from later or different CPUs
  • cycle counts

Status values used below:

  • documented is part of the standard documented Z80 set
  • documented prefix family is standard, but lives in CB, ED, DD, FD, DDCB, or FDCB
  • undocumented but classic sits outside the original documented set, yet is widely supported and commonly treated as standard practice

MnemonicSupported classic formsPrefix familiesStatusNotes
ADCadc a,r, adc a,n, adc a,(hl), adc a,(ix+d), adc a,(iy+d), adc hl,ssbase, DD, FD, EDdocumentedtwo separate families: 8-bit accumulator and 16-bit HL
ADDadd a,r, add a,n, add a,(hl), add a,(ix+d), add a,(iy+d), add hl,ss, add ix,pp, add iy,rrbase, DD, FDdocumented16-bit add always writes back to first pair
ANDand r, and n, and (hl), and (ix+d), and (iy+d)base, DD, FDdocumentedaccumulator-only logical op
BITbit b,r, bit b,(hl), bit b,(ix+d), bit b,(iy+d)CB, DDCB, FDCBdocumented prefix familybit test, no stored result
CALLcall nn, call cc,nnbasedocumentedabsolute subroutine call
CCFccfbasedocumentedcomplement carry
CPcp r, cp n, cp (hl), cp (ix+d), cp (iy+d)base, DD, FDdocumentedcompare against A, flags only
CPDcpdEDdocumented prefix familyblock compare, decrement
CPDRcpdrEDdocumented prefix familyrepeated CPD
CPIcpiEDdocumented prefix familyblock compare, increment
CPIRcpirEDdocumented prefix familyrepeated CPI
CPLcplbasedocumentedcomplement accumulator
DAAdaabasedocumentedBCD adjust after add/subtract
DECdec r, dec rr, dec (hl), dec (ix+d), dec (iy+d), dec ixh, dec ixl, dec iyh, dec iylbase, DD, FDdocumented plus undocumented-but-classic half-register formshalf-index-register forms are the undocumented part
DIdibasedocumenteddisable interrupts
DJNZdjnz dispbasedocumentedrelative counted branch using B
EIeibasedocumentedenable interrupts
EXex de,hl, ex af,af', ex (sp),hl, ex (sp),ix, ex (sp),iybase, DD, FDdocumentedswap, not copy
EXXexxbasedocumentedswaps BC/DE/HL with shadow set
HALThaltbasedocumentedstop until interrupt
IMim 0, im 1, im 2EDdocumented prefix familyinterrupt mode control
INin a,(n), in r,(c)base, EDdocumentedin f,(c) is not a meaningful portable form
INCinc r, inc rr, inc (hl), inc (ix+d), inc (iy+d), inc ixh, inc ixl, inc iyh, inc iylbase, DD, FDdocumented plus undocumented-but-classic half-register formshalf-index-register forms are the undocumented part
INDindEDdocumented prefix familyblock input, decrement
INDRindrEDdocumented prefix familyrepeated IND
INIiniEDdocumented prefix familyblock input, increment
INIRinirEDdocumented prefix familyrepeated INI
JPjp nn, jp cc,nn, jp (hl), jp (ix), jp (iy)base, DD, FDdocumentedabsolute branch or indirect jump
JRjr disp, jr nz,disp, jr z,disp, jr nc,disp, jr c,dispbasedocumentedshort relative branch only
LDregister/register, register/immediate, (hl) forms, (ix+d) / (iy+d) forms, a with (bc) / (de), absolute memory forms, sp <- hl/ix/iy, i/r transfers, block forms below, classic half-register forms with ixh/ixl/iyh/iylbase, DD, FD, EDdocumented plus undocumented-but-classic half-register formsthe biggest family and the one with the most exceptions
LDDlddEDdocumented prefix familyblock transfer, decrement
LDDRlddrEDdocumented prefix familyrepeated LDD
LDIldiEDdocumented prefix familyblock transfer, increment
LDIRldirEDdocumented prefix familyrepeated LDI
NEGnegEDdocumented prefix familyhistorically duplicated across several ED opcodes
NOPnopbasedocumentedno operation
ORor r, or n, or (hl), or (ix+d), or (iy+d)base, DD, FDdocumentedaccumulator-only logical op
OTDRotdrEDdocumented prefix familyrepeated block output, decrement
OTIRotirEDdocumented prefix familyrepeated block output, increment
OUTout (n),a, out (c),rbase, EDdocumentedout (c),0 is not treated here as standard classic course material
OUTDoutdEDdocumented prefix familyblock output, decrement
OUTIoutiEDdocumented prefix familyblock output, increment
POPpop bc, pop de, pop hl, pop af, pop ix, pop iybase, DD, FDdocumentedword-sized only
PUSHpush bc, push de, push hl, push af, push ix, push iybase, DD, FDdocumentedword-sized only
RESres b,r, res b,(hl), res b,(ix+d), res b,(iy+d), indexed result-copy formsCB, DDCB, FDCBdocumented prefix family plus undocumented-but-classic indexed result-copy formsclassic CPUs commonly copy indexed result into target register
RETret, ret ccbasedocumentedreturn from subroutine
RETIretiEDdocumented prefix familyinterrupt return
RETNretnEDdocumented prefix familyinterrupt/non-maskable return
RLrl r, rl (hl), rl (ix+d), rl (iy+d), indexed result-copy formsCB, DDCB, FDCBdocumented prefix family plus undocumented-but-classic indexed result-copy forms9-bit left rotation through carry: bit 7 → new C, old C → bit 0; updates S, Z, P/V, C
RLArlabasedocumentedsame 9-bit left rotation as RL, accumulator only; only C updated — S, Z, P/V unchanged
RLCrlc r, rlc (hl), rlc (ix+d), rlc (iy+d), indexed result-copy formsCB, DDCB, FDCBdocumented prefix family plus undocumented-but-classic indexed result-copy formscircular left: bit 7 wraps to bit 0 and copies to C; updates S, Z, P/V, C
RLCArlcabasedocumentedsame circular left rotation as RLC, accumulator only; only C updated — S, Z, P/V unchanged
RLDrldEDdocumented prefix familynibble rotate between A and (HL)
RRrr r, rr (hl), rr (ix+d), rr (iy+d), indexed result-copy formsCB, DDCB, FDCBdocumented prefix family plus undocumented-but-classic indexed result-copy forms9-bit right rotation through carry: bit 0 → new C, old C → bit 7; updates S, Z, P/V, C
RRArrabasedocumentedsame 9-bit right rotation as RR, accumulator only; only C updated — S, Z, P/V unchanged
RRCrrc r, rrc (hl), rrc (ix+d), rrc (iy+d), indexed result-copy formsCB, DDCB, FDCBdocumented prefix family plus undocumented-but-classic indexed result-copy formscircular right: bit 0 wraps to bit 7 and copies to C; updates S, Z, P/V, C
RRCArrcabasedocumentedsame circular right rotation as RRC, accumulator only; only C updated — S, Z, P/V unchanged
RRDrrdEDdocumented prefix familynibble rotate between A and (HL)
RSTrst $00/$08/$10/$18/$20/$28/$30/$38basedocumentedfixed low-memory call vectors
SBCsbc a,r, sbc a,n, sbc a,(hl), sbc a,(ix+d), sbc a,(iy+d), sbc hl,ssbase, DD, FD, EDdocumentedtwo separate families: 8-bit accumulator and 16-bit HL
SCFscfbasedocumentedset carry
SETset b,r, set b,(hl), set b,(ix+d), set b,(iy+d), indexed result-copy formsCB, DDCB, FDCBdocumented prefix family plus undocumented-but-classic indexed result-copy formssets bit and writes back
SLAsla r, sla (hl), sla (ix+d), sla (iy+d), indexed result-copy formsCB, DDCB, FDCBdocumented prefix family plus undocumented-but-classic indexed result-copy formsshift left: bit 7 → C, 0 fills bit 0; effectively multiply by 2; updates S, Z, P/V, C
SLL / SLSsll r, sll (hl), sll (ix+d), sll (iy+d), indexed result-copy formsCB, DDCB, FDCBundocumented but classicshift left with 1 filling bit 0 (result always odd); bit 7 → C; two common names for the same opcode
SRAsra r, sra (hl), sra (ix+d), sra (iy+d), indexed result-copy formsCB, DDCB, FDCBdocumented prefix family plus undocumented-but-classic indexed result-copy formsarithmetic right shift: bit 0 → C, bit 7 preserved (sign extension); correct for signed divide by 2; updates S, Z, P/V, C
SRLsrl r, srl (hl), srl (ix+d), srl (iy+d), indexed result-copy formsCB, DDCB, FDCBdocumented prefix family plus undocumented-but-classic indexed result-copy formslogical right shift: bit 0 → C, 0 fills bit 7; correct for unsigned divide by 2; updates S, Z, P/V, C
SUBsub r, sub n, sub (hl), sub (ix+d), sub (iy+d)base, DD, FDdocumentedaccumulator-only subtract
XORxor r, xor n, xor (hl), xor (ix+d), xor (iy+d)base, DD, FDdocumentedaccumulator-only logical op

Notes On The Undocumented Forms Included Here

  • IXH, IXL, IYH, IYL in many 8-bit LD, INC, DEC, and ALU forms
  • SLL / SLS
  • DDCB / FDCB indexed rotate/shift/bit-result-copy forms such as rlc (ix+3),b

Rotate and Shift Instructions in Detail


Circular rotates: RLC / RLCA and RRC / RRCA

The byte rotates as a closed ring. The bit that falls off one end wraps to the other end, and a copy of it lands in the carry flag.

RLC / RLCA  (circular rotate left)
  before:  [b7 b6 b5 b4 b3 b2 b1 b0]   C = ?
  after:   [b6 b5 b4 b3 b2 b1 b0 b7]   C = b7
  (bit 7 wraps to bit 0; C receives a copy of b7)

RRC / RRCA  (circular rotate right)
  before:  [b7 b6 b5 b4 b3 b2 b1 b0]   C = ?
  after:   [b0 b7 b6 b5 b4 b3 b2 b1]   C = b0
  (bit 0 wraps to bit 7; C receives a copy of b0)

Through-carry rotates: RL / RLA and RR / RRA

The carry flag acts as a ninth bit. The displaced bit exits through carry; the old carry enters on the other side.

RL / RLA  (rotate left through carry)
  before:  [b7 b6 b5 b4 b3 b2 b1 b0]   C = c
  after:   [b6 b5 b4 b3 b2 b1 b0  c]   C = b7
  (old C enters bit 0; bit 7 exits to new C)

RR / RRA  (rotate right through carry)
  before:  [b7 b6 b5 b4 b3 b2 b1 b0]   C = c
  after:   [ c b7 b6 b5 b4 b3 b2 b1]   C = b0
  (old C enters bit 7; bit 0 exits to new C)

A left rotation through carry followed by a right rotation through carry recovers the original byte and carry. This makes RL/RR suitable for shifting multi-byte values because carry transfers the overflow bit between adjacent bytes.


Shifts: SLA, SRA, SRL, SLL/SLS

A shift discards the bit that falls off one end, after copying it to carry, and fills the vacated position with a fixed value. Rotates are the ones that wrap.

SLA  (shift left arithmetic)
  before:  [b7 b6 b5 b4 b3 b2 b1 b0]   C = ?
  after:   [b6 b5 b4 b3 b2 b1 b0  0]   C = b7
  (0 fills bit 0; bit 7 exits to C; equivalent to multiply by 2)

SLL / SLS  (shift left logical, undocumented)
  before:  [b7 b6 b5 b4 b3 b2 b1 b0]   C = ?
  after:   [b6 b5 b4 b3 b2 b1 b0  1]   C = b7
  (1 fills bit 0; bit 7 exits to C; result always has bit 0 set)

SRA  (shift right arithmetic)
  before:  [b7 b6 b5 b4 b3 b2 b1 b0]   C = ?
  after:   [b7 b7 b6 b5 b4 b3 b2 b1]   C = b0
  (bit 7 preserved, copied into itself; bit 0 exits to C; signed divide by 2)

SRL  (shift right logical)
  before:  [b7 b6 b5 b4 b3 b2 b1 b0]   C = ?
  after:   [ 0 b7 b6 b5 b4 b3 b2 b1]   C = b0
  (0 fills bit 7; bit 0 exits to C; unsigned divide by 2)

SRA and SRL differ in exactly one way: SRA copies bit 7 into itself, preserving the sign. SRL clears bit 7. For signed values, SRA divides by 2 correctly, so −4 (= $FC) shifted right arithmetically gives −2 (= $FE). SRL would give 126 (= $7E), which is wrong for a signed interpretation.


Accumulator forms vs CB-prefix forms

FormExampleFlags updated
Accumulator-onlyRLCA, RRCA, RLA, RRAC only
CB-prefix (any register)RLC r, RRC r, RL r, RR rS, Z, P/V, C

RLCA, RRCA, RLA, and RRA are single-byte base instructions, fast and compact.

RLC r, RRC r, RL r, and RR r are CB-prefix forms. A zero test after a rotation, such as detecting when all bits have shifted out, requires the CB-prefix form rather than the accumulator shorthand.


Quick reference: what enters and exits each operation

InstructionBit enteringFromBit exitingTo
RLC / RLCAb7wraps from bit 7b7 copyC
RL / RLAold Centers bit 0b7new C
RRC / RRCAb0wraps from bit 0b0 copyC
RR / RRAold Centers bit 7b0new C
SLA0fills bit 0b7C
SLL / SLS1fills bit 0b7C
SRAb7preserved in placeb0C
SRL0fills bit 7b0C