Skip to content

Atom Appendices08

Appendix 8 — Registers, Flags and Conditions


Main Registers

RegisterWidthUsual roleNotes
A8accumulatormain byte arithmetic/logic destination
F8flagsholds S Z H P/V N C; not a general data register
B8general purposeoften used as a loop counter
C8general purposealso used with port I/O
D8general purposeoften paired with E
E8general purposeoften paired with D
H8general purposehigh byte of HL
L8general purposelow byte of HL
BC16register paircounts, addresses, A-only indirect through (BC)
DE16register pairdata/address pair, A-only indirect through (DE)
HL16primary pointer pairmain indirect memory register
IX16index registerindexed access with displacement
IY16index registersecond indexed access register
SP16stack pointerpoints into the hardware stack
PC16program counteraddress of next instruction
I8interrupt vector high byteused in interrupt mode 2
R8refresh registernormally not useful in everyday code

Shadow Registers

Register setWhat it is
AF'shadow accumulator and flags
BC', DE', HL'shadow copies of the main 16-bit working pairs

You reach these through EX AF,AF' and EXX, not through ordinary LD forms.


Flags Register

BitNameMeaning when setCommon beginner use
7Sresult is negative in signed interpretationsigned comparisons
6Zresult is zeroJP Z, JR NZ, loop exits
5undocumented result bitcommonly copies result bit 5usually ignore
4Hhalf-carry from bit 3 to bit 4BCD support
3undocumented result bitcommonly copies result bit 3usually ignore
2P/Vparity or overflow, depends on instructionsigned overflow / parity / block ops
1Nlast arithmetic op was subtractionmostly internal / BCD support
0Ccarry out or borrowunsigned comparisons, rotates, shifts

Not every instruction updates every flag.


Condition Codes

ConditionMeaningFlag test
ZzeroZ = 1
NZnot zeroZ = 0
CcarryC = 1
NCno carryC = 0
MminusS = 1
PplusS = 0
PEparity even / overflowP/V = 1
POparity odd / no overflowP/V = 0

These appear in conditional JP, JR, CALL and RET forms. JR supports NZ, Z, NC and C.


Signed and Unsigned Landmarks

WidthUnsigned rangeSigned range (two's complement)
8-bit byte0 to 255-128 to 127
16-bit word0 to 65535-32768 to 32767

Useful byte landmarks:

ValueUnsignedSigned
$0000
$7F127127
$80128-128
$FF255-1

Relative Branch Range

Instruction familyRange
JR CC,TARGET-128 to +127 bytes from the next instruction
DJNZ TARGET-128 to +127 bytes from the next instruction

Targets outside that range require JP.