Until now, we’ve worked with 8-bit registers, which can hold values from 0 to 255. But what if you need to work with larger numbers, like screen coordinates or memory addresses?
This lesson introduces register pairs, explains direct memory access, and walks through how to draw lines using the Tatung Einstein’s built-in graphics routines.
The Z80 allows you to treat certain pairs of 8-bit registers as one 16-bit register:
B and C → BCD and E → DEH and L → HLThese pairs can hold values from 0 to 65535.
ORG 256
LD DE,12345 ; Load DE with a 16-bit number
LD HL,DE ; Copy that value from DE to HL
RET
This uses immediate mode addressing — you give the value directly in the instruction.
Single 8-bit registers are limited to 255. Register pairs let you:
So far, you’ve stored everything in registers. That works for small programs — but real-world software needs more storage.
To store or retrieve data in memory, you can use direct mode addressing.
LD (1024),BC
This copies the value in BC into memory starting at address 1024.
LD DE,(1024)
This copies a 16-bit value from memory into register pair DE.
Remember to wrap the memory address in parentheses — LD DE,1024 is not valid, but LD DE,(1024) is.
Z80 doesn’t allow:
LD (2000),42 ; INVALID
Instead, use two steps:
LD A,42 ; Load value into A
LD (2000),A ; Store A at address 2000
The Tatung Einstein includes built-in MCAL routines in ROM for graphics, like drawing lines. To use these functions we need to use direct mode addressing.
To draw a line, we call MCAL 200.
64424 – Line Type (set to 255 for solid)
64425 – Segment spacing (set to 0)
64426 – Second segment end (set to 0)
64427 – Third segment end (set to 0)
Set these values before calling the line routine, or your program may crash.
IX = start X coordinateIY = start Y coordinate64406 = end X coordinate64408 = end Y coordinate x Why mix registers and memory? Because:IX and IY are special and rarely used elsewhere ORG 256
LD A,255
LD (64424),A ; Set solid line
LD A,0
LD (64425),A
LD (64426),A
LD (64427),A
LD IX,0 ; Start X = 0
LD IY,0 ; Start Y = 0
LD A,200
LD (64406),A ; End X = 200
LD (64408),A ; End Y = 200
RST 8
DEFB 200 ; MCAL call to draw the line
RET
This draws a solid line from (0, 0) to (200, 200).
For further information see 'Appendix II - Registers'
(0, 0) to (100, 200)