Z80 instruction set


The Zilog Z80 is an 8-bit microprocessor introduced in 1976. The instruction set was designed to be upward binary compatible with the Intel 8080. Intel 8080 instructions are one to three bytes long whereas the Z80 requires up to four bytes per instruction.
Zilog continued to expand the instruction set of the Z80 with several successors including the Z180, Z280, and Z380. The latest iteration, the eZ80, was introduced in 2001 and was available for purchase as of 2025. The instruction set also appears on non-Zilog CPUs such as the Hitachi HD64180, Mitsui R800, and the Eastern Bloc U880.

Instruction set

The Z80 uses 252 out of the available 256 codes as single byte opcodes, most of which are inherited from the 8080. The four remaining codes are used extensively as opcode prefixes: [|CB] and [|ED] enable extra instructions, and DD or FD select IX or IY respectively in place of HL. This scheme gives the Z80 a large number of permutations of instructions and registers. Zilog categorizes these into 158 different "instruction types", 78 of which are the same as those of the Intel 8080. This allows operation of all 8080 programs on a Z80. The Zilog documentation further groups instructions into categories. Most are from the 8080, others are entirely new like the block and bit instructions, and other 8080 instructions with more versatile addressing modes, like the 16-bit loads, I/O, rotates/shifts, and relative jumps. The categories are:
  • Load and exchange
  • Block transfer and search
  • Arithmetic and logical
  • Rotate and shift
  • Bit manipulation
  • Jump, call, and return
  • Input/output
  • CPU control

    Encoding order

To expand on the 8080 instruction set, Z80 instructions may require a [|IX/IY override], an opcode prefix, or both. Any one instruction may contain up to four components. The components of the instruction are assembled in the following order:
IX/IY override
CB or ED prefix
offset if CB
Opcode
offset if no CB
data or address

Root instructions

The root opcodes include all the 8080 opcodes. The Z80 adds eight new one-byte instructions, two opcode prefixes, and the IX and IY overrides. indicate new Z80 instructions.

Instructions prefixed with ED

The ED-prefixed opcodes are a catch-all of new Z80 instructions that could not be encoded in one byte. This group encompasses only 60 of 256 available opcodes.

Instructions prefixed with CB

The CB-prefixed opcodes cover shifts and rotates plus the bit test, clear, and set instructions. All of these instructions can be used with any register or memory. The form of these instructions can be combined with an IX or IY opcode prefix to operate on or. This group encompasses 248 of 256 available opcodes.

IX and IY overrides

Two opcode prefixes expand the number of Z80 addressing modes to access the new IX and IY index registers:
  • Prefix DD changes HL to IX or to
  • Prefix FD changes HL to IY or to
The index registers, IX and IY, were intended as flexible 16-bit pointers, enhancing the ability to manipulate memory, stack frames, and data structures. Officially, they were treated as 16-bit only. In reality, they were implemented as a pair of 8-bit registers in the same fashion as the HL register, which is accessible either as 16 bits or separately as the high and low registers. The binary opcodes were identical, but preceded by a new opcode prefix.

Undocumented uses of IX/IY

Zilog published the opcodes and related mnemonics for the intended functions, but did not document the fact that every opcode that allowed manipulation of the HL register was equally valid for the 8-bit halves of the IX and IY registers. For example, opcode 26h followed by an immediate byte value forms the instruction. It will load the n immediate value into the H register. Preceding this two-byte instruction with the IX register's opcode prefix, DD, would instead result in the most significant 8 bits of the IX register being loaded with that same value. A notable exception to this would be instructions similar to which make use of both the HL and IX or IY registers in the same instruction. In this case the DD prefix is only applied to the portion of the instruction.
Accessing the IX/IY halves can speed some operations. To load DE into IX using official instructions, one could use and, taking 25 cycles. Using the half-load feature, the same could be coded as and, saving 9 cycles but taking an extra byte.
The IX and IY halves can also hold operands for 8-bit arithmetic, logical, and compare instructions, sparing the regular 8-bit registers for other use. Any IX/IY half can be incremented or decremented or loaded to or from any 8-bit register except H or L.

Instruction synonyms

The Z80 expands the 8080 instruction set and makes it more orthogonal. A byproduct of this is there are certain instruction functions that map to two different instruction encodings. In a few cases there is an 8080 instruction coding that is smaller and faster than the orthogonal Z80 encoding. Some examples:
  • The Z80 introduced orthogonal versions of and instructions where RP can be any register pair or SP. The Z80 assembler substitutes the 8080 version of and to save a byte and four clocks.
  • ,,,, and instructions are part of the Z80 CB-prefixed rotates. The 8080,,,, and instructions are a byte smaller and twice as fast.
  • The Z80 introduced a two-byte unconditional jump,. Although larger, the three-byte 8080 is two clocks faster.
  • The Z80 added two-byte conditional jumps:,,, and as alternates to the 8080 three byte conditional jumps:,,, and. Although the two-byte forms are two clocks slower when taken, they are three clocks faster when not taken.
  • The Z80 DJNZ instruction is half the size of the 8080 equivalent instructions and one clock faster.