Software implementation examples – Zilog Z08470 User Manual
Page 38

Hardware and Software Implementation
UM008007-0715
26
Z80 CPU
User Manual
Software Implementation Examples
The Z80 instruction set provides the user with a large number of operations to control the
Z80 CPU. The main alternate and index registers can hold arithmetic and logical opera-
tions, form memory addresses, or act as fast-access storage for frequently used data.
Information can be moved directly from register to register, memory to memory, memory
to registers, or from registers to memory. In addition, register contents and register/mem-
ory contents can be exchanged without using temporary storage. In particular, the contents
of main and alternate registers can be completely exchanged by executing only two
instructions, EX and EXX. This register exchange procedure can be used to separate the
set of working registers from different logical procedures or to expand the set of available
registers in a single procedure.
Storage and retrieval of data between pairs of registers and memory can be controlled on a
last-in first-out basis through PUSH and POP instructions that utilize a special Stack
Pointer (SP) Register. This stack register is available both to manipulate data and to auto-
matically store and retrieve addresses for subroutine linkage. When a subroutine is called,
for example, the address following the CALL instruction is placed on the top of the push-
down stack pointed to by SP. When a subroutine returns to the calling routine, the address
on the top of the stack is used to set the program counter for the address of the next
instruction. The stack pointer is adjusted automatically to reflect the current top stack
position during PUSH, POP, CALL, and RET instructions. This stack mechanism allows
pushdown data stacks and subroutine calls to be nested to any practical depth because the
stack area can potentially be as large as memory space.
The sequence of instruction execution can be controlled by six different flags (carry, zero,
sign, parity/overflow, add/subtract, half-carry), which reflect the results of arithmetic, log-
ical, shift, and compare instructions. After the execution of an instruction that sets a flag,
that flag can be used to control a conditional jump or return instruction. These instructions
provide logical control following the manipulation of single bit, 8-bit byte, or 18-bit data
quantities.
A full set of logical operations, including AND, OR, XOR (exclusive-OR), CPL (NOR),
and NEG (two’s complement) are available for Boolean operations between the Accumu-
lator and all other 8-bit registers, memory locations, or immediate operands.
In addition, a full set of arithmetic and logical shifts in both directions are available which
operate on the contents of all 8-bit primary registers or directly on any memory location.
The carry flag can be included or set by these shift instructions to provide both the testing
of shift results and to link register/register or register/memory shift operations.