Top Qs
Timeline
Chat
Perspective

Z80 instruction set

From Wikipedia, the free encyclopedia

Remove ads

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. 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, with the latest iteration, the eZ80, introduced in 2001 and available for purchase as of 2025. The instruction set also appears on non-Zilog CPUs such as the R800.

Remove ads

Instruction set

Summarize
Perspective
Thumb
Zilog Z80 CPU. 1976 date code.

The Z80 uses 252 out of the available 256 codes as single byte opcodes (the "root instructions"), most of which are inherited from the 8080. The four remaining codes are used extensively as opcode prefixes:[1] 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,[1] allowing operation of all 8080 programs on a Z80. The Zilog documentation[2] 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:

  • Load and exchange
  • Block transfer and search
  • Arithmetic and logical
  • Rotate and shift
  • Bit manipulation (set, reset, test)
  • 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. The elements of the instruction are assembled in the following order:

IX/IY override
CB or ED prefix
(IX/IY + n) offset if CB present
Opcode
data or address
(IX/IY + n) offset without CB

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.[3]

More information Opcode, Operands ...

OUT port,A and IN A,port instructions generate a 16-bit port address with the 8-bit immediate port number forming the lower part of the address and the A register forming the upper part. Typically, devices will only decode the lower part. In contrast, the 8080 duplicates the immediate port number on both the upper and lower address bus.

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 56 of 256 available opcodes.[3]

More information Opcode, Operands ...

When D = 1, pointers HL and DE decrement. When R = 1, operation repeats until BC or B = 0. CPIR/CPDR may terminate early if A = (HL). All block IO instructions output BC, not just C, as the port address.

LD A,I and LD A,R are the only two LD instructions that set flags. Additionally, IFF2 is loaded into the P/O flag. C unaffected.

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. This group encompasses 248 of 256 available opcodes.[3]

More information Opcode, Mnemonic ...

IX and IY overrides

Two opcode prefixes expand the number of Z80 addressing modes to access the new IX and IY index registers:

  • Prefix ED changes HL to IX or (HL) to (IX+displacement)
  • Prefix FD changes HL to IY or (HL) to (IY+displacement)

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,[4] 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.[5] 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 portions of the IX and IY registers. For example, the opcode 26h followed by an immediate byte value forms the instruction LD H,n. It will load that 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 LD H,(IX+d) which make use of both the HL and IX or IY registers in the same instruction.[5] In this case the DD prefix is only applied to the (IX+d) portion of the instruction. The halves of the XY registers could also hold operands for 8-bit arithmetic, logical, and compare instructions, sparing the regular 8-bit registers for other use.

Remove ads

References

Loading related searches...

Wikiwand - on

Seamless Wikipedia browsing. On steroids.

Remove ads