Your CPU’s Workspace: The Registers

Think of the Z80’s registers as a small, specialized crew of fast workers who hold all your data. They are faster than memory, so we want them to do most of the work.

The Main Workers (8-bit)

Register Analogy Key Function
A (Accumulator) The Calculator Where math always happens. If you add, subtract, or compare, it happens here.
B, C, D, E, H, L The General Storage Used to hold temporary numbers or counts.

The Main Address Book (16-bit)

Register Pair Analogy Key Function
HL The Memory Pointer Always holds a 16-bit address (a location in memory) so the CPU knows where to read or write data.

The Only Command You Need: LD (Load)

In Z80, data movement is done with the LD (Load) instruction. Think of this as the “Copy” command.

Syntax: LD destination, source

Example 1: Loading a Simple Number (Immediate Value)

    LD   A, 10      ; Load the decimal value 10 into the Accumulator (A)
    LD   HL, 5000H  ; Load the memory address 5000 (hex) into the HL pointer

Example 2: Loading Data from Memory

When you see parentheses (), it means “go to the address stored inside the register.”

    LD   A, (HL)    ; Load the number *at* the address in HL into A
    LD   (HL), B    ; Store the number in B *at* the address in HL

Creating “Hello World” (The Concept)

To display text, we need the CPU to: 1) Know where the text is, and 2) Call a built-in OS routine to do the work.

The Steps:

  1. Define your text in memory (a DB or Define Byte instruction).
  2. Point the HL register to the start of that text.
  3. Use the CALL instruction to jump to the OS’s print function address.