Assembly Language Fundamentals

Beginner
Version:
1.1

Register Pairs

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.

Register Pairs, Combining for 16-Bit Power

The Z80 allows you to treat certain pairs of 8-bit registers as one 16-bit register:

These pairs can hold values from 0 to 65535.

Example: Load and Copy 16-Bit Values

       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.

Why Use Register Pairs?

Single 8-bit registers are limited to 255. Register pairs let you:

Storing Data in Memory

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.

Store a Register Pair into Memory

LD (1024),BC

This copies the value in BC into memory starting at address 1024.

Load a Register Pair from Memory

LD DE,(1024)

This copies a 16-bit value from memory into register pair DE.

Remember to wrap the memory address in parenthesesLD DE,1024 is not valid, but LD DE,(1024) is.

Why You Must Load the Accumulator First

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

Drawing with Direct Memory and MCAL

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.

Line Drawing Setup

Required Scratchpad Memory Locations

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.

Coordinates for the Line

Example: Drawing a Line

       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'

Exercise 7.1 — Memory Order

  1. Write a program to draw a line from (0, 0) to (100, 200)
  2. Write a program to draw a square

Summary

Previous Module
Next Module