7

(avery) #1
FORGE

in our examples, but they are one of the features
that make the Z80 so powerful and popular.
In the hardware article, we saw the address and
data buses. Recall that they are the way the CPU
interacts with the rest of the system: the address
bus identifies where in memory (or which I/O port)
the CPU wants to read/write data from/to, and the
data bus moves the data between the system and
the CPU.
The buses show up inside the CPU as well.
Various registers have their contents routed to/from
one or the other buses in order to move data around,
as defined by our code.
The ALU (arithmetic logic unit) is where maths and
logic operations are performed.
The instruction register, decode, and control
blocks are where the instruction being executed is
stored, and processed. Each instruction causes a
specific sequence of events to occur in the CPU.
The exact sequence will depend on the instruction
and will move data around the CPU and between
CPU and memory (or I/O), as required to implement
the instruction.
So, registers hold data being worked on, the ALU
does the work, the buses communicate with the rest
of the system, and the instruction decode/control
module orchestrates everything.


HELLO WORLD
‘Hello World’ is the canonical first program, so why
don’t we start our exploration of Z80 assembly


language with it? We’re going to dive in head first
and then walk through and explain the code.
We want a program to output ‘Hello, World!’,
followed by a new line. We put the code below in a
file called hello.asm. Each line is a single instruction
that is made up of an opcode (what to do) and zero
or more operands (what data to use).
title ‘Hello, world’

ld bc, hello
loop:
ld a, (bc)
or 0
jp z, end
out (1), a
inc bc
jp loop
end:
halt

Right
The internals
of the Z80

CPU AND
SYSTEM
CONTROL
SIGNALS

INSTRUCTION
DECODE
AND
CPU
CONTROL

CPU
CONTROL

INST.
REG

8-BIT
DATA BUS

INTERNAL DATA BUS

16-BIT
ADDRESS BUS

DATA BUS
CONTROL

CPU
REGISTERS

ADDRESS
CONTROL

ALU

+5 V GND CLOCK

The idea behind assembly language is to provide a
one-to-one mapping to machine code while being far
more readable and writable than a series of bytes


Free download pdf