Assembly Language Registers Zilog Z80 registers


Registers: 8 bit: A, B, C, D, E, H, L, F, I, R, 16 bit: SP, PC, IX, IY, and shadows of some 8b registers: A', B', C', D', E', H', L' and F'.

Most of the 8 bit registers can be used also in pairs as 16 bit registers: AF, BC, DE and HL.

SP is stack pointer, marking the bottom of stack memory (used by PUSH/POP/CALL/RET instructions).
PC is program counter, pointing to the currently executed instruction.
I is Interrupt register, supplying high byte of vector table address for IM 2 interrupt mode.
R is refresh register, it increments each time the CPU fetches an opcode (or opcode prefix).
Some unofficial instructions exist on some Z80 processors to manipulate 8bit parts of IX as IXH:IXL and IY as IYH:IYL.

Shadow variants can't be directly accessed by any instruction, the EX AF,AF' instruction will swap between AF and AF', and EXX instruction will swap BC,DE,HL with BC',DE',HL'.

Loading value into a register:

    ; from other register
    LD   I,A        ; copies value in A into I (8 bit)
    LD   BC,HL      ; copies value in HL into BC (16 bit)
    ; directly with value encoded in instruction machine code
    LD   B,d8       ; 8b value d8 into B
    LD   DE,d16     ; 16b value d16 into DE
    ; from a memory (ROM/RAM)
    LD   A,(HL)     ; value from memory addressed by HL into A
    LD   A,(a16)    ; value from memory with address a16 into A
    LD   HL,(a16)   ; 16b value from memory with address a16 into HL
    POP  IX         ; 16b value popped from stack into IX
    LD   A,(IY+a8)  ; IX and IY allows addressing with 8b offset
    ; from I/O port (for writing value at I/O port use "OUT")
    IN   A,(C)      ; reads I/O port C, value goes to A

Correct combinations of possible source and destination operands are limited (for example LD H,(a16) does not exist).

Storing value into a memory:

    LD   (HL),D     ; value D stored into memory addressed by HL
    LD   (a16),A    ; value A into memory with address a16
    LD   (a16),HL   ; value HL into 16b of memory with address a16
    LD   (IX+a8),d8 ; value d8 into memory at address IX+a8
    LD   (IY+a8),B  ; value B into memory at address IY+a8
    ; specials ;)
    PUSH DE         ; 16b value DE pushed to stack
    CALL a16        ; while primarily used for execution branching
      ; it also stores next instruction address into stack