Skip to content

Atom Appendices09

Appendix 9 — Addressing, Prefixes and Forms


Form notation

The tables use R for an encodable 8-bit register, RR or another doubled letter for the register-pair set accepted by that instruction, N for an 8-bit value, NN for a 16-bit value, D for an index displacement and CC for a condition code. Each instruction family determines the exact register set.

Addressing Shapes

ShapeExampleMeaningTypical use
immediate byteLD A, $2Aconstant encoded in the instructionconstants, masks, small values
immediate wordLD HL, $800016-bit constant encoded in the instructionaddresses, counters, setup
registerLD D, Acopy between registerscheap data movement
register pairADD HL, DEoperate on a 16-bit pairaddresses, word arithmetic
register indirectLD A, (HL)memory at address in HLpointer-based table walk
indexed indirectLD A, (IX+3)memory at IX + displacementrecords, stack frames
absolute memoryLD A, ($8000)memory at a fixed 16-bit addressglobals, I/O-mapped data
relative branchJR NZ, LOOPbranch by signed offsetshort local branches
absolute branchJP NZ, TARGETbranch to full 16-bit addresslong-range control flow

Prefix Families

PrefixFamilyWhat it usually means
nonebaseordinary documented Z80 instruction set
CBrotate/shift/bit familyRLC, BIT, RES, SET and related forms
EDextended familyblock ops, NEG, RETI/RETN, IM, RLD/RRD, 16-bit ADC/SBC, port forms
DDIX substitutionmany HL-based forms become IX-based
FDIY substitutionmany HL-based forms become IY-based
DD CB Dindexed bit/shift familyoperate on (IX+D)
FD CB Dindexed bit/shift familyoperate on (IY+D)

DD and FD substitute IX or IY only in the encodable forms shown below.


LD Quick Table

FamilyExamplesNotes
8-bit register to registerLD A, B, LD D, Hcommon and fast
immediate to registerLD A, $2A, LD HL, $8000constants encoded in instruction
register with (HL)LD A, (HL), LD (HL), A, LD (HL), 0main indirect byte access
register with (IX+d) / (IY+d)LD A, (IX+3), LD (IY-1), Aindexed access
A with (BC) / (DE)LD A, (BC), LD (DE), Aonly A is allowed
absolute memoryLD A, ($8000), LD ($8000), A, LD HL, ($8000)globals and fixed addresses
stack pointer loadLD SP, HL, LD SP, IX, LD SP, IYspecial-case form

Illegal pattern to remember:

asm
LD ($8001), ($8000)   ; IMPOSSIBLE

Memory-to-memory moves must go through a register.


Arithmetic, Logic and Compare Quick Table

FamilyMain formsResult goes toNotes
ADDADD A,X, ADD HL,SS, ADD IX,PP, ADD IY,RRfirst operand8-bit add is accumulator-based
ADCADC A,X, ADC HL,SSfirst operandincludes carry
SUBSUB XAaccumulator only
SBCSBC A,X, SBC HL,SSfirst operandsubtract with carry/borrow
ANDAND XAaccumulator only
OROR XAaccumulator only
XORXOR XAaccumulator only
CPCP Xno stored resultflags only
INCINC R, INC RR, INC (HL), INC (IX+D)operand itselfchanges the operand in place
DECDEC R, DEC RR, DEC (HL), DEC (IX+D)operand itselfoften used for loops

Rotate, Shift, and Bit Quick Table

FamilyExamplesNotes
accumulator rotatesRLCA, RRCA, RLA, RRAshort one-byte accumulator forms
general rotatesRLC R, RRC R, RL R, RR Rbase CB family
shiftsSLA R, SRA R, SRL Rbase CB family
bit testBIT N,R, BIT N,(HL)tests a bit and leaves the operand as it stands
bit clearRES N,R, RES N,(HL)writes back changed value
bit setSET N,R, SET N,(HL)writes back changed value
indexed formsBIT 3,(IX+2), SRL (IY-1)DD CB D / FD CB D families
classic-undocumented shiftSLL R / SLS Rwidely used but not part of the original documented set

Control Flow, Stack and Exchange Quick Table

FamilyExamplesNotes
absolute jumpJP TARGET, JP NZ,TARGET, JP (HL)long-range branch
relative jumpJR TARGET, JR Z,TARGETshort branch only
counted branchDJNZ LOOPB := B - 1, branch if result not zero
call/returnCALL FN, RET, RET Zuses hardware stack
restartRST $38call to fixed low-memory vector
stackPUSH BC, POP HLword-sized only
exchangeEX DE,HL, EX AF,AF', EXX, EX (SP),HLswaps rather than copies
interrupt stateDI, EI, IM 0/1/2machine control, not everyday data movement

Block Instructions At A Glance

FamilyMnemonicsWhat they do
block transferLDI, LDIR, LDD, LDDRcopy bytes between (HL) and (DE) while updating pointers/counter
block compareCPI, CPIR, CPD, CPDRcompare A against bytes in memory while updating pointers/counter
block inputINI, INIR, IND, INDRport input plus memory store
block outputOUTI, OTIR, OUTD, OTDRmemory read plus port output