Difference between revisions of "Z80"

From CPCWiki - THE Amstrad CPC encyclopedia!
Jump to: navigation, search
(Registers)
(Oddities)
 
(417 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[image:Z80A.jpg|thumb|Zilog Z80A]]
 
[[image:Z80A.jpg|thumb|Zilog Z80A]]
Microprocessor from Zilog, which is used in the Amstrad CPC Computers. The Z80/Z80A was a very popular microprocessor, used in a great variety of home computers and appliances as far-fetched as satellites. It was even used in the Commodore C128 as a secondary processor in order to achieve [[CP/M]] compatibility.
+
The Z80 is an 8-bit microprocessor designed by Zilog founder and CEO Federico Faggin, first released in July 1976. It is the CPU used in the Amstrad CPC / Plus / PCW computers.
  
== Description ==
+
The Z80/Z80A was a very popular microprocessor, used in a wide range of applications, from gaming consoles like the [[ColecoVision]] or the [[Sega Master System]] to handhelds like the [[Sega GameGear]] or some TI calculators to personal computers like the [[ZX81]], [[ZX Spectrum]], [[MSX]] and [[VG 5000]].
  
The Z80 microprocessor is an 8 bit [[CPU]] with a 16 bit address bus capable of direct access to 64k of memory space. It has a language of 252 root instructions and with the reserved 4 bytes as prefixes, access to an additional 308 instructions. The Z80 was modelled after the [[8080]] and contains the seventy-eight 8080 opcodes as a subset to its language.  
+
It was even used in the [[Sega MegaDrive]] as the sound CPU and in the [[Commodore C128]] as a secondary processor in order to achieve [[CP/M]] compatibility. Similarly, the Acorn Z80 Second Processor expansion for the [[BBC Micro]] enables [[CP/M]] compatibility.
  
Programming features include an accumulator and six 8-bit registers that can be paired as three 16-bit registers. In addition to the general registers, a stack pointer, program counter, and two index (memory pointer) registers are provided. While not in the same league as the Intel 80x86 or the [[Motorola 68000]] series, the Z80 is extremely useful for low cost control applications. One of the more useful features of the Z80 is the built-in refresh circuitry for ease of design with DRAMs.
+
<br>
  
The Z80 comes in a 40 pin DIP package. It has been manufactured in A, B, and C models, differing only in maximum clock speed. It also has been manufactured as a stand-alone microcontroller with various configurations of on-chip RAM and EPROM.
+
== History ==
  
== Part numbers used in the Amstrad CPC during its lifetime ==
+
In the early 1970s, Intel developed the 8080, one of the first widely used microprocessors. However, a group of engineers led by Federico Faggin, the originator of the 8080 architecture in early 1972, left Intel to start their own company called Zilog in 1974.
  
The Z80 CPU has been manufactured by others, and various Z80s have been used in the construction of the CPC during its lifetime.
+
At Zilog, Faggin and his team wanted to create an improved version of the 8080 that would be more efficient, flexible, and easier to use. This led to the development of the Z80, which was designed to be both backward-compatible with the 8080 and more powerful. This compatibility meant that any software written for the 8080 could run on the Z80, making it an attractive upgrade for manufacturers and developers.
  
* SGS Z8400AB1
+
The Z80 had several key improvements over the 8080. It featured more registers, block instructions, bitwise ops, indexed addressing, and improved interrupt handling. It also had built-in memory refresh for dynamic RAM, that made it easier to build systems around it.
* ST Z8400AB1
+
* ZILOG Z8400APS
+
* ZILOG Z0840004PSC
+
  
=== modern incarnatinons ===
+
<br>
{{stub}}
+
  
Apart from surplus/new Z80-clones that are quite easy to find, many emulations depend on software implementations of the Z80:
+
== Description ==
  
* The [[T80]] is a [[VHDL|VHDL]] implementation of the Z80 and Z80A, finished in 2002 on [[OpenCores|OpenCores]]
+
The Z80 microprocessor is an 8-bit [[CPU]] with a 4-bit ALU and a 16-bit address bus capable of direct access to 64KB of memory space. The Z80 is a little-endian CPU, meaning it stores 16-bit values with the least significant byte first, followed by the most significant byte.
* [[arnold]] uses [[InkZ80]], written in C++ (apart from the author-designed C simulation)
+
* On OpenCores, there is also a [[Verilog|Verilog]] implementation of the Z80.
+
  
[[Zilog]] itself offers the [[eZ80|eZ80]] processor, a new, 50MHz design. Kits now have reached a less-than-prohibitive price range and may be available without a business.
+
It has a language of 252 root instructions and with the reserved 4 bytes as prefixes, access to an additional 308 instructions. Although it lacks the raw processing power of processors like the Intel 80x86 or the [[Motorola 68000]] series, the Z80 is extremely useful for low cost control applications.
  
== See also ==
+
The Z80 has about 8500 transistors. To put it into perspective, 64KB of DRAM contains 524288 transistors, as 1 bit of DRAM needs 1 transistor. Fun fact: an Amstrad CPC equipped with a 4MB RAM expansion has 32 million transistors dedicated to RAM while the Z80 CPU still has only 8500 transistors.
  
* [[Z80 - undocumented opcodes]]
+
The Z80 is mid-1970s technology while the 64KB DRAM is early-1980s technology and the 4MB DRAM is early-1990s technology.
* [[Media:Z80 CPC Timings cheat sheet.20230709.pdf]]
+
  
== Block Diagram ==
+
The Z80 comes in a 40-pin DIP package. It has been manufactured in A, B, and C models, differing only in maximum clock speed. It also has been manufactured as a stand-alone microcontroller with various configurations of on-chip RAM and EPROM.
[[File:Z80 Block Diagram.gif]]
+
  
== Manuals ==
+
<br>
  
*[[Media:Um0080.pdf|Official Zilog Z80 CPU user manual (2016)]]
+
== Part numbers used in the Amstrad CPC during its lifetime ==
*[[Media:Z80 CPU Technical Manual 1977.pdf]]
+
*[[Media:Mostek Z80 Programming Manual.pdf]]
+
  
== Weblinks ==
+
The Z80 CPU has been manufactured by others, and various Z80s have been used in the construction of the CPC during its lifetime:
 +
* Mostek MK3880N-4 [https://www.cpcwiki.eu/imgs/e/ee/MC0008D_Z70200_LeZone_PCB_Top.jpg Source]
 +
* NEC D780C [https://www.cpcwiki.eu/imgs/c/c6/CPC464_270100_MC0001A_PCB_Top.jpg Source]
 +
* SGS Z8400AB1 [https://www.cpcwiki.eu/imgs/5/52/CPC464_PCB_Top_%28Z70200_MC0002B%29.jpg Source]
 +
* ST Z8400AB1 [https://www.cpcwiki.eu/imgs/8/8e/CPC464_PCB_Top_%28Z80329_MC0099A%29.jpg Source]
 +
* ZILOG Z8400APS [https://www.cpcwiki.eu/imgs/9/91/CPC464_PCB_Top_%28Z70100%29_GA40007-4.jpg Source]
 +
* ZILOG Z0840004PSC [https://www.cpcwiki.eu/imgs/8/88/CPC464_MC0044B_PCB_Top.jpg Source]
  
*[[Zilog]] [http://www.zilog.com]
+
All the Z80 CPUs that have been used on CPC and Plus machines are NMOS. [https://www.cpcwiki.eu/forum/amstrad-cpc-hardware/z80-cpu-nmos-or-cmos/ Source]
*[http://www.z80.info/z80cs.htm Computer Systems based on Z80 Family]
+
 
*[http://en.wikipedia.org/wiki/Z80 The Z80 processor on Wikipedia]
+
Zilog ended the production of the Z80 in April 2024. This chip is still available in ample quantities through NOS chip suppliers. And Zilog continues to produce the [[eZ80]] which is a modernized Z80 CPU.
*[https://www.grimware.org/doku.php/documentations/devices/z80 Z80 documentation from Grimware]
+
 
*[https://floooh.github.io/2021/12/06/z80-instruction-timing.html Detailed look at Z80 instruction timings with the help of a Z80 netlist simulation]
+
<br>
*[https://wikiti.brandonw.net/index.php?title=Z80_Instruction_Set Z80 Instruction Set on WikiTI]
+
 
 +
=== Modern incarnations ===
 +
 
 +
Apart from surplus/new Z80-clones that are quite easy to find, many emulations depend on software implementations of the Z80:
 +
 
 +
* The [[T80]] is a [[VHDL|VHDL]] implementation of the Z80 and Z80A, finished in 2002 on [[OpenCores|OpenCores]]
 +
* [[arnold]] uses [[InkZ80]], written in C++ (apart from the author-designed C simulation)
 +
* On OpenCores, there is also a [[Verilog|Verilog]] implementation of the Z80.
 +
 
 +
<br>
  
 
== Registers==
 
== Registers==
  
{| class="wikitable"
+
{| class="wikitable" style="white-space: nowrap;"
 
! Register !! Size !! Description !! Notes
 
! Register !! Size !! Description !! Notes
 
|-
 
|-
Line 65: Line 70:
 
* bit7 - SF - Sign Flag
 
* bit7 - SF - Sign Flag
 
* bit6 - ZF - Zero Flag
 
* bit6 - ZF - Zero Flag
* bit5 - F5 - Undocumented
+
* bit5 - F5 - Undocumented by Zilog
 
* bit4 - HF - Half Carry Flag
 
* bit4 - HF - Half Carry Flag
* bit3 - F3 - Undocumented
+
* bit3 - F3 - Undocumented by Zilog
 
* bit2 - PF - Parity Flag (also sometimes used for Overflow)
 
* bit2 - PF - Parity Flag (also sometimes used for Overflow)
* bit1 - NF - Negation Flag (last ALU op was subtract or compare)
+
* bit1 - NF - Negate Flag (last ALU op was subtract or compare)
 
* bit0 - CF - Carry Flag
 
* bit0 - CF - Carry Flag
|| Flags are affected by most operations
+
|| Flags (including F5 and F3) are affected by most operations.
 +
HF and NF are used in the DAA algorithm.
 
|-
 
|-
 
| AF', BC', DE', HL' || 16-bit || Alternate register set || Swappable with primary registers for fast context switching
 
| AF', BC', DE', HL' || 16-bit || Alternate register set || Swappable with primary registers for fast context switching
Line 83: Line 89:
 
| I (Interrupt Vector) || 8-bit || Holds base address for interrupt mode 2 || Combined with external data to form an interrupt vector
 
| I (Interrupt Vector) || 8-bit || Holds base address for interrupt mode 2 || Combined with external data to form an interrupt vector
 
|-
 
|-
| R (Memory Refresh) || 8-bit || Increments after each instruction fetch to refresh DRAM || Only the lower 7 bits are incremented
+
| R (Memory Refresh) || 8-bit || Increments after each M1 cycle (instruction or prefix fetch) to refresh DRAM || Only the lower 7 bits are incremented. Bit7 can only be changed by writing to the R register.
 +
|}
 +
 
 +
<br>
 +
 
 +
== Internal state ==
 +
 
 +
{| class="wikitable" style="white-space: nowrap;"
 +
! Register !! Size !! Description !! Notes
 
|-
 
|-
| IFF1 || 1-bit || Interrupt enable flag || Set when interrupts are enabled, cleared on disable
+
| IM (Interrupt Mode) || 2-bit || Specifies the interrupt mode (0, 1, or 2) || Controls how interrupts are handled:
 +
* IM 0: External devices provide an opcode to execute (most likely an RST instruction). This mode was originally implemented in the Intel 8080 CPU
 +
* IM 1: Fixed vector at 0038h
 +
* IM 2: Vector provided by I register and external data
 +
 
 +
The NMI vector is fixed at 0066h, regardless of the I register, and of the IM interrupt mode.
 
|-
 
|-
| IFF2 || 1-bit || IFF1 buffer || Allows interrupts to be enabled after the instruction following EI
+
| IFF1 || 1-bit || Main Interrupt Flip-Flop || Set when interrupts are enabled, cleared on disable.
 +
When the CPU accepts a maskable interrupt, both IFF1 and IFF2 are automatically cleared, inhibiting further interrupts.
 
|-
 
|-
| WZ || 16-bit || Internal temporary register pair || Used for memory and address calculations (not user-accessible)
+
| IFF2 || 1-bit || Stores the state of IFF1 during Non-Maskable Interrupts (NMI) || When an NMI occurs, the processor clears IFF1 to disable interrupts temporarily.
 +
IFF2 stores the previous state of IFF1 so that after the NMI is handled, IFF1 can be restored to its original state.
 +
 
 +
A barebone Amstrad CPC doesn't use NMI. So IFF1 and IFF2 are always the same. However, NMI is used by the [[PlayCity]] and [[Play2CPC]] expansions.
 +
|-
 +
| WZ || 16-bit || Internal temporary register pair. Also known as MEMPTR || Used for memory and address calculations.
 +
Normally, you never see the content of this register. But it leaks through the flags F5 and F3 in the BIT b,(HL) instruction. [https://zx-pk.ru/attachment.php?attachmentid=2989 Source]
 +
|-
 +
| Q || 8-bit || Internal register where it assembles the new content of the F register, before moving it back to F ||
 +
  On Zilog NMOS Z80, when the instruction doesn't compute new flags, this register is cleared instead. But not on NEC NMOS Z80. And CMOS Z80 behave in a different way too.
 +
  Normally, you never see the content of this register. But it leaks through F5 and F3 in the SCF/CCF instructions. [https://worldofspectrum.org/forums/discussion/41704 Source]
 +
  Emulating Q is not strictly necessary. A 1-bit flag, indicating whether the previous instruction computed flags, is enough to emulate the behaviour of SCF/CCF. [https://github.com/hoglet67/Z80Decoder/wiki/Undocumented-Flags#scfccf Source]
 +
  Also note that while POP AF and EX AF,AF' modify F, they do not compute new flag values.
 +
 
 +
The explanation above is just an approximation. Latest research on the subject (May 2024) show that '''SCF/CCF instructions are unstable'''. [https://github.com/hoglet67/Z80Decoder/wiki/Unstable-CCF-SCF-Behaviour Source]
 +
|-
 +
| IR (Instruction Register) || 8-bit || Holds the opcode of the currently executing instruction || Internally used, not accessible by the programmer. Not to be confused with I (Interrupt Vector) and R (Memory Refresh) registers.
 +
|-
 +
| EIP (Extended Instruction Prefix) || 2-bit || Holds the prefix for extended instructions (CB, ED, or none) || Used for extended instruction sets like bitwise ops.
 +
|-
 +
| IMP (Indexing Mode Prefix) || 2-bit || Specifies the indexing mode (DD for IX+d, FD for IY+d, or none for HL) || Indicates use of index registers (IX or IY) for memory access.
 
|}
 
|}
  
== Opcodes ==
+
Notes:
 +
* EIP and IMP can be fusioned into a 3-bit internal state as there are only 7 possible values for the prefixes (none, ed, dd, fd, cb, ddcb, fdcb). Probably not a win though as it makes everything more confusing.
 +
* IFF1 / IFF2 are called IEF1 / IEF2 (Interrupt Enable Flip-flops) in the Zilog eZ80 manual.
  
Check the end of the document for explanations of abbreviations used below.
+
<br>
  
=== Alphabetical list ===
+
== Z80 Instructions ==
  
{|{{Prettytable|width: 700px; font-size: 2em;}}
+
=== Legend ===
|''Mnemonic''||''Clock''||''Size''||''SZHPNC''||''Opcode''||''Description||''Notes''
+
 
|- style="background:#efefef;"
+
{| class="wikitable" style="white-space: nowrap;"
|ADC A, r||4||1||rowspan=5|*** V0 *||88 + rb||rowspan=5|Add with Carry||rowspan=5|A = A + s + CY
+
! Notation !! Meaning !! Respective Opcode Bits
|- style="background:#efefef;"
+
|ADC A, N||7||2||CE XX
+
|- style="background:#efefef;"
+
|ADC A, (HL)||7||1||8E
+
|- style="background:#efefef;"
+
|ADC A, (IX + N)||19||3||DD 8E XX 
+
|- style="background:#efefef;"
+
|ADC A, (IY + N)||19||3||FD 8E XX 
+
 
|-
 
|-
|ADC HL, BC||15||2||rowspan=4|**? V0 *||ED 4A||rowspan=4|Add with Carry||rowspan=4|HL = HL + ss + CY
+
| A || 16-bit address or immediate || alalalal ahahahah
 
|-
 
|-
|ADC HL, DE||15||2||ED 5A
+
| B || Bit number (0..7) || bbb = 000..111
 
|-
 
|-
|ADC HL, HL||15||2||ED 6A
+
| C || Condition (nz, z, nc, c, po, pe, p, m)
 +
nz: ZF=0, z: ZF=1, nc: CF=0, c: CF=1, po: PF=0, pe: PF=1, p: SF=0, m: SF=1
 +
|| ccc = 000, 001, 010, 011, 100, 101, 110, 111
 
|-
 
|-
|ADC HL, SP||15||2||ED 7A
+
| D || 8-bit signed relative offset || dddddddd
|- style="background:#efefef;"
+
|ADD A, r||4||1||rowspan=5|*** V0 *||80 + rb||rowspan=5|Add (8-bit)||rowspan=5|A = A + s
+
|- style="background:#efefef;"
+
|ADD A, N||7||2||C6 XX 
+
|- style="background:#efefef;"
+
|ADD A, (HL)||7||1||86
+
|- style="background:#efefef;"
+
|ADD A, (IX + N)||19||3||DD 86 XX
+
|- style="background:#efefef;"
+
|ADD A, (IY + N)||19||3||FD 86 XX
+
 
|-
 
|-
|ADD HL, BC||11||1||rowspan=4|--?- 0 *||09||rowspan=4|Add (16-bit)||rowspan=4|HL = HL + ss
+
| E || 16-bit relative address || dddddddd (E minus address of next instruction)
 
|-
 
|-
|ADD HL, DE||11||1||19
+
| I || Index register (ix, iy) || i = 0, 1
 
|-
 
|-
|ADD HL, HL||11||1||29
+
| J || Half index register (ixh, ixl, iyh, iyl) || (i, b) = (0, 0), (0, 1), (1, 0), (1, 1)
 
|-
 
|-
|ADD HL, SP||11||1||39
+
| N || 8-bit immediate || nnnnnnnn
|- style="background:#efefef;"
+
|ADD IX, BC||15||2||rowspan=4|--?- 0 *||DD 09||rowspan=4|Add (IX register)||rowspan=4|IX = IX + pp
+
|- style="background:#efefef;"
+
|ADD IX, DE||15||2||DD 19
+
|- style="background:#efefef;"
+
|ADD IX, IX||15||2||DD 29
+
|- style="background:#efefef;"
+
|ADD IX, SP||15||2||DD 39
+
|-
+
|ADD IY, BC||15||2||rowspan=4|--?- 0 *||FD 09||rowspan=4|Add (IY register)||rowspan=4|IY = IY + rr
+
 
|-
 
|-
|ADD IY, DE||15||2||FD 19
+
| P || 16-bit register pair (bc, de, hl, af) || pp = 00, 01, 10, 11
 
|-
 
|-
|ADD IY, IY||15||2||FD 29
+
| Q || 16-bit register (bc, de, hl/ix/iy, sp) || qq = 00, 01, 10, 11
 
|-
 
|-
|ADD IY, SP||15||2||FD 39
+
| R || 8-bit general purpose register (a, b, c, d, e, h, l) || rrr (or sss) = 111, 000, 001, 010, 011, 100, 101
|- style="background:#efefef;"
+
|AND r||4||1||rowspan=5|***P00||A0+rb||rowspan=5|Logical AND||rowspan=5|A=A&s
+
|- style="background:#efefef;"
+
|AND N||7||2||E6 XX
+
|- style="background:#efefef;"
+
|AND (HL)||7||1||A6
+
|- style="background:#efefef;"
+
|AND (IX+N)||19||3||DD A6 XX
+
|- style="background:#efefef;"
+
|AND (IY+N)||19||3||FD A6 XX
+
 
|-
 
|-
|BIT b,r||8||2||rowspan=4|?*1?0-||CB 40+8*b+rb||rowspan=4|Test Bit||rowspan=4|m&{2^b}
+
| S || Restart address (0x00, 0x08,..., 0x38) || sss = 000, 001,..., 111
 +
|}
 +
 
 +
==== Flags ====
 +
* - = no change
 +
* + = change by definition (if noted, by the operation marked with '=> flags', otherwise by the only non-single-bit operation):
 +
* S = sign, bit 7 of the result byte (accumulator or high byte for 16-bit operations)
 +
* Z = zero, set if the result is zero (8 or 16-bit value)
 +
* 5 = undocumented, bit 5 of the result byte
 +
* H = half-carry, the carry (theoretical bit 4) of the low nibble of the result byte
 +
* 3 = undocumented, bit 3 of the result byte
 +
* P = parity (set if the result byte has an even number of bits set) or overflow (set when crossing the boundary of the signed range); always specified
 +
* N = negative, set if the previous operation was a subtraction; always specified
 +
* C = carry, the theoretical bit 8 of the result byte
 +
* 0 = always reset
 +
* 1 = always set
 +
* X = change described under Effect
 +
* P = parity (only for the parity flag)
 +
* V = overflow (only for the parity flag)
 +
* A = OR with the respective bit of the accumulator
 +
* C = set if the counter (bc) is nonzero after decrementing
 +
 
 +
==== Miscellaneous ====
 +
* () = indirection
 +
* (()) = I/O port
 +
* [] = operator precedence (to avoid confusion with indirection)
 +
* E.B = the Bth bit of the value of expression E
 +
* * = any bit value (0 or 1)
 +
* wz = an internal 16-bit register connected to 16-bit operations
 +
* tmp, tmp2 = temporary storage whose value is thrown away after each instruction
 +
 
 +
=== Letter A ===
 +
 
 +
{| class="wikitable" style="white-space: nowrap;"
 
|-
 
|-
|BIT b,(HL)||12||2||CB 46+8*b
+
! Instruction !! Opcode !! NOPs !! Cycles !! S !! Z !! 5 !! H !! 3 !! P !! N !! C !! Effect !! Description
 
|-
 
|-
|BIT b,(IX+N)||20||4||DD CB XX 46+8*b
+
| adc a,R || 10001rrr || 1 || 4 (4) || + || + || + || + || + || V || 0 || + || a += R + cf ||rowspan=6|Add with Carry
 
|-
 
|-
|BIT b,(IY+N)||20||4||FD CB XX 46+8*b
+
| adc a,J || 11i11101 1000110b || 2 || 8 (4,4) || + || + || + || + || + || V || 0 || + || a += J + cf
|- style="background:#efefef;"
+
|CALL NN||17||3||------||CD XX XX||Unconditional Call||-(SP)=PC,PC=nn
+
 
|-
 
|-
|CALL C,NN||17/1||3||rowspan=8|------||DC XX XX||rowspan=8|Conditional Call||If Carry = 1
+
| adc a,N || 11001110 nnnnnnnn || 2 || 7 (4,3) || + || + || + || + || + || V || 0 || + || a += N + cf
 
|-
 
|-
|CALL NC,NN||17/1||3||D4 XX XX||If carry = 0
+
| adc a,(hl) || 10001110 || 2 || 7 (4,3) || + || + || + || + || + || V || 0 || + || a += (hl) + cf
 
|-
 
|-
|CALL M,NN||17/1||3||FC XX XX||If Sign = 1 (negative)
+
| adc a,(I+D) || 11i11101 10001110 dddddddd || 5 || 19 (4,4,3,5,3) || + || + || + || + || + || V || 0 || + || a += (I+D) + cf
 
|-
 
|-
|CALL P,NN||17/1||3||F4 XX XX||If Sign = 0 (positive)
+
| adc hl,Q || 11101101 01qq1010 || 4 || 15 (4,4,4,3) || + || + || + || + || + || V || 0 || + || hl += Q + cf
 
|-
 
|-
|CALL Z,NN||17/1||3||CC XX XX||If Zero = 1 (ans.=0)
+
| add a,R || 10000rrr || 1 || 4 (4) || + || + || + || + || + || V || 0 || + || a += R ||rowspan=7|Add
 
|-
 
|-
|CALL NZ,NN||17/1||3||C4 XX XX||If Zero = 0 (non-zero)
+
| add a,J || 11i11101 1000010b || 2 || 8 (4,4) || + || + || + || + || + || V || 0 || + || a += J
 
|-
 
|-
|CALL PE,NN||17/1||3||EC XX XX||If Parity = 1 (even)
+
| add a,N || 11000110 nnnnnnnn || 2 || 7 (4,3) || + || + || + || + || + || V || 0 || + || a += N
 
|-
 
|-
|CALL PO,NN||17/1||3||E4 XX XX||If Parity = 0 (odd)
+
| add a,(hl) || 10000110 || 2 || 7 (4,3) || + || + || + || + || + || V || 0 || + || a += (hl)
|- style="background:#efefef;"
+
|CCF||4||1||--?-0*||3F||Complement Carry Flag||CY=~CY
+
 
|-
 
|-
|CP r||4||1||rowspan=5|***V1*||B8+rb||rowspan=5|Compare||rowspan=5|Compare A-s
+
| add a,(I+D) || 11i11101 10000110 dddddddd || 5 || 19 (4,4,3,5,3) || + || + || + || + || + || V || 0 || + || a += (I+D)
 
|-
 
|-
|CP N||7||2||FE XX
+
| add hl,Q || 00qq1001 || 3 || 11 (4,4,3) || - || - || + || + || + || - || 0 || + || hl += Q
 
|-
 
|-
|CP (HL)||7||1||BE
+
| add I,Q || 11i11101 00qq1001 || 4 || 15 (4,4,4,3) || - || - || + || + || + || - || 0 || + || I += Q
 
|-
 
|-
|CP (IX+N)||19||3||DD BE XX
+
| and R || 10100rrr || 1 || 4 (4) || + || + || + || 1 || + || P || 0 || 0 || a := a AND R ||rowspan=5|Logical AND
 
|-
 
|-
|CP (IY+N)||19||3||FD BE XX
+
| and J || 11i11101 1010010b || 2 || 8 (4,4) || + || + || + || 1 || + || P || 0 || 0 || a := a AND J
 
|-
 
|-
|CPD||16||2||****1-||ED A9||Compare and Decrement||A-(HL),HL=HL-1,BC=BC-1
+
| and N || 11100110 nnnnnnnn || 2 || 7 (4,3) || + || + || + || 1 || + || P || 0 || 0 || a := a AND N
 
|-
 
|-
|CPDR||21/1||2||****1-||ED B9||Compare, Dec., Repeat||CPD till A=(HL)or BC=0
+
| and (hl) || 10100110 || 2 || 7 (4,3) || + || + || + || 1 || + || P || 0 || 0 || a := a AND (hl)
 
|-
 
|-
|CPI||16||2||****1-||ED A1||Compare and Increment||A-(HL),HL=HL+1,BC=BC-1
+
| and (I+D) || 11i11101 10100110 dddddddd || 5 || 19 (4,4,3,5,3) || + || + || + || 1 || + || P || 0 || 0 || a := a AND (I+D)
 +
|}
 +
 
 +
=== Letter B ===
 +
 
 +
{| class="wikitable" style="white-space: nowrap;"
 
|-
 
|-
|CPIR||21/1||2||****1-||ED B1||Compare, Inc., Repeat||CPI till A=(HL)or BC=0
+
! Instruction !! Opcode !! NOPs !! Cycles !! S !! Z !! 5 !! H !! 3 !! P !! N !! C !! Effect !! Description
|- style="background:#efefef;"
+
|CPL||4||1||--1-1-||2F||Complement||A=~A
+
 
|-
 
|-
|DAA||4||1||***P-*||27||Decimal Adjust Acc.||A=BCD format (dec.)
+
| bit B,R || 11001011 01bbbrrr || 2 || 8 (4,4) || + || + || + || 1 || + || P || 0 || - || tmp := R AND [1 << B] ||rowspan=3|Test Bit
|- style="background:#efefef;"
+
|DEC A||4||1||rowspan=10|***V1-||3D||rowspan=10|Decrement (8-bit)||rowspan=7|s=s-1
+
|-
+
|DEC B||4||1||05
+
|-
+
|DEC C||4||1||0D
+
|-
+
|DEC D||4||1||15
+
|-
+
|DEC E||4||1||1D
+
|-
+
|DEC H||4||1||25
+
|-  
+
|DEC L||4||2||2D
+
|-
+
|DEC (HL)||11||1||35||(HL)=(HL)-1
+
|-
+
|DEC (IX+N)||23||3||DD 35 XX||rowspan=2|(xx-d)=(xx-d)+1
+
|-
+
|DEC (IY+N)||23||3||FD 35 XX
+
 
|-
 
|-
|DEC BC||6||1||rowspan=4|------||0B||rowspan=4|Decrement (16-bit)||rowspan=4|ss=ss-1
+
| bit B,(hl) || 11001011 01bbb110 || 3 || 12 (4,4,4) || + || + || X || 1 || X || P || 0 || - || tmp := (hl) AND [1 << B],
 +
f5 := wz.13, f3 := wz.11
 
|-
 
|-
|DEC DE||6||1||1B
+
| bit B,(I+D) || 11i11101 11001011 dddddddd 01bbb*** || 6 || 20 (4,4,3,5,4) || + || + || X || 1 || X || P || 0 || - || tmp := (I+D) AND [1 << B],
 +
f5 := [I+D].13, f3 := [I+D].11
 +
|}
 +
 
 +
=== Letter C ===
 +
 
 +
{| class="wikitable" style="white-space: nowrap;"
 
|-
 
|-
|DEC HL||6||1||2B
+
! Instruction !! Opcode !! NOPs !! Cycles !! S !! Z !! 5 !! H !! 3 !! P !! N !! C !! Effect !! Description
 
|-
 
|-
|DEC SP||6||1||3B
+
| call A || 11001101 alalalal ahahahah || 5 || 17 (4,3,4,3,3) || - || - || - || - || - || - || - || - || sp -= 2, (sp) := pc, pc := A || Call
|- style="background:#efefef;"
+
|DEC IX||10||2||rowspan=2|------||DD 2B||rowspan=2|Decrement||rowspan=2|xx=xx-1
+
|- style="background:#efefef;"
+
|DEC IY||10||2||FD 2B
+
 
|-
 
|-
|DI||4||1||------||F3||Disable Interrupts||
+
| call C,A || 11ccc100 alalalal ahahahah || 5/3 || 17/10 (4,3,4,3,3)/(4,3,3) || - || - || - || - || - || - || - || - || if C then sp -= 2, (sp) := pc, pc := A || Conditional Call
|- style="background:#efefef;"
+
|DJNZ $+2||13/8||1||------||10||Dec., Jump Non-Zero||B=B-1 till B=0
+
 
|-
 
|-
|EI||4||1||------||FB||Enable Interrupts||
+
| ccf || 00111111 || 1 || 4 (4) || - || - || A || X || A || - || 0 || X || hf := cf, cf := ~cf || Complement Carry Flag
|- style="background:#efefef;"
+
|EX (SP),HL||19||1||rowspan=5|------||E3||rowspan=5|Exchange||(SP)<->HL
+
|- style="background:#efefef;"
+
|EX (SP),IX||23||2||DD E3||(SP)<->xx
+
|- style="background:#efefef;"
+
|EX (SP),IY||23||2||FD E3||
+
|- style="background:#efefef;"
+
|EX AF,AF'||4||1||08||AF<->AF'
+
|- style="background:#efefef;"
+
|EX DE,HL||4||1||EB||DE<->HL
+
|- style="background:#efefef;"
+
|EXX||4||1||------||D9||Exchange||qq<->qq' (except AF)
+
 
|-
 
|-
|HALT||4||1||------||76||Halt||
+
| cp R || 10111rrr || 1 || 4 (4) || + || + || X || + || X || V || 1 || + || tmp := a - R, f5 := R.5, f3 := R.3 ||rowspan=5|Compare
|- style="background:#efefef;"
+
|IM 0||8||2||rowspan=3|------||ED 46||rowspan=3|Interrupt Mode ||rowspan=3|(n=0,1,2)
+
|- style="background:#efefef;"
+
|IM 1||8||2||ED 56
+
|- style="background:#efefef;"
+
|IM 2||8||2||ED 5E
+
|-
+
|IN A,(N)||11||2||------||DB XX||Input||A=(n)
+
 
|-
 
|-
|IN (C)||12||2||***P0-||ED 70||Input*||(Unsupported)
+
| cp J || 11i11101 1011110b || 2 || 8 (4,4) || + || + || X || + || X || V || 1 || + || tmp := a - J, f5 := J.5, f3 := J.3
 
|-
 
|-
|IN A,(C)||12||2||rowspan=7|***P0-||ED 78||rowspan=7|Input||rowspan=7|r=(C)
+
| cp N || 11111110 nnnnnnnn || 2 || 7 (4,3) || + || + || X || + || X || V || 1 || + || tmp := a - N, f5 := N.5, f3 := N.3
 
|-
 
|-
|IN B,(C)||12||2||ED 40
+
| cp (hl) || 10111110 || 2 || 7 (4,3) || + || + || X || + || X || V || 1 || + || tmp := a - (hl), f5 := (hl).5, f3 := (hl).3
 
|-
 
|-
|IN C,(C)||12||2||ED 48
+
| cp (I+D) || 11i11101 10111110 dddddddd || 5 || 19 (4,4,3,5,3) || + || + || X || + || X || V || 1 || + || tmp := a - (I+D), f5 := (I+D).5, f3 := (I+D).3
 
|-
 
|-
|IN D,(C)||12||2||ED 50
+
| cpd || 11101101 10101001 || 4 || 16 (4,4,3,5) || + || + || X || + || X || C || 1 || - || tmp := a - (hl) => flags, bc -= 1, hl -= 1,
 +
f5 := [tmp - hf].1, f3 = [tmp - hf].3
 +
|| Compare and Decrement
 
|-
 
|-
|IN E,(C)||12||2||ED 58
+
| cpdr || 11101101 10111001 || 6/4 || 21/16 (4,4,3,5,5)/(4,4,3,5) || + || + || X || + || X || C || 1 || - || cpd, if bc <> 0 and nz then pc -= 2 || Compare and Decrement, Repeat
 
|-
 
|-
|IN H,(C)||12||2||ED 60
+
| cpi || 11101101 10100001 || 4 || 16 (4,4,3,5)|| + || + || X || + || X || C || 1 || - || tmp := a - (hl) => flags, bc -= 1, hl += 1,
 +
f5 := [tmp - hf].1, f3 = [tmp - hf].3
 +
|| Compare and Increment
 
|-
 
|-
|IN L,(C)||12||2||ED 68
+
| cpir || 11101101 10110001 || 6/4 || 21/16 (4,4,3,5,5)/(4,4,3,5) || + || + || X || + || X || C || 1 || - || cpi, if bc <> 0 and nz then pc -= 2 || Compare and Increment, Repeat
|- style="background:#efefef;"
+
|INC A||4||1||rowspan=10|***V0-||3C||rowspan=10|Increment (8-bit)||rowspan=7|r=r+1
+
|- style="background:#efefef;"
+
|INC B||4||1||04
+
|- style="background:#efefef;"
+
|INC C||4||1||0C
+
|- style="background:#efefef;"
+
|INC D||4||1||14
+
|- style="background:#efefef;"
+
|INC E||4||1||1C
+
|- style="background:#efefef;"
+
|INC H||4||1||24
+
|- style="background:#efefef;"
+
|INC L||4||1||2C
+
 
|-
 
|-
|INC (HL)||11||1||34||(HL)=(HL)+1
+
| cpl || 00101111 || 1 || 4 (4) || - || - || + || 1 || + || - || 1 || - || a := ~a || Complement
|- style="background:#efefef;"
+
|}
|INC (IX+N)||23||3||DD 34 XX||rowspan=2|(xx+d)=(xx+d)+1
+
 
|- style="background:#efefef;"
+
=== Letter D ===
|INC (IY+N)||23||3||FD 34 XX
+
 
|-  
+
{| class="wikitable" style="white-space: nowrap;"
|INC BC||6||1||rowspan=4|------||03||rowspan=4|Increment (16-bit)||rowspan=4|ss=ss+1
+
 
|-
 
|-
|INC DE||6||1||13
+
! Instruction !! Opcode !! NOPs !! Cycles !! S !! Z !! 5 !! H !! 3 !! P !! N !! C !! Effect !! Description
 
|-
 
|-
|INC HL||6||1||23
+
| daa || 00100111 || 1 || 4 (4) || + || + || + || X || + || P || - || X || tmp := a,
 +
if nf then
 +
if hf or [a AND 0x0f > 9] then tmp -= 0x06
 +
if cf or [a > 0x99] then tmp -= 0x60
 +
else
 +
if hf or [a AND 0x0f > 9] then tmp += 0x06
 +
if cf or [a > 0x99] then tmp += 0x60
 +
endif,
 +
 
 +
tmp => flags, cf := cf OR [a > 0x99],
 +
 
 +
hf := a.4 XOR tmp.4, a := tmp
 +
|| Decimal Adjust Accumulator
 
|-
 
|-
|INC SP||6||1||33
+
| dec R || 00rrr101 || 1 || 4 (4) || + || + || + || + || + || V || 1 || - || R -= 1 ||rowspan=6|Decrement
|- style="background:#efefef;"
+
|INC IX||10||2||rowspan=2|------||DD 23||rowspan=2|Increment||rowspan=2|xx=xx+1
+
|- style="background:#efefef;"
+
|INC IY||10||2||FD 23
+
 
|-
 
|-
|IND||16||2||?*??1-||ED AA||Input and Decrement||(HL)=(C),HL=HL-1,B=B-1
+
| dec J || 11i11101 0010b101 || 2 || 8 (4,4) || + || + || + || + || + || V || 1 || - || J -= 1
 
|-
 
|-
|INDR||21/1||2||?1??1-||ED BA||Input, Dec., Repeat||IND till B=0
+
| dec (hl) || 00110101 || 3 || 11 (4,4,3) || + || + || + || + || + || V || 1 || - || (hl) -= 1
 
|-
 
|-
|INI||16||2||?*??1-||ED A2||Input and Increment||(HL)=(C),HL=HL+1,B=B-1
+
| dec (I+D) || 11i11101 00110101 dddddddd || 6 || 23 (4,4,3,5,4,3) || + || + || + || + || + || V || 1 || - || (I+D) -= 1
 
|-
 
|-
|INIR||21/1||2||?1??1-||ED B2||Input, Inc., Repeat||INI till B=0
+
| dec Q || 00qq1011 || 2 || 6 (6) || - || - || - || - || - || - || - || - || Q -= 1
|- style="background:#efefef;"
+
|JP NN||10||3||rowspan=4|------||C3 XX XX||rowspan=4|Unconditional Jump||PC=nn
+
|- style="background:#efefef;"
+
|JP (HL)||4||1||E9||PC=(HL)
+
|- style="background:#efefef;"
+
|JP (IX)||8||2||DD E9||rowspan=2|PC=(xx)
+
|- style="background:#efefef;"
+
|JP (IY)||8||2||FD E9
+
|-  
+
|JP C,$NN||10/1||3||rowspan=8|------||DA XX XX||rowspan=8|Conditional Jump||If Carry = 1
+
 
|-
 
|-
|JP NC,$NN||10/1||3||D2 XX XX||If Carry = 0
+
| dec I || 11i11101 00101011 || 3 || 10 (4,6) || - || - || - || - || - || - || - || - || I -= 1
 
|-
 
|-
|JP M,$NN||10/1||3||FA XX XX||If Sign = 1 (negative)
+
| di || 11110011 || 1 || 4 (4) || - || - || - || - || - || - || - || - || iff1 := 0, iff2 := 0 || Disable Interrupts
 
|-
 
|-
|JP P,$NN||10/1||3||F2 XX XX||If Sign = 0 (positive)
+
| djnz E || 00010000 dddddddd || 4/3 || 13/8 (5,3,5)/(5,3) || - || - || - || - || - || - || - || - || b -= 1, if b <> 0 then pc := E || Decrement, Jump Non-Zero
 +
|}
 +
 
 +
=== Letter E ===
 +
 
 +
{| class="wikitable" style="white-space: nowrap;"
 
|-
 
|-
|JP Z,$NN||10/1||3||CA XX XX||If Zero = 1 (ans.= 0)
+
! Instruction !! Opcode !! NOPs !! Cycles !! S !! Z !! 5 !! H !! 3 !! P !! N !! C !! Effect !! Description
 
|-
 
|-
|JP NZ,$NN||10/1||3||C2 XX XX||If Zero = 0 (non-zero)
+
| ei || 11111011 || 1 || 4 (4) || - || - || - || - || - || - || - || - || iff1 := 1, iff2 := 1 after the next instruction || Enable Interrupts
 
|-
 
|-
|JP PE,$NN||10/1||3||EA XX XX||If Parity = 1 (even)
+
| ex (sp),hl || 11100011 || 6 || 19 (4,3,4,3,5) || - || - || - || - || - || - || - || - || (sp) <=> hl ||rowspan=5|Exchange
 
|-
 
|-
|JP PO,$NN||10/1||3||E2 XX XX||If Parity = 0 (odd)
+
| ex (sp),I || 11i11101 11100011 || 7 || 23 (4,4,3,4,3,5) || - || - || - || - || - || - || - || - || (sp) <=> I
|- style="background:#efefef;"
+
|JR $N+2||12||2||------||18 XX||Relative Jump||PC=PC+e
+
|-  
+
|JR C,$N+2||12/7||2||rowspan=4|------||38 XX||rowspan=4|Cond. Relative Jump||rowspan=4|If cc JR(cc=C,NC,NZ,Z)
+
 
|-
 
|-
|JR NC,$N+2||12/7||2||30 XX
+
| ex af,af' || 00001000 || 1 || 4 (4) || X || X || X || X || X || X || X || X || af <=> af'
 
|-
 
|-
|JR Z,$N+2||12/7||2||28 XX
+
| ex de,hl || 11101011 || 1 || 4 (4) || - || - || - || - || - || - || - || - || de <=> hl
 
|-
 
|-
|JR NZ,$N+2||12/7||2||20 XX
+
| exx || 11011001 || 1 || 4 (4) || - || - || - || - || - || - || - || - || bc, de, hl <=> bc', de', hl'
|- style="background:#efefef;"
+
|}
|LD I,A||9||2||rowspan=2|------||ED 47||rowspan=2|Load*||rowspan=2|dst=src
+
 
|- style="background:#efefef;"
+
=== Letter H ===
|LD R,A||9||2||ED 4F
+
 
|-
+
{| class="wikitable" style="white-space: nowrap;"
|LD A,I||9||2||rowspan=2|**0*0-||ED 57||rowspan=2|Load*||rowspan=2|dst=src
+
 
|-
 
|-
|LD A,R||9||2||ED 5F
+
! Instruction !! Opcode !! NOPs !! Cycles !! S !! Z !! 5 !! H !! 3 !! P !! N !! C !! Effect !! Description
|- style="background:#efefef;"
+
|LD A,r||4||1||rowspan=38|------||78+rb||rowspan=38|Load (8-bit)||rowspan=38|dst=src
+
|- style="background:#efefef;"
+
|LD A,N||7||2||3E XX
+
|- style="background:#efefef;"
+
|LD A,(BC)||7||1||0A
+
|- style="background:#efefef;"
+
|LD A,(DE)||7||1||1A
+
|- style="background:#efefef;"
+
|LD A,(HL)||7||1||7E
+
|- style="background:#efefef;"
+
|LD A,(IX+N)||19||3||DD 7E XX
+
|- style="background:#efefef;"
+
|LD A,(IY+N)||19||3||FD 7E XX
+
|- style="background:#efefef;"
+
|LD A,(NN)||13||3||3A XX XX
+
|- style="background:#efefef;"
+
|LD B,r||4||1||40+rb
+
|- style="background:#efefef;"
+
|LD B,N||7||2||06 XX
+
|- style="background:#efefef;"
+
|LD B,(HL)||7||1||46
+
|- style="background:#efefef;"
+
|LD B,(IX+N)||19||3||DD 46 XX
+
|- style="background:#efefef;"
+
|LD B,(IY+N)||19||3||FD 46 XX
+
|- style="background:#efefef;"
+
|LD C,r||4||1||48+rb
+
|- style="background:#efefef;"
+
|LD C,N||7||2||0E XX
+
|- style="background:#efefef;"
+
|LD C,(HL)||7||1||4E
+
|- style="background:#efefef;"
+
|LD C,(IX+N)||19||3||DD 4E XX
+
|- style="background:#efefef;"
+
|LD C,(IY+N)||19||3||FD 4E XX
+
|- style="background:#efefef;"
+
|LD D,r||4||1||50+rb
+
|- style="background:#efefef;"
+
|LD D,N||7||2||16 XX
+
|- style="background:#efefef;"
+
|LD D,(HL)||7||1||56
+
|- style="background:#efefef;"
+
|LD D,(IX+N)||19||3||DD 56 XX
+
|- style="background:#efefef;"
+
|LD D,(IY+N)||19||3||FD 56 XX
+
|- style="background:#efefef;"
+
|LD E,r||4||1||58+rb
+
|- style="background:#efefef;"
+
|LD E,N||7||2||1E XX
+
|- style="background:#efefef;"
+
|LD E,(HL)||7||1||5E
+
|- style="background:#efefef;"
+
|LD E,(IX+N)||19||3||DD 5E XX
+
|- style="background:#efefef;"
+
|LD E,(IY+N)||19||3||FD 5E XX
+
|- style="background:#efefef;"
+
|LD H,r||4||1||60+rb
+
|- style="background:#efefef;"
+
|LD H,N||7||2||26 XX
+
|- style="background:#efefef;"
+
|LD H,(HL)||7||1||66
+
|- style="background:#efefef;"
+
|LD H,(IX+N)||19||3||DD 66 XX
+
|- style="background:#efefef;"
+
|LD H,(IY+N)||19||3||FD 66 XX
+
|- style="background:#efefef;"
+
|LD L,r||4||1||68+rb
+
|- style="background:#efefef;"
+
|LD L,N||7||2||2E XX
+
|- style="background:#efefef;"
+
|LD L,(HL)||7||1||6E
+
|- style="background:#efefef;"
+
|LD L,(IX+N)||19||3||DD 6E XX
+
|- style="background:#efefef;"
+
|LD L,(IY+N)||19||3||FD 6E XX
+
|-
+
|LD BC,(NN)||20||4||rowspan=15|------||ED 4B XX XX ||rowspan=15|Load (16-bit)||rowspan=15|dst=src
+
|-
+
|LD BC,NN||10||3||01 XX XX
+
|-
+
|LD DE,(NN)||20||4||ED 5B XX XX
+
|-
+
|LD DE,NN||10||3||11 XX XX
+
|-
+
|LD HL,(NN)||20||3||2A XX XX
+
|-
+
|LD HL,NN||10||3||21 XX XX
+
|-
+
|LD SP,(NN)||20||4||ED 7B XX XX
+
|-
+
|LD SP,HL||6||1||F9
+
|-
+
|LD SP,IX||10||2||DD F9
+
|-
+
|LD SP,IY||10||2||FD F9
+
|-
+
|LD SP,NN||10||3||31 XX XX
+
|-
+
|LD IX,(NN)||20||4||DD 2A XX XX
+
|-
+
|LD IX,NN||14||4||DD 21 XX XX
+
|-
+
|LD IY,(NN)||20||4||FD 2A XX XX
+
|-
+
|LD IY,NN||14||4||FD 21 XX XX
+
|-
+
|LD (HL),r||7||1||rowspan=15|------||70+rb||rowspan=15|Load (Indirect)||rowspan=15|dst=src
+
 
|-
 
|-
|LD (HL),N||10||2||36 XX
+
| halt || 01110110 || 1 || 4 (4) || - || - || - || - || - || - || - || - || wait for interrupt || Suspends CPU operation
 +
|}
 +
 
 +
=== Letter I ===
 +
 
 +
{| class="wikitable" style="white-space: nowrap;"
 
|-
 
|-
|LD (BC),A||7||1||02
+
! Instruction !! Opcode !! NOPs !! Cycles !! S !! Z !! 5 !! H !! 3 !! P !! N !! C !! Effect !! Description
 
|-
 
|-
|LD (DE),A||7||1||12
+
| im 0 || 11101101 01*0*110 || 2 || 8 (4,4) || - || - || - || - || - || - || - || - || mode 0: execute instruction on bus ||rowspan=3|Set Interrupt Mode
 
|-
 
|-
|LD (NN),A||13||3||32 XX XX
+
| im 1 || 11101101 01*10110 || 2 || 8 (4,4) || - || - || - || - || - || - || - || - || mode 1: execute rst 38h
 
|-
 
|-
|LD (NN),BC||20||4||ED 43 XX XX
+
| im 2 || 11101101 01*11110 || 2 || 8 (4,4) || - || - || - || - || - || - || - || - || mode 2: call (i * 256 + byte on bus)
 
|-
 
|-
|LD (NN),DE||20||4||ED 53 XX XX
+
| in a,(N) || 11011011 nnnnnnnn || 3 || 11 (4,3,4) || - || - || - || - || - || - || - || - || a := ((N)) ||rowspan=3|I/O Input
 
|-
 
|-
|LD (NN),HL||16||3||22 XX XX
+
| in R,(c) || 11101101 01rrr000 || 4 || 12 (4,4,4) || + || + || + || 0 || + || P || 0 || - || R := ((c))
 
|-
 
|-
|LD (NN),IX||20||4||DD 22 XX XX
+
| in f,(c) || 11101101 01110000 || 4 || 12 (4,4,4) || + || + || + || 0 || + || P || 0 || - || tmp := ((c))
 
|-
 
|-
|LD (NN),IY||20||4||FD 22 XX XX
+
| inc R || 00rrr100 || 1 || 4 (4) || + || + || + || + || + || V || 0 || - || R += 1 ||rowspan=6|Increment
 
|-
 
|-
|LD (NN),SP||20||4||ED 73 XX XX
+
| inc J || 11i11101 0010b100 || 2 || 8 (4,4) || + || + || + || + || + || V || 0 || - || J += 1
 
|-
 
|-
|LD (IX+N),r||19||3||DD 70+rb XX
+
| inc (hl) || 00110100 || 3 || 11 (4,4,3) || + || + || + || + || + || V || 0 || - || (hl) += 1
 
|-
 
|-
|LD (IX+N),N||19||4||DD 36 XX XX
+
| inc (I+D) || 11i11101 00110100 dddddddd || 6 || 23 (4,4,3,5,4,3) || + || + || + || + || + || V || 0 || - || (I+D) += 1
 
|-
 
|-
|LD (IY+N),r||19||3||FD 70+rb XX
+
| inc Q || 00qq0011 || 2 || 6 (6) || - || - || - || - || - || - || - || - || Q += 1
 
|-
 
|-
|LD (IY+N),N||19||4||FD 36 XX XX
+
| inc I || 11i11101 00100011 || 3 || 10 (4,6) || - || - || - || - || - || - || - || - || I += 1
 
|-
 
|-
|LDD||16||2||--0*0-||ED A8||Load and Decrement||(DE)=(HL),HL=HL-1,#
+
| ind || 11101101 10101010 || 5 || 16 (4,5,3,4) || + || + || + || X || + || X || X || X || tmp := ((c)), (hl) := tmp, hl -= 1,
 +
b -= 1 => flags, nf := tmp.7,
 +
 
 +
tmp2 = tmp + [[c - 1] AND 0xff],
 +
 
 +
pf := parity of [[tmp2 AND 0x07] XOR b],
 +
 
 +
hf := cf := tmp2 > 255
 +
|| I/O Input and Decrement
 
|-
 
|-
|LDDR||21/1||2||--000-||ED B8||Load, Dec., Repeat||LDD till BC=0
+
| indr || 11101101 10111010 || 6/5 || 21/16 (4,5,3,4,5)/(4,5,3,4) || + || + || + || X || + || X || X || X || ind, if b <> 0 then pc -= 2 || I/O Input and Decrement, Repeat
 
|-
 
|-
|LDI||16||2||--0*0-||ED A0||Load and Increment||(DE)=(HL),HL=HL+1,#
+
| ini || 11101101 10100010 || 5 || 16 (4,5,3,4) || + || + || + || X || + || X || X || X || tmp := ((c)), (hl) := tmp, hl += 1,
 +
b -= 1 => flags, nf := tmp.7,
 +
 
 +
tmp2 := tmp + [[c + 1] AND 0xff],
 +
 
 +
pf := parity of [[tmp2 AND 0x07] XOR b],
 +
 
 +
hf := cf := tmp2 > 255
 +
|| I/O Input and Increment
 
|-
 
|-
|LDIR||21/1||2||--000-||ED B0||Load, Inc., Repeat||LDI till BC=0
+
| inir || 11101101 10110010 || 6/5 || 21/16 (4,5,3,4,5)/(4,5,3,4) || + || + || + || X || + || X || X || X || ini, if b <> 0 then pc -= 2 || I/O Input and Increment, Repeat
 +
|}
 +
 
 +
=== Letter J ===
 +
 
 +
{| class="wikitable" style="white-space: nowrap;"
 
|-
 
|-
|NEG||8||2||***V1*||ED 44||Negate||A=-A
+
! Instruction !! Opcode !! NOPs|| Cycles !! S !! Z !! 5 !! H !! 3 !! P !! N !! C !! Effect !! Description
 
|-
 
|-
|NOP||4||1||------||00||No Operation||
+
| jp A || 11000011 alalalal ahahahah || 3 || 10 (4,3,3) || - || - || - || - || - || - || - || - || pc := A ||rowspan=3|Jump
 
|-
 
|-
|OR r||4||1||rowspan=5|***P00||B0+rb||rowspan=5|Logical inclusive OR||rowspan=5|A=Avs
+
| jp (hl) || 11101001 || 1 || 4 (4) || - || - || - || - || - || - || - || - || pc := hl
 
|-
 
|-
|OR N||7||2||F6 XX
+
| jp (I) || 11i11101 11101001 || 2 || 8 (4,4) || - || - || - || - || - || - || - || - || pc := I
 
|-
 
|-
|OR (HL)||7||1||B6
+
| jp C,A || 11ccc010 alalalal ahahahah || 3 || 10 (4,3,3) || - || - || - || - || - || - || - || - || if C then pc := A || Conditional Jump
 
|-
 
|-
|OR (IX+N)||19||3||DD B6 XX
+
| jr E || 00011000 dddddddd || 3 || 12 (4,3,5) || - || - || - || - || - || - || - || - || pc := E || Relative Jump
 
|-
 
|-
|OR (IY+N)||19||3||FD B6 XX
+
| jr nz,E || 00100000 dddddddd || 3/2 || 12/7 (4,3,5)/(4,3) || - || - || - || - || - || - || - || - || if nz then pc := E ||rowspan=4|Conditional Relative Jump
 
|-
 
|-
|OUT (N),A||11||2||rowspan=9|------||D3 XX||Output||(n)=A
+
| jr z,E || 00101000 dddddddd || 3/2 || 12/7 (4,3,5)/(4,3) || - || - || - || - || - || - || - || - || if zf then pc := E
 
|-
 
|-
|OUT (C),0||12||2||ED 71||Output*||(Unsupported)
+
| jr nc,E || 00110000 dddddddd || 3/2 || 12/7 (4,3,5)/(4,3) || - || - || - || - || - || - || - || - || if nc then pc := E
 
|-
 
|-
|OUT (C),A||12||2||ED 79||rowspan=7|Output||rowspan=7|(C)=r
+
| jr c,E || 00111000 dddddddd || 3/2 || 12/7 (4,3,5)/(4,3) || - || - || - || - || - || - || - || - || if cf then pc := E
 +
|}
 +
 
 +
=== Letter L ===
 +
 
 +
{| class="wikitable" style="white-space: nowrap;"
 
|-
 
|-
|OUT (C),B||12||2||ED 41
+
! Instruction !! Opcode !! NOPs !! Cycles !! S !! Z !! 5 !! H !! 3 !! P !! N !! C !! Effect !! Description
 
|-
 
|-
|OUT (C),C||12||2||ED 49
+
| ld R1,R2 || 01rrrsss || 1 || 4 (4) || - || - || - || - || - || - || - || - || R1 := R2 ||rowspan=34|Load
 
|-
 
|-
|OUT (C),D||12||2||ED 51
+
| ld R,J || 11i11101 01rrr10b || 2 || 8 (4,4) || - || - || - || - || - || - || - || - || R := J
 
|-
 
|-
|OUT (C),E||12||2||ED 59
+
| ld J,R || 11i11101 0110brrr || 2 || 8 (4,4) || - || - || - || - || - || - || - || - || J := R
 
|-
 
|-
|OUT (C),H||12||2||ED 61
+
| ld ixh,ixl || 11011101 01100101 || 2 || 8 (4,4) || - || - || - || - || - || - || - || - || ixh := ixl
 
|-
 
|-
|OUT (C),L||12||2||ED 69
+
| ld ixl,ixh || 11011101 01101100 || 2 || 8 (4,4) || - || - || - || - || - || - || - || - || ixl := ixh
 
|-
 
|-
|OUTD||16||2||?*??1-||ED AB||Output and Decrement||(C)=(HL),HL=HL-1,B=B-1
+
| ld iyh,iyl || 11111101 01100101 || 2 || 8 (4,4) || - || - || - || - || - || - || - || - || iyh := iyl
 
|-
 
|-
|OTDR||21/1||2||?1??1-||ED BB||Output, Dec., Repeat||OUTD till B=0
+
| ld iyl,iyh || 11111101 01101100 || 2 || 8 (4,4) || - || - || - || - || - || - || - || - || iyl := iyh
 
|-
 
|-
|OUTI||16||2||?*??1-||ED A3||Output and Increment||(C)=(HL),HL=HL+1,B=B-1
+
| ld R,N || 00rrr110 nnnnnnnn || 2 || 7 (4,3) || - || - || - || - || - || - || - || - || R := N
 
|-
 
|-
|OTIR||21/1||2||?1??1-||ED B3||Output, Inc., Repeat||OUTI till B=0
+
| ld R,(hl) || 01rrr110 || 2 || 7 (4,3) || - || - || - || - || - || - || - || - || R := (hl)
 
|-
 
|-
|POP AF||10||1||rowspan=4|------||F1||rowspan=4|Pop||rowspan=4|qq=(SP)+
+
| ld R,(I+D) || 11i11101 01rrr110 dddddddd || 5 || 19 (4,4,3,5,3) || - || - || - || - || - || - || - || - || R := (I+D)
 
|-
 
|-
|POP BC||10||1||C1
+
| ld (hl),R || 01110rrr || 2 || 7 (4,3) || - || - || - || - || - || - || - || - || (hl) := R
 
|-
 
|-
|POP DE||10||1||D1
+
| ld (hl),N || 00110110 nnnnnnnn || 3 || 10 (4,3,3) || - || - || - || - || - || - || - || - || (hl) := N
 
|-
 
|-
|POP HL||10||1||E1
+
| ld (I+D),R || 11i11101 01110rrr dddddddd || 5 || 19 (4,4,3,5,3) || - || - || - || - || - || - || - || - || (I+D) := R
 
|-
 
|-
|POP IX||14||2||rowspan=2|------||DD E1||rowspan=2|Pop||rowspan=2|xx=(SP)+
+
| ld (I+D),N || 11i11101 00110110 dddddddd nnnnnnnn || 6 || 19 (4,4,3,5,3) || - || - || - || - || - || - || - || - || (I+D) := N
 
|-
 
|-
|POP IY||14||2||FD E1
+
| ld a,(bc) || 00001010 || 2 || 7 (4,3) || - || - || - || - || - || - || - || - || a := (bc)
 
|-
 
|-
|PUSH AF||11||1||rowspan=4|------||F5||rowspan=4|Push||rowspan=4|(SP)=qq
+
| ld a,(de) || 00011010 || 2 || 7 (4,3) || - || - || - || - || - || - || - || - || a := (de)
 
|-
 
|-
|PUSH BC||11||1||C5
+
| ld a,(A) || 00111010 alalalal ahahahah || 4 || 13 (4,3,3,3) || - || - || - || - || - || - || - || - || a := (A)
 
|-
 
|-
|PUSH DE||11||1||D5
+
| ld (bc),a || 00000010 || 2 || 7 (4,3) || - || - || - || - || - || - || - || - || (bc) := a
 
|-
 
|-
|PUSH HL||11||1||E5
+
| ld (de),a || 00010010 || 2 || 7 (4,3) || - || - || - || - || - || - || - || - || (de) := a
 
|-
 
|-
|PUSH IX||15||2||rowspan=2|------||DD E5||rowspan=2|Push||rowspan=2|-(SP)=xx
+
| ld (A),a || 00110010 alalalal ahahahah || 4 || 13 (4,3,3,3) || - || - || - || - || - || - || - || - || (A) := a
 
|-
 
|-
|PUSH IY||15||2||FD E5|
+
| ld i,a || 11101101 01000111 || 3 || 9 (4,5) || - || - || - || - || - || - || - || - || i := a
 
|-
 
|-
|RES b,r||8||2||rowspan=4|------||CB 80+8*b+rb||rowspan=4|Reset bit||rowspan=4|m=m&{~2^b}
+
| ld r,a || 11101101 01001111 || 3 || 9 (4,5) || - || - || - || - || - || - || - || - || r := a
 
|-
 
|-
|RES b,(HL)||15||2||CB 86+8*b
+
| ld a,i || 11101101 01010111 || 3 || 9 (4,5) || + || + || + || 0 || + || X || 0 || - || a := i, pf := iff2
 
|-
 
|-
|RES b,(IX+N)||23||4||DD CB XX 86+8*b
+
| ld a,r || 11101101 01011111 || 3 || 9 (4,5) || + || + || + || 0 || + || X || 0 || - || a := r, pf := iff2
 
|-
 
|-
|RES b,(IY+N)||23||4||FD CB XX 86+8*b
+
| ld Q,A || 00qq0001 alalalal ahahahah || 3 || 10 (4,3,3) || - || - || - || - || - || - || - || - || Q := A
 
|-
 
|-
|RET||10||1||rowspan=9|------||C9||Return||PC=(SP)+
+
| ld I,A || 11i11101 00100001 alalalal ahahahah || 4 || 14 (4,4,3,3) || - || - || - || - || - || - || - || - || I := A
 
|-
 
|-
|RET C||11/5||1||D8||rowspan=8|Conditional Return||If Carry = 1
+
| ld Q,(A) || 11101101 01qq1011 alalalal ahahahah || 6 || 20 (4,4,3,3,3,3) || - || - || - || - || - || - || - || - || Q := (A)
 
|-
 
|-
|RET NC||11/5||1||D0||If Carry = 0
+
| ld hl,(A) || 00101010 alalalal ahahahah || 5 || 16 (4,3,3,3,3) || - || - || - || - || - || - || - || - || hl := (A)
 
|-
 
|-
|RET M||11/5||1||F8||If Sign = 1 (negative)
+
| ld I,(A) || 11i11101 00101010 alalalal ahahahah || 6 || 20 (4,4,3,3,3,3) || - || - || - || - || - || - || - || - || I := (A)
 
|-
 
|-
|RET P||11/5||1||F0||If Sign = 0 (positive)
+
| ld (A),Q || 11101101 01qq0011 alalalal ahahahah || 6 || 20 (4,4,3,3,3,3) || - || - || - || - || - || - || - || - || (A) := Q
 
|-
 
|-
|RET Z||11/5||1||C8||If Zero = 1 (ans.=0)
+
| ld (A),hl || 00100010 alalalal ahahahah || 5 || 16 (4,3,3,3,3) || - || - || - || - || - || - || - || - || (A) := hl
 
|-
 
|-
|RET NZ||11/5||1||C0||If Zero = 0 (non-zero)
+
| ld (A),I || 11i11101 00100010 alalalal ahahahah || 6 || 20 (4,4,3,3,3,3) || - || - || - || - || - || - || - || - || (A) := I
 
|-
 
|-
|RET PE||11/5||1||E8||If Parity = 1 (even)
+
| ld sp,hl || 11111001 || 2 || 6 (6) || - || - || - || - || - || - || - || - || sp := hl
 
|-
 
|-
|RET PO||11/5||1||E0||If Parity = 0 (odd)
+
| ld sp,I || 11i11101 11111001 || 3 || 10 (4,6) || - || - || - || - || - || - || - || - || sp := I
 
|-
 
|-
|RET||10||1||------||C9||Return||PC=(SP)+
+
| ldd || 11101101 10101000 || 5 || 16 (4,4,3,5) || - || - || X || 0 || X || C || 0 || - || tmp := (hl), (de) := tmp, de -= 1, hl -= 1,
 +
bc -= 1, f5 := [tmp + a].1, f3 := [tmp + a].3
 +
|| Load and Decrement
 
|-
 
|-
|RET C||11/5||1||rowspan=8|------||D8||rowspan=8|Conditional Return||If Carry = 1
+
| lddr || 11101101 10111000 || 6/5 || 21/16 (4,4,3,5,5)/(4,4,3,5) || - || - || X || 0 || X || C || 0 || - || ldd, if bc <> 0 then pc -= 2 || Load and Decrement, Repeat
 
|-
 
|-
|RET NC||11/5||1||D0||If Carry = 0
+
| ldi || 11101101 10100000 || 5 || 16 (4,4,3,5) || - || - || X || 0 || X || C || 0 || - || tmp := (hl), (de) := tmp, de += 1, hl += 1,
 +
bc -= 1, f5 := [tmp + a].1, f3 := [tmp + a].3
 +
|| Load and Increment
 
|-
 
|-
|RET M||11/5||1||F8||If Sign = 1 (negative)
+
| ldir || 11101101 10110000 || 6/5 || 21/16 (4,4,3,5,5)/(4,4,3,5) || - || - || X || 0 || X || C || 0 || - || ldi, if bc <> 0 then pc -= 2 || Load and Increment, Repeat
 +
|}
 +
 
 +
=== Letter N ===
 +
 
 +
{| class="wikitable" style="white-space: nowrap;"
 
|-
 
|-
|RET P||11/5||1||F0||If Sign = 0 (positive)
+
! Instruction !! Opcode !! NOPs !! Cycles !! S !! Z !! 5 !! H !! 3 !! P !! N !! C !! Effect !! Description
 
|-
 
|-
|RET Z||11/5||1||C8||If Zero = 1 (ans.=0)
+
| neg || 11101101 01***100 || 2 || 8 (4,4) || + || + || + || + || + || V || 1 || + || a := 0 - a || Negate
 
|-
 
|-
|RET NZ||11/5||1||C0||If Zero = 0 (non-zero)
+
| nop || 00000000 || 1 || 4 (4) || - || - || - || - || - || - || - || - || nothing ||No Operation
 +
|}
 +
 
 +
=== Letter O ===
 +
 
 +
{| class="wikitable" style="white-space: nowrap;"
 
|-
 
|-
|RET PE||11/5||1||E8||If Parity = 1 (even)
+
! Instruction !! Opcode !! NOPs !! Cycles !! S !! Z !! 5 !! H !! 3 !! P !! N !! C !! Effect !! Description
 
|-
 
|-
|RET PO||11/5||1||E0||If Parity = 0 (odd)
+
| or R || 10110rrr || 1 || 4 (4) || + || + || + || 0 || + || P || 0 || 0 || a := a OR R ||rowspan=5|Logical Inclusive OR
 
|-
 
|-
|RETI||14||2||------||ED 4D||Return from Interrupt||PC=(SP)+
+
| or J || 11i11101 1011010b || 2 || 8 (4,4) || + || + || + || 0 || + || P || 0 || 0 || a := a OR J
 
|-
 
|-
|RETN||14||2||------||ED 45||Return from NMI||PC=(SP)+
+
| or N || 11110110 nnnnnnnn || 2 || 7 (4,3) || + || + || + || 0 || + || P || 0 || 0 || a := a OR N
 
|-
 
|-
|RLA||4||1||--0-0*||17||Rotate Left Acc.||A={CY,A}<-
+
| or (hl) || 10110110 || 2 || 7 (4,3) || + || + || + || 0 || + || P || 0 || 0 || a := a OR (hl)
 
|-
 
|-
|RL r||8||2||rowspan=4|**0P0*||CB 10+rb||rowspan=4|Rotate Left||rowspan=4|m={CY,m}<-
+
| or (I+D) || 11i11101 10110110 dddddddd || 5 || 19 (4,4,3,5,3) || + || + || + || 0 || + || P || 0 || 0 || a := a OR (I+D)
 
|-
 
|-
|RL (HL)||15||2||CB 16
+
| out (N),a || 11010011 nnnnnnnn || 3 || 11 (4,3,4) || - || - || - || - || - || - || - || - || ((N)) := a ||rowspan=3| I/O Output
 
|-
 
|-
|RL (IX+N)||23||4||DD CB XX 16
+
| out (c),R || 11101101 01rrr001 || 4 || 12 (4,4,4) || - || - || - || - || - || - || - || - || ((c)) := R
 
|-
 
|-
|RL (IY+N)||23||4||FD CB XX 16
+
| out (c),0 || 11101101 01110001 || 4 || 12 (4,4,4) || - || - || - || - || - || - || - || - || ((c)) := 0 (255 on CMOS CPU)
 
|-
 
|-
|RLCA||4||1||--0-0*||07||Rotate Left Cir. Acc.||A=A<-
+
| outd || 11101101 10101011 || 5 || 16 (4,5,3,4) || + || + || + || X || + || X || X || X || tmp := (hl), ((c)) := tmp, hl -= 1,
 +
b -= 1 => flags, nf := tmp.7, tmp2 = tmp + l,
 +
 
 +
pf := parity of [[tmp2 AND 0x07] XOR b],
 +
 
 +
hf := cf := tmp2 > 255
 +
|| I/O Output and Decrement
 
|-
 
|-
|RLC r||8||2||rowspan=4|**0P0*||CB 00+rb||rowspan=4|Rotate Left Circular||rowspan=4|m=m<-
+
| otdr || 11101101 10111011 || 6/5 || 21/16 (4,5,3,4,5)/(4,5,3,4) || + || + || + || X || + || X || X || X || outd, if b <> 0 then pc -= 2 || I/O Output and Decrement, Repeat
 
|-
 
|-
|RLC (HL)||15||2||CB 06
+
| outi || 11101101 10100011 || 5 || 16 (4,5,3,4) || + || + || + || X || + || X || X || X || tmp := (hl), ((c)) := tmp, hl += 1,
 +
b -= 1 => flags, nf := tmp.7, tmp2 = tmp + l,
 +
 
 +
pf := parity of [[tmp2 AND 0x07] XOR b],
 +
 
 +
hf := cf := tmp2 > 255
 +
|| I/O Output and Increment
 
|-
 
|-
|RLC (IX+N)||23||4||DD CB XX 06
+
| otir || 11101101 10110011 || 6/5 || 21/16 (4,5,3,4,5)/(4,5,3,4) || + || + || + || X || + || X || X || X || outi, if b <> 0 then pc -= 2 || I/O Output and Increment, Repeat
 +
|}
 +
 
 +
=== Letter P ===
 +
 
 +
{| class="wikitable" style="white-space: nowrap;"
 
|-
 
|-
|RLC (IY+N)||23||4||FD CB XX 06
+
! Instruction !! Opcode !! NOPs !! Cycles !! S !! Z !! 5 !! H !! 3 !! P !! N !! C !! Effect !! Description
 
|-
 
|-
|RLD||18||2||**0P0-||ED 6F||Rotate Left 4 bits||{A,(HL)}={A,(HL)}<- ##
+
| pop P || 11pp0001 || 3 || 10 (4,3,3) || - || - || - || - || - || - || - || - || P := (sp), sp += 2 ||rowspan=2|Pop a value from the stack
 
|-
 
|-
|RRA||4||1||--0-0*||1F||Rotate Right Acc.||A=->{CY,A}
+
| pop I || 11i11101 11100001 || 4 || 14 (4,4,3,3) || - || - || - || - || - || - || - || - || I := (sp), sp += 2
 
|-
 
|-
|RR r||8 ||2||rowspan=4|**0P0*||CB 18+rb||rowspan=4|Rotate Right||rowspan=4|m=->{CY,m}
+
| push P || 11pp0101 || 4 || 11 (5,3,3) || - || - || - || - || - || - || - || - || sp -= 2, (sp) := P ||rowspan=2|Push a value onto the stack
 
|-
 
|-
|RR (HL)||15||2||CB 1E
+
| push I || 11i11101 11100101 || 5 || 15 (4,5,3,3) || - || - || - || - || - || - || - || - || sp -= 2, (sp) := I
 +
|}
 +
 
 +
=== Letter R ===
 +
 
 +
{| class="wikitable" style="white-space: nowrap;"
 
|-
 
|-
|RR (IX+N)||23||4||DD CB XX 1E
+
! Instruction !! Opcode !! NOPs !! Cycles !! S !! Z !! 5 !! H !! 3 !! P !! N !! C !! Effect !! Description
 
|-
 
|-
|RR (IY+N)||23||4||FD CB XX 1E
+
| res B,R || 11001011 10bbbrrr || 2 || 8 (4,4) || - || - || - || - || - || - || - || - || R := R AND ~[1 << B] ||rowspan=4|Reset Bit
 
|-
 
|-
|RRCA||4||1||--0-0*||0F||Rotate Right Cir.Acc.||A=->A
+
| res B,(hl) || 11001011 10bbb110 || 4 || 15 (4,4,4,3) || - || - || - || - || - || - || - || - || (hl) := (hl) AND ~[1 << B]
 
|-
 
|-
|RRC r||8||2||rowspan=4|**0P0*||CB 08+rb||rowspan=4|Rotate Right Circular||rowspan=4|m=->m
+
| res B,(I+D) || 11i11101 11001011 dddddddd 10bbb110 || 7 || 23 (4,4,3,5,4,3) || - || - || - || - || - || - || - || - || (I+D) := (I+D) AND ~[1 << B]
 
|-
 
|-
|RRC (HL)||15||2||CB 0E
+
| res B,(I+D)->R || 11i11101 11001011 dddddddd 10bbbrrr || 7 || 23 (4,4,3,5,4,3) || - || - || - || - || - || - || - || - || (I+D) := R := (I+D) AND ~[1 << B]
 
|-
 
|-
|RRC (IX+N)||23||4||DD CB XX 0E
+
| ret || 11001001 || 3 || 10 (4,3,3) || - || - || - || - || - || - || - || - || pc := (sp), sp += 2 || Return
 
|-
 
|-
|RRC (IY+N)||23||4||FD CB XX 0E
+
| ret C || 11ccc000 || 4/2 || 11/5 (5,3,3)/(5)|| - || - || - || - || - || - || - || - || if C then pc := (sp), sp += 2 || Conditional Return
 
|-
 
|-
|RRD||18||2||**0P0-||ED 67||Rotate Right 4 bits||{A,(HL)}=->{A,(HL)} ##
+
| reti || 11101101 01001101 || 4 || 14 (4,4,3,3) || - || - || - || - || - || - || - || - || pc := (sp), sp += 2, iff1 := iff2 || Return from Interrupt
 
|-
 
|-
|RST 0||11||1||rowspan=8|------||C7||rowspan=8|Restart||rowspan=8|(p=0H,8H,10H,...,38H)
+
| retn || 11101101 01***101 || 4 || 14 (4,4,3,3) || - || - || - || - || - || - || - || - || pc := (sp), sp += 2, iff1 := iff2 || Return from NMI
 
|-
 
|-
|RST 08H||11||1||CF
+
| rla || 00010111 || 1 || 4 (4) || - || - || + || 0 || + || - || 0 || X || ocf := cf, cf := a.7, a := [a << 1] + ocf || Rotate Left Accumulator
 
|-
 
|-
|RST 10H||11||1||D7
+
| rl R || 11001011 00010rrr || 2 || 8 (4,4) || + || + || + || 0 || + || P || 0 || X || ocf := cf, cf := R.7, R := [R << 1] + ocf ||rowspan=4|Rotate Left
 
|-
 
|-
|RST 18H||11||1||DF
+
| rl (hl) || 11001011 00010110 || 4 || 15 (4,4,4,3) || + || + || + || 0 || + || P || 0 || X || ocf := cf, cf := (hl).7, (hl) := [(hl) << 1] + ocf
 
|-
 
|-
|RST 20H||11||1||E7
+
| rl (I+D) || 11i11101 11001011 dddddddd 00010110 || 7 || 23 (4,4,3,5,4,3) || + || + || + || 0 || + || P || 0 || X || ocf := cf, cf := (I+D).7, (I+D) := [(I+D) << 1] + ocf
 
|-
 
|-
|RST 28H||11||1||EF
+
| rl (I+D)->R || 11i11101 11001011 dddddddd 00010rrr || 7 || 23 (4,4,3,5,4,3) || + || + || + || 0 || + || P || 0 || X || ocf := cf, cf := (I+D).7, (I+D) := R := [(I+D) << 1] + ocf
 
|-
 
|-
|RST 30H||11||1||F7
+
| rlca || 00000111 || 1 || 4 (4) || - || - || + || 0 || + || - || 0 || X || cf := a.7, a := [a << 1] + cf || Rotate Left Carry Accumulator
 
|-
 
|-
|RST 38H||11||1||FF
+
| rlc R || 11001011 00000rrr || 2 || 8 (4,4) || + || + || + || 0 || + || P || 0 || X || cf := R.7, R := [R << 1] + cf ||rowspan=4|Rotate Left Carry
 
|-
 
|-
|SBC r||4||1||rowspan=5|***V1*||98+rb|| rowspan=5|Subtract with Carry|| rowspan=5|A=A-s-CY
+
| rlc (hl) || 11001011 00000110 || 4 || 15 (4,4,4,3) || + || + || + || 0 || + || P || 0 || X || cf := (hl).7, (hl) := [(hl) << 1] + cf
 
|-
 
|-
|SBC A,N||7||2||DE XX
+
| rlc (I+D) || 11i11101 11001011 dddddddd 00000110 || 7 || 23 (4,4,3,5,4,3) || + || + || + || 0 || + || P || 0 || X || cf := (I+D).7, (I+D) := [(I+D) << 1] + cf
 
|-
 
|-
|SBC (HL)||7||1||9E
+
| rlc (I+D)->R || 11i11101 11001011 dddddddd 00000rrr || 7 || 23 (4,4,3,5,4,3) || + || + || + || 0 || + || P || 0 || X || cf := (I+D).7, (I+D) := R := [(I+D) << 1] + cf
 
|-
 
|-
|SBC A,(IX+N)||19||3||DD 9E XX
+
| rld || 11101101 01101111 || 5 || 18 (4,4,3,4,3) || + || + || + || 0 || + || P || 0 || - || tmp := [(hl) << 4] + [a AND 0x0f], (hl) := tmp,
 +
a := [a AND 0xf0] + [tmp >> 8] => flags
 +
|| Rotate Left Decimal
 
|-
 
|-
|SBC A,(IY+N)||19||3||FD 9E XX
+
| rra || 00011111 || 1 || 4 (4) || - || - || + || 0 || + || - || 0 || X || ocf := cf, cf := a.0, a := [a >> 1] + [ocf << 7] || Rotate Right Accumulator
 
|-
 
|-
|SBC HL,BC||15||2||rowspan=4|**?V1*||ED 42||rowspan=4|Subtract with Carry||rowspan=4|HL=HL-ss-CY
+
| rr R || 11001011 00011rrr || 2 || 8 (4,4) || + || + || + || 0 || + || P || 0 || X || ocf := cf, cf := R.0, R := [R >> 1] + [ocf << 7] ||rowspan=4|Rotate Right
 
|-
 
|-
|SBC HL,DE||15||2||ED 52
+
| rr (hl) || 11001011 00011110 || 4 || 15 (4,4,4,3) || + || + || + || 0 || + || P || 0 || X || ocf := cf, cf := (hl).0, (hl) := [(hl) >> 1] + [ocf << 7]
 
|-
 
|-
|SBC HL,HL||15||2||ED 62
+
| rr (I+D) || 11i11101 11001011 dddddddd 00011110 || 7 || 23 (4,4,3,5,4,3) || + || + || + || 0 || + || P || 0 || X || ocf := cf, cf := (I+D).0, (I+D) := [(I+D) >> 1] + [ocf << 7]
 
|-
 
|-
|SBC HL,SP||15||2||ED 72
+
| rr (I+D)->R || 11i11101 11001011 dddddddd 00011rrr || 7 || 23 (4,4,3,5,4,3) || + || + || + || 0 || + || P || 0 || X || ocf := cf, cf := (I+D).0, (I+D) := R := [(I+D) >> 1] + [ocf << 7]
 
|-
 
|-
|SCF||4||1||--0-01||37||Set Carry Flag||CY=1
+
| rrca || 00001111 || 1 || 4 (4) || - || - || + || 0 || + || - || 0 || X || cf := a.0, a := [a >> 1] + [cf << 7] || Rotate Right Carry Accumulator
 
|-
 
|-
|SET b,r||8||2||rowspan=4|------||CB C0+8*b+rb||rowspan=4|Set bit||rowspan=4|m=mv{2^b}
+
| rrc R || 11001011 00001rrr || 2 || 8 (4,4) || + || + || + || 0 || + || P || 0 || X || cf := R.0, R := [R >> 1] + [cf << 7] ||rowspan=4|Rotate Right Carry
 
|-
 
|-
|SET b,(HL)||15||2||CB C6+8*b
+
| rrc (hl) || 11001011 00001110 || 4 || 15 (4,4,4,3) || + || + || + || 0 || + || P || 0 || X || cf := (hl).0, (hl) := [(hl) >> 1] + [cf << 7]
 
|-
 
|-
|SET b,(IX+N)||23||4||DD CB XX C6+8*b
+
| rrc (I+D) || 11i11101 11001011 dddddddd 00001110 || 7 || 23 (4,4,3,5,4,3) || + || + || + || 0 || + || P || 0 || X || cf := (I+D).0, (I+D) := [(I+D) >> 1] + [cf << 7]
 
|-
 
|-
|SET b,(IY+N)||23||4||FD CB XX C6+8*b
+
| rrc (I+D)->R || 11i11101 11001011 dddddddd 00001rrr || 7 || 23 (4,4,3,5,4,3) || + || + || + || 0 || + || P || 0 || X || cf := (I+D).0, (I+D) := R := [(I+D) >> 1] + [cf << 7]
 
|-
 
|-
|SLA r||8||2||rowspan=4|**0P0*||CB 20+rb||rowspan=4|Shift Left Arithmetic||rowspan=4|m=m*2
+
| rrd || 11101101 01100111 || 5 || 18 (4,4,3,4,3) || + || + || + || 0 || + || P || 0 || - || tmp := (hl), (hl) := [tmp >> 4] + [[a AND 0x0f] << 4],
 +
a := [a AND 0xf0] + [tmp AND 0x0f] => flags
 +
|| Rotate Right Decimal
 
|-
 
|-
|SLA (HL)||15||2||CB 26
+
| rst S || 11sss111 || 4 || 11 (5,3,3) || - || - || - || - || - || - || - || - || sp -= 2, (sp) := pc, pc := S || Restart
 +
|}
 +
 
 +
=== Letter S ===
 +
 
 +
{| class="wikitable" style="white-space: nowrap;"
 +
! Instruction !! Opcode !! NOPs !! Cycles !! S !! Z !! 5 !! H !! 3 !! P !! N !! C !! Effect !! Description
 
|-
 
|-
|SLA (IX+N)||23||4||DD CB XX 26
+
| sbc a,R || 10011rrr || 1 || 4 (4) || + || + || + || + || + || V || 1 || + || a -= R + cf ||rowspan=6|Subtract with Carry
 
|-
 
|-
|SLA (IY+N)||23||4||FD CB XX 26
+
| sbc a,J || 11i11101 1001110b || 2 || 8 (4,4) || + || + || + || + || + || V || 1 || + || a -= J + cf
 
|-
 
|-
|SRA r||8||2||rowspan=4|**0P0*||CB 28+rb||rowspan=4|Shift Right Arith.||rowspan=4|m=m/2
+
| sbc a,N || 11011110 nnnnnnnn || 2 || 7 (4,3) || + || + || + || + || + || V || 1 || + || a -= N + cf
 
|-
 
|-
|SRA (HL)||15||2||CB 2E
+
| sbc a,(hl) || 10011110 || 2 || 7 (4,3) || + || + || + || + || + || V || 1 || + || a -= (hl) + cf
 
|-
 
|-
|SRA (IX+N)||23||4||DD CB XX 2E
+
| sbc a,(I+D) || 11i11101 10011110 dddddddd || 5 || 19 (4,4,3,5,3) || + || + || + || + || + || V || 1 || + || a -= (I+D) + cf
 
|-
 
|-
|SRA (IY+N)||23||4||FD CB XX 2E
+
| sbc hl,Q || 11101101 01qq0010 || 4 || 15 (4,4,4,3) || + || + || + || + || + || V || 1 || + || hl -= Q + cf
 
|-
 
|-
|SLL r||8||2||rowspan=4|**0P0*||CB 30+rb||rowspan=4|Shift Left Logical*||rowspan=4|m={0,m,CY}<-
+
| scf || 00110111 || 1 || 4 (4) || - || - || A || 0 || A || - || 0 || 1 || nothing else || Set Carry Flag
(SLL Instructions
+
are unsupported)
+
 
|-
 
|-
|SLL (HL)||15||2||CB 36
+
| set B,R || 11001011 11bbbrrr || 2 || 8 (4,4) || - || - || - || - || - || - || - || - || R := R OR [1 << B] ||rowspan=4|Set Bit
 
|-
 
|-
|SLL (IX+N)||23||4||DD CB XX 36
+
| set B,(hl) || 11001011 11bbb110 || 4 || 15 (4,4,4,3) || - || - || - || - || - || - || - || - || (hl) := (hl) OR [1 << B]
 
|-
 
|-
|SLL (IY+N)||23||4||FD CB XX 36
+
| set B,(I+D) || 11i11101 11001011 dddddddd 11bbb110 || 7 || 23 (4,4,3,5,4,3) || - || - || - || - || - || - || - || - || (I+D) := (I+D) OR [1 << B]
 
|-
 
|-
|SRL r||8||2||rowspan=4|**0P0*||CB 38+rb||rowspan=4|Shift Right Logical||rowspan=4|m=->{0,m,CY}
+
| set B,(I+D)->R || 11i11101 11001011 dddddddd 11bbbrrr || 7 || 23 (4,4,3,5,4,3) || - || - || - || - || - || - || - || - || (I+D) := R := (I+D) OR [1 << B]
 
|-
 
|-
|SRL (HL)||15||2||CB 3E
+
| sla R || 11001011 00100rrr || 2 || 8 (4,4) || + || + || + || 0 || + || P || 0 || X || cf := R.7, R := R << 1 ||rowspan=4|Shift Left Arithmetic
 
|-
 
|-
|SRL (IX+N)||23||4||DD CB XX 3E
+
| sla (hl) || 11001011 00100110 || 4 || 15 (4,4,4,3) || + || + || + || 0 || + || P || 0 || X || cf := (hl).7, (hl) := (hl) << 1
 
|-
 
|-
|SRL (IY+N)||23||4||FD CB XX 3E
+
| sla (I+D) || 11i11101 11001011 dddddddd 00100110 || 7 || 23 (4,4,3,5,4,3) || + || + || + || 0 || + || P || 0 || X || cf := (I+D).7, (I+D) := (I+D) << 1
 
|-
 
|-
|SUB r||4||1||rowspan=5|***V1*||90+rb||rowspan=5|Subtract||rowspan=5|A=A-s
+
| sla (I+D)->R || 11i11101 11001011 dddddddd 00100rrr || 7 || 23 (4,4,3,5,4,3) || + || + || + || 0 || + || P || 0 || X || cf := (I+D).7, (I+D) := R := (I+D) << 1
 
|-
 
|-
|SUB N||7||2||D6 XX
+
| sra R || 11001011 00101rrr || 2 || 8 (4,4) || + || + || + || 0 || + || P || 0 || X || cf := R.0, R := R >> 1, R.7 := R.6 ||rowspan=4|Shift Right Arithmetic
 
|-
 
|-
|SUB (HL)||7||1||96
+
| sra (hl) || 11001011 00101110 || 4 || 15 (4,4,4,3) || + || + || + || 0 || + || P || 0 || X || cf := (hl).0, (hl) := (hl) >> 1, (hl).7 := (hl).6
 
|-
 
|-
|SUB (IX+N)||19||3||DD 96 XX
+
| sra (I+D) || 11i11101 11001011 dddddddd 00101110 || 7 || 23 (4,4,3,5,4,3) || + || + || + || 0 || + || P || 0 || X || cf := (I+D).0,
 +
(I+D) := (I+D) >> 1, (I+D).7 := (I+D).6
 
|-
 
|-
|SUB (IY+N)||19||3||FD 96 XX
+
| sra (I+D)->R || 11i11101 11001011 dddddddd 00101rrr || 7 || 23 (4,4,3,5,4,3) || + || + || + || 0 || + || P || 0 || X || cf := (I+D).0,
 +
tmp := (I+D) >> 1, tmp.7 := tmp.6,
 +
 
 +
(I+D) := R := tmp
 
|-
 
|-
|XOR r||4||1||rowspan=5|***P00||A8+rb||rowspan=5|Logical Exclusive OR||rowspan=5|A=Axs
+
| sll R || 11001011 00110rrr || 2 || 8 (4,4) || + || + || + || 0 || + || P || 0 || X || cf := R.7, R := [R << 1] + 1 ||rowspan=4|Shift Left Logical
 
|-
 
|-
|XOR N||7||2||EE XX
+
| sll (hl) || 11001011 00110110 || 4 || 15 (4,4,4,3) || + || + || + || 0 || + || P || 0 || X || cf := (hl).7, (hl) := [(hl) << 1] + 1
 
|-
 
|-
|XOR (HL)||7||1||AE
+
| sll (I+D) || 11i11101 11001011 dddddddd 00110110 || 7 || 23 (4,4,3,5,4,3) || + || + || + || 0 || + || P || 0 || X || cf := (I+D).7, (I+D) := [(I+D) << 1] + 1
 
|-
 
|-
|XOR (IX+N)||19||3||DD AE XX
+
| sll (I+D)->R || 11i11101 11001011 dddddddd 00110rrr || 7 || 23 (4,4,3,5,4,3) || + || + || + || 0 || + || P || 0 || X || cf := (I+D).7, (I+D) := R := [(I+D) << 1] + 1
 
|-
 
|-
|XOR (IY+N)||19||3||FD AE XX
+
| srl R || 11001011 00111rrr || 2 || 8 (4,4) || 0 || + || + || 0 || + || P || 0 || X || cf := R.0, R := R >> 1 ||rowspan=4|Shift Right Logical
 +
|-
 +
| srl (hl) || 11001011 00111110 || 4 || 15 (4,4,3) || 0 || + || + || 0 || + || P || 0 || X || cf := (hl).0, (hl) := (hl) >> 1
 +
|-
 +
| srl (I+D) || 11i11101 11001011 dddddddd 00111110 || 7 || 23 (4,4,3,5,4,3) || 0 || + || + || 0 || + || P || 0 || X || cf := (I+D).0, (I+D) := (I+D) >> 1
 +
|-
 +
| srl (I+D)->R || 11i11101 11001011 dddddddd 00111rrr || 7 || 23 (4,4,3,5,4,3) || 0 || + || + || 0 || + || P || 0 || X || cf := (I+D).0, (I+D) := R := (I+D) >> 1
 +
|-
 +
| sub R || 10010rrr || 1 || 4 (4) || + || + || + || + || + || V || 1 || + || a -= R ||rowspan=5|Subtract
 +
|-
 +
| sub J || 11i11101 1001010b || 2 || 8 (4,4) || + || + || + || + || + || V || 1 || + || a -= J
 +
|-
 +
| sub N || 11010110 nnnnnnnn || 2 || 7 (4,3) || + || + || + || + || + || V || 1 || + || a -= N
 +
|-
 +
| sub (hl) || 10010110 || 2 || 7 (4,3) || + || + || + || + || + || V || 1 || + || a -= (hl)
 +
|-
 +
| sub (I+D) || 11i11101 10010110 dddddddd || 5 || 19 (4,4,3,5,3) || + || + || + || + || + || V || 1 || + || a -= (I+D)
 
|}
 
|}
  
=== CPC Timings ===
+
=== Letter X ===
  
{| class="wikitable sortable"
+
{| class="wikitable" style="white-space: nowrap;"
!Instruction
+
! Instruction !! Opcode !! NOPs !! Cycles !! S !! Z !! 5 !! H !! 3 !! P !! N !! C !! Effect !! Description
!µs
+
!Size
+
!I/O
+
 
|-
 
|-
|ADC/ADD/SBC/SUB A, (HL)
+
| xor R || 10101rrr || 1 || 4 (4) || + || + || + || 0 || + || P || 0 || 0 || a := a XOR R ||rowspan=5|Logical eXclusive OR
|2
+
|1
+
|
+
 
|-
 
|-
|ADC/ADD/SBC/SUB A, (IX/IY+d)
+
| xor J || 11i11101 1010110b || 2 || 8 (4,4) || + || + || + || 0 || + || P || 0 || 0 || a := a XOR J
|5
+
|3
+
|
+
 
|-
 
|-
|ADC/ADD/SBC/SUB A, A/B/C/D/E/H/L
+
| xor N || 11101110 nnnnnnnn || 2 || 7 (4,3) || + || + || + || 0 || + || P || 0 || 0 || a := a XOR N
|1
+
|1
+
|
+
 
|-
 
|-
|ADC/ADD/SBC/SUB A, HX/LX/HY/LY
+
| xor (hl) || 10101110 || 2 || 7 (4,3) || + || + || + || 0 || + || P || 0 || 0 || a := a XOR (hl)
|2
+
|2
+
|
+
 
|-
 
|-
|ADC/ADD/SBC/SUB A, d
+
| xor (I+D) || 11i11101 10101110 dddddddd || 5 || 19 (4,4,3,5,3) || + || + || + || 0 || + || P || 0 || 0 || a := a XOR (I+D)
|2
+
|}
|2
+
 
|
+
<br>
 +
 
 +
== Timings ==
 +
 
 +
On CPC, bus arbitration is done on every CPU bus access. On MSX, bus arbitration only applies to M1 machine cycles but access to VRAM has other limitations. On ZX Spectrum, bus arbitration is done not by using the /WAIT pin but by disabling the CPU clock when needed.
 +
 
 +
The NOPs column corresponds to CPC timings, which account for the bus arbitration managed by the [[Gate Array]]. The NOP instruction takes 4 cycles. This is the minimum amount of cycles an instruction can take.
 +
 
 +
Every M-cycle that involves a memory or I/O access will be stretched due to bus arbitration. But beware, some M-cycles are purely internal and don't involve a memory or I/O access.
 +
 
 +
Nevertheless, a few CPC timings can appear surprising at first glance:
 +
 
 +
* Instructions LD (IX+d),r and LD (IX+d),n take 5 and 6 NOPs respectively, even though they are both listed as 19 (4,4,3,5,3) cycles in the datasheet. This happens because LD (IX+d),r has one less memory access operation to do compared to LD (IX+d),n as it does not have to fetch its operand from memory.
 +
 
 +
* Instructions IN r,(C) and OUT (C),r take 4 NOPs with CPC timings, even though they are listed as 12 (4,4,4) cycles in the datasheet. This happens because I/O access is not aligned with memory access. On Zilog manual, it is precised that one wait-state TW is automatically inserted after T2 on I/O access.
 +
 
 +
The CPC timings of some instructions will be altered if an interrupt happens. The interrupt test occurs on the last T-State of the instruction, and if it's low, the Z80 will insert 2 wait states to acknowledge the interrupt.
 +
 
 +
So, instructions which end in the third or fourth T-State relative to the read alignment for the next instruction fetch will be delayed by an extra 4 T-States. The few instructions which end in the first or second T-State won't since the first instruction fetch/read in the interrupt won't be delayed an extra 4 T-States. [https://www.cpcwiki.eu/forum/programming/interrupt-wait/ Source]
 +
 
 +
<br>
 +
 
 +
== Opcodes ==
 +
 
 +
The Z80 follows a 2-3-3 opcode bit pattern.
 +
 
 +
All CB-prefixed opcodes and half of the standard opcodes (from &40 to &BF) follow a strict uniform layout. The sole exception is the HALT instruction (opcode &76), which replaces the expected LD (HL),(HL) instruction.
 +
 
 +
The rest of the opcode table is also neatly organised but in an horizontal way instead of vertical.
 +
 
 +
Any instruction in bold is undocumented by Zilog.
 +
 
 +
=== Standard opcodes ===
 +
 
 +
{| style="white-space: nowrap;"
 
|-
 
|-
|ADD/SUB HL, BC/DE/HL/SP
+
|  
|3
+
{| class="wikitable"
|1
+
! Opcode !! Mnemonic
|
+
 
|-
 
|-
|ADD/SUB IX/IY, BC/DE/HL/SP
+
| 00 || NOP
|4
+
|2
+
|
+
 
|-
 
|-
|AND/OR/XOR A, (HL)
+
| 01 nn || LD BC,nn
|2
+
|1
+
|
+
 
|-
 
|-
|AND/OR/XOR A, (IX/IY+d)
+
| 02 || LD (BC),A
|5
+
|3
+
|
+
 
|-
 
|-
|AND/OR/XOR A, A/B/C/D/E/H/L
+
| 03 || INC BC
|1
+
|1
+
|
+
 
|-
 
|-
|AND/OR/XOR A, HX/LX/HY/LY
+
| 04 || INC B
|2
+
|2
+
|
+
 
|-
 
|-
|AND/OR/XOR A, d
+
| 05 || DEC B
|2
+
|2
+
|
+
 
|-
 
|-
|BIT x, (HL)
+
| 06 n || LD B,n
|3
+
|2
+
|
+
 
|-
 
|-
|BIT x, (IX/IY+d)
+
| 07 || RLCA
|6
+
|}
|4
+
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|BIT x, A/B/C/D/E/H/L
+
| 08 || EX AF,AF'
|2
+
|2
+
|
+
 
|-
 
|-
|CALL cond, aa
+
| 09 || ADD HL,BC
|5/3
+
|3
+
|
+
 
|-
 
|-
|CALL aa
+
| 0A || LD A,(BC)
|5
+
|3
+
|
+
 
|-
 
|-
|CCF/SCF
+
| 0B || DEC BC
|1
+
|1
+
|
+
 
|-
 
|-
|CP A, (HL)
+
| 0C || INC C
|2
+
|1
+
|
+
 
|-
 
|-
|CP A, (IX/IY+d)
+
| 0D || DEC C
|5
+
|3
+
|
+
 
|-
 
|-
|CP A, A/B/C/D/E/H/L
+
| 0E n || LD C,n
|1
+
|1
+
|
+
 
|-
 
|-
|CP A, HX/LX/HY/LY
+
| 0F || RRCA
|2
+
|}
|2
+
|  
|
+
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|CP A, d
+
| 10 e || DJNZ e
|2
+
|2
+
|
+
 
|-
 
|-
|CPD/CPI
+
| 11 nn || LD DE,nn
|4
+
|2
+
|
+
 
|-
 
|-
|CPDR/CPIR
+
| 12 || LD (DE),A
|6/4
+
|2
+
|
+
 
|-
 
|-
|CPL
+
| 13 || INC DE
|1
+
|1
+
|
+
 
|-
 
|-
|DAA
+
| 14 || INC D
|1
+
|1
+
|
+
 
|-
 
|-
|DEC/INC (HL)
+
| 15 || DEC D
|3
+
|-
|1
+
| 16 n || LD D,n
 +
|-
 +
| 17 || RLA
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|DEC/INC (IX/IY+d)
+
| 18 e || JR e
|6
+
|-
|3
+
| 19 || ADD HL,DE
 +
|-
 +
| 1A || LD A,(DE)
 +
|-
 +
| 1B || DEC DE
 +
|-
 +
| 1C || INC E
 +
|-
 +
| 1D || DEC E
 +
|-
 +
| 1E n || LD E,n
 +
|-
 +
| 1F || RRA
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|DEC/INC A/B/C/D/E/H/L
+
| 20 e || JR NZ,e
|1
+
|-
|1
+
| 21 nn || LD HL,nn
 +
|-
 +
| 22 nn || LD (nn),HL
 +
|-
 +
| 23 || INC HL
 +
|-
 +
| 24 || INC H
 +
|-
 +
| 25 || DEC H
 +
|-
 +
| 26 n || LD H,n
 +
|-
 +
| 27 || DAA
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|DEC/INC HX/LX/HY/LY
+
| 28 e || JR Z,e
|2
+
|-
|2
+
| 29 || ADD HL,HL
 +
|-
 +
| 2A nn || LD HL,(nn)
 +
|-
 +
| 2B || DEC HL
 +
|-
 +
| 2C || INC L
 +
|-
 +
| 2D || DEC L
 +
|-
 +
| 2E n || LD L,n
 +
|-
 +
| 2F || CPL
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|DEC/INC BC/DE/HL/SP
+
| 30 e || JR NC,e
|2
+
|-
|1
+
| 31 nn || LD SP,nn
 +
|-
 +
| 32 nn || LD (nn),A
 +
|-
 +
| 33 || INC SP
 +
|-
 +
| 34 || INC (HL)
 +
|-
 +
| 35 || DEC (HL)
 +
|-
 +
| 36 n || LD (HL),n
 +
|-
 +
| 37 || SCF
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|DEC/INC IX/IY
+
| 38 e || JR C,e
|3
+
|-
|2
+
| 39 || ADD HL,SP
 +
|-
 +
| 3A nn || LD A,(nn)
 +
|-
 +
| 3B || DEC SP
 +
|-
 +
| 3C || INC A
 +
|-
 +
| 3D || DEC A
 +
|-
 +
| 3E n || LD A,n
 +
|-
 +
| 3F || CCF
 +
|}
 +
|}
 +
 
 +
{| style="white-space: nowrap;"
 +
|-
 +
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 +
|-
 +
| 40 || LD B,B
 +
|-
 +
| 41 || LD B,C
 +
|-
 +
| 42 || LD B,D
 +
|-
 +
| 43 || LD B,E
 +
|-
 +
| 44 || LD B,H
 +
|-
 +
| 45 || LD B,L
 +
|-
 +
| 46 || LD B,(HL)
 +
|-
 +
| 47 || LD B,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|DI/EI
+
| 48 || LD C,B
|1
+
|-
|1
+
| 49 || LD C,C
 +
|-
 +
| 4A || LD C,D
 +
|-
 +
| 4B || LD C,E
 +
|-
 +
| 4C || LD C,H
 +
|-
 +
| 4D || LD C,L
 +
|-
 +
| 4E || LD C,(HL)
 +
|-
 +
| 4F || LD C,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|DJNZ
+
| 50 || LD D,B
|4/3
+
|-
|2
+
| 51 || LD D,C
 +
|-
 +
| 52 || LD D,D
 +
|-
 +
| 53 || LD D,E
 +
|-
 +
| 54 || LD D,H
 +
|-
 +
| 55 || LD D,L
 +
|-
 +
| 56 || LD D,(HL)
 +
|-
 +
| 57 || LD D,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|EX (SP), HL
+
| 58 || LD E,B
|6
+
|-
|1
+
| 59 || LD E,C
 +
|-
 +
| 5A || LD E,D
 +
|-
 +
| 5B || LD E,E
 +
|-
 +
| 5C || LD E,H
 +
|-
 +
| 5D || LD E,L
 +
|-
 +
| 5E || LD E,(HL)
 +
|-
 +
| 5F || LD E,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|EX (SP), IX/IY
+
| 60 || LD H,B
|7
+
|-
|2
+
| 61 || LD H,C
 +
|-
 +
| 62 || LD H,D
 +
|-
 +
| 63 || LD H,E
 +
|-
 +
| 64 || LD H,H
 +
|-
 +
| 65 || LD H,L
 +
|-
 +
| 66 || LD H,(HL)
 +
|-
 +
| 67 || LD H,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|EX AF, AF’
+
| 68 || LD L,B
|1
+
|-
|1
+
| 69 || LD L,C
 +
|-
 +
| 6A || LD L,D
 +
|-
 +
| 6B || LD L,E
 +
|-
 +
| 6C || LD L,H
 +
|-
 +
| 6D || LD L,L
 +
|-
 +
| 6E || LD L,(HL)
 +
|-
 +
| 6F || LD L,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|EX DE, HL
+
| 70 || LD (HL),B
|1
+
|-
|1
+
| 71 || LD (HL),C
 +
|-
 +
| 72 || LD (HL),D
 +
|-
 +
| 73 || LD (HL),E
 +
|-
 +
| 74 || LD (HL),H
 +
|-
 +
| 75 || LD (HL),L
 +
|-
 +
| 76 || HALT
 +
|-
 +
| 77 || LD (HL),A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|EXX
+
| 78 || LD A,B
|1
+
|-
|1
+
| 79 || LD A,C
 +
|-
 +
| 7A || LD A,D
 +
|-
 +
| 7B || LD A,E
 +
|-
 +
| 7C || LD A,H
 +
|-
 +
| 7D || LD A,L
 +
|-
 +
| 7E || LD A,(HL)
 +
|-
 +
| 7F || LD A,A
 +
|}
 +
|}
 +
 
 +
{| style="white-space: nowrap;"
 +
|-
 +
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 +
|-
 +
| 80 || ADD A,B
 +
|-
 +
| 81 || ADD A,C
 +
|-
 +
| 82 || ADD A,D
 +
|-
 +
| 83 || ADD A,E
 +
|-
 +
| 84 || ADD A,H
 +
|-
 +
| 85 || ADD A,L
 +
|-
 +
| 86 || ADD A,(HL)
 +
|-
 +
| 87 || ADD A,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|HALT
+
| 88 || ADC A,B
|1
+
|-
|1
+
| 89 || ADC A,C
 +
|-
 +
| 8A || ADC A,D
 +
|-
 +
| 8B || ADC A,E
 +
|-
 +
| 8C || ADC A,H
 +
|-
 +
| 8D || ADC A,L
 +
|-
 +
| 8E || ADC A,(HL)
 +
|-
 +
| 8F || ADC A,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|IM m
+
| 90 || SUB B
|2
+
|-
|2
+
| 91 || SUB C
 +
|-
 +
| 92 || SUB D
 +
|-
 +
| 93 || SUB E
 +
|-
 +
| 94 || SUB H
 +
|-
 +
| 95 || SUB L
 +
|-
 +
| 96 || SUB (HL)
 +
|-
 +
| 97 || SUB A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|IN A/B/C/D/E/H/L, (C)
+
| 98 || SBC A,B
|4
+
|2
+
|4
+
 
|-
 
|-
|IN A, (d)
+
| 99 || SBC A,C
|3
+
|2
+
|3
+
 
|-
 
|-
|IN F
+
| 9A || SBC A,D
|4
+
|2
+
|4
+
 
|-
 
|-
|IND/INI
+
| 9B || SBC A,E
|5
+
|2
+
|4
+
 
|-
 
|-
|INDR/INIR
+
| 9C || SBC A,H
|6/5
+
|2
+
|4
+
 
|-
 
|-
|JP aa
+
| 9D || SBC A,L
|3
+
|-
|3
+
| 9E || SBC A,(HL)
 +
|-
 +
| 9F || SBC A,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|JP cond, aa
+
| A0 || AND B
|3
+
|-
|3
+
| A1 || AND C
 +
|-
 +
| A2 || AND D
 +
|-
 +
| A3 || AND E
 +
|-
 +
| A4 || AND H
 +
|-
 +
| A5 || AND L
 +
|-
 +
| A6 || AND (HL)
 +
|-
 +
| A7 || AND A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|JP (HL)
+
| A8 || XOR B
|1
+
|-
|1
+
| A9 || XOR C
 +
|-
 +
| AA || XOR D
 +
|-
 +
| AB || XOR E
 +
|-
 +
| AC || XOR H
 +
|-
 +
| AD || XOR L
 +
|-
 +
| AE || XOR (HL)
 +
|-
 +
| AF || XOR A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|JP (IX/IY)
+
| B0 || OR B
|2
+
|-
|2
+
| B1 || OR C
 +
|-
 +
| B2 || OR D
 +
|-
 +
| B3 || OR E
 +
|-
 +
| B4 || OR H
 +
|-
 +
| B5 || OR L
 +
|-
 +
| B6 || OR (HL)
 +
|-
 +
| B7 || OR A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|JR a
+
| B8 || CP B
|3
+
|-
|2
+
| B9 || CP C
 +
|-
 +
| BA || CP D
 +
|-
 +
| BB || CP E
 +
|-
 +
| BC || CP H
 +
|-
 +
| BD || CP L
 +
|-
 +
| BE || CP (HL)
 +
|-
 +
| BF || CP A
 +
|}
 +
|}
 +
 
 +
{| style="white-space: nowrap;"
 +
|-
 +
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 +
|-
 +
| C0 || RET NZ
 +
|-
 +
| C1 || POP BC
 +
|-
 +
| C2 nn || JP NZ,nn
 +
|-
 +
| C3 nn || JP nn
 +
|-
 +
| C4 nn || CALL NZ,nn
 +
|-
 +
| C5 || PUSH BC
 +
|-
 +
| C6 n || ADD A,n
 +
|-
 +
| C7 || RST 00H
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|JR cond, a
+
| C8 || RET Z
|3/2
+
|-
|2
+
| C9 || RET
 +
|-
 +
| CA nn || JP Z,nn
 +
|-
 +
| CB || ''Instruction prefix''
 +
|-
 +
| CC nn || CALL Z,nn
 +
|-
 +
| CD nn || CALL nn
 +
|-
 +
| CE n || ADC A,n
 +
|-
 +
| CF || RST 08H
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|LD (BC/DE), A
+
| D0 || RET NC
|2
+
|-
|1
+
| D1 || POP DE
 +
|-
 +
| D2 nn || JP NC,nn
 +
|-
 +
| D3 n || OUT (n),A
 +
|-
 +
| D4 nn || CALL NC,nn
 +
|-
 +
| D5 || PUSH DE
 +
|-
 +
| D6 n || SUB n
 +
|-
 +
| D7 || RST 10H
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|LD (HL), A/B/C/D/E/H/L
+
| D8 || RET C
|2
+
|-
|1
+
| D9 || EXX
 +
|-
 +
| DA nn || JP C,nn
 +
|-
 +
| DB n || IN A,(n)
 +
|-
 +
| DC nn || CALL C,nn
 +
|-
 +
| DD || ''Instruction prefix''
 +
|-
 +
| DE n || SBC A,n
 +
|-
 +
| DF || RST 18H
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|LD (HL),d
+
| E0 || RET PO
|3
+
|-
|2
+
| E1 || POP HL
 +
|-
 +
| E2 nn || JP PO,nn
 +
|-
 +
| E3 || EX (SP),HL
 +
|-
 +
| E4 nn || CALL PO,nn
 +
|-
 +
| E5 || PUSH HL
 +
|-
 +
| E6 n || AND n
 +
|-
 +
| E7 || RST 20H
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|LD (IX/IY+d), A/B/C/D/E/H/L
+
| E8 || RET PE
|5
+
|-
|3
+
| E9 || JP (HL)
 +
|-
 +
| EA nn || JP PE,nn
 +
|-
 +
| EB || EX DE,HL
 +
|-
 +
| EC nn || CALL PE,nn
 +
|-
 +
| ED || ''Instruction prefix''
 +
|-
 +
| EE n || XOR n
 +
|-
 +
| EF || RST 28H
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|LD (IX/IY+d), d’
+
| F0 || RET P
|6
+
|-
|4
+
| F1 || POP AF
 +
|-
 +
| F2 nn || JP P,nn
 +
|-
 +
| F3 || DI
 +
|-
 +
| F4 nn || CALL P,nn
 +
|-
 +
| F5 || PUSH AF
 +
|-
 +
| F6 n || OR n
 +
|-
 +
| F7 || RST 30H
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|LD (aa), A
+
| F8 || RET M
|4
+
|-
|3
+
| F9 || LD SP,HL
 +
|-
 +
| FA nn || JP M,nn
 +
|-
 +
| FB || EI
 +
|-
 +
| FC nn || CALL M,nn
 +
|-
 +
| FD || ''Instruction prefix''
 +
|-
 +
| FE n || CP n
 +
|-
 +
| FF || RST 38H
 +
|}
 +
|}
 +
 
 +
=== CB-prefixed opcodes ===
 +
 
 +
{| style="white-space: nowrap;"
 +
|-
 +
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 +
|-
 +
| 00 || RLC B
 +
|-
 +
| 01 || RLC C
 +
|-
 +
| 02 || RLC D
 +
|-
 +
| 03 || RLC E
 +
|-
 +
| 04 || RLC H
 +
|-
 +
| 05 || RLC L
 +
|-
 +
| 06 || RLC (HL)
 +
|-
 +
| 07 || RLC A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|LD (aa), BC/DE/SP/IX/IY
+
| 08 || RRC B
|6
+
|-
|4
+
| 09 || RRC C
 +
|-
 +
| 0A || RRC D
 +
|-
 +
| 0B || RRC E
 +
|-
 +
| 0C || RRC H
 +
|-
 +
| 0D || RRC L
 +
|-
 +
| 0E || RRC (HL)
 +
|-
 +
| 0F || RRC A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|LD (aa), HL
+
| 10 || RL B
|5
+
|-
|3
+
| 11 || RL C
 +
|-
 +
| 12 || RL D
 +
|-
 +
| 13 || RL E
 +
|-
 +
| 14 || RL H
 +
|-
 +
| 15 || RL L
 +
|-
 +
| 16 || RL (HL)
 +
|-
 +
| 17 || RL A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|LD A, (BC/DE)
+
| 18 || RR B
|2
+
|-
|1
+
| 19 || RR C
 +
|-
 +
| 1A || RR D
 +
|-
 +
| 1B || RR E
 +
|-
 +
| 1C || RR H
 +
|-
 +
| 1D || RR L
 +
|-
 +
| 1E || RR (HL)
 +
|-
 +
| 1F || RR A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|LD A/B/C/D/E/H/L, (HL)
+
| 20 || SLA B
|2
+
|-
|1
+
| 21 || SLA C
 +
|-
 +
| 22 || SLA D
 +
|-
 +
| 23 || SLA E
 +
|-
 +
| 24 || SLA H
 +
|-
 +
| 25 || SLA L
 +
|-
 +
| 26 || SLA (HL)
 +
|-
 +
| 27 || SLA A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|LD A/B/C/D/E/H/L, (IX/IY+d)
+
| 28 || SRA B
|5
+
|-
|3
+
| 29 || SRA C
 +
|-
 +
| 2A || SRA D
 +
|-
 +
| 2B || SRA E
 +
|-
 +
| 2C || SRA H
 +
|-
 +
| 2D || SRA L
 +
|-
 +
| 2E || SRA (HL)
 +
|-
 +
| 2F || SRA A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|LD A,(aa)
+
| 30 || '''SLL B'''
|4
+
|-
|3
+
| 31 || '''SLL C'''
 +
|-
 +
| 32 || '''SLL D'''
 +
|-
 +
| 33 || '''SLL E'''
 +
|-
 +
| 34 || '''SLL H'''
 +
|-
 +
| 35 || '''SLL L'''
 +
|-
 +
| 36 || '''SLL (HL)'''
 +
|-
 +
| 37 || '''SLL A'''
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 +
|-
 +
| 38 || SRL B
 +
|-
 +
| 39 || SRL C
 +
|-
 +
| 3A || SRL D
 +
|-
 +
| 3B || SRL E
 +
|-
 +
| 3C || SRL H
 +
|-
 +
| 3D || SRL L
 +
|-
 +
| 3E || SRL (HL)
 +
|-
 +
| 3F || SRL A
 +
|}
 
|-
 
|-
|LD A/B/C/D/E/H/L, A/B/C/D/E/H/L
 
|1
 
|1
 
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|LD A/B/C/D/E/H/L, d
+
| 40 || BIT 0,B
|2
+
|-
|2
+
| 41 || BIT 0,C
 +
|-
 +
| 42 || BIT 0,D
 +
|-
 +
| 43 || BIT 0,E
 +
|-
 +
| 44 || BIT 0,H
 +
|-
 +
| 45 || BIT 0,L
 +
|-
 +
| 46 || BIT 0,(HL)
 +
|-
 +
| 47 || BIT 0,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|LD HX/LX, A/B/C/D/E/HX/LX
+
| 48 || BIT 1,B
|2
+
|-
|3
+
| 49 || BIT 1,C
 +
|-
 +
| 4A || BIT 1,D
 +
|-
 +
| 4B || BIT 1,E
 +
|-
 +
| 4C || BIT 1,H
 +
|-
 +
| 4D || BIT 1,L
 +
|-
 +
| 4E || BIT 1,(HL)
 +
|-
 +
| 4F || BIT 1,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|LD HY/LY, A/B/C/D/E/HY/LY
+
| 50 || BIT 2,B
|2
+
|-
|3
+
| 51 || BIT 2,C
 +
|-
 +
| 52 || BIT 2,D
 +
|-
 +
| 53 || BIT 2,E
 +
|-
 +
| 54 || BIT 2,H
 +
|-
 +
| 55 || BIT 2,L
 +
|-
 +
| 56 || BIT 2,(HL)
 +
|-
 +
| 57 || BIT 2,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|LD BC/DE/HL/SP, dd
+
| 58 || BIT 3,B
|3
+
|-
|3
+
| 59 || BIT 3,C
 +
|-
 +
| 5A || BIT 3,D
 +
|-
 +
| 5B || BIT 3,E
 +
|-
 +
| 5C || BIT 3,H
 +
|-
 +
| 5D || BIT 3,L
 +
|-
 +
| 5E || BIT 3,(HL)
 +
|-
 +
| 5F || BIT 3,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|LD IX/IY, dd
+
| 60 || BIT 4,B
|4
+
|-
|4
+
| 61 || BIT 4,C
 +
|-
 +
| 62 || BIT 4,D
 +
|-
 +
| 63 || BIT 4,E
 +
|-
 +
| 64 || BIT 4,H
 +
|-
 +
| 65 || BIT 4,L
 +
|-
 +
| 66 || BIT 4,(HL)
 +
|-
 +
| 67 || BIT 4,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|LD SP, IX/IY
+
| 68 || BIT 5,B
|3
+
|-
|2
+
| 69 || BIT 5,C
 +
|-
 +
| 6A || BIT 5,D
 +
|-
 +
| 6B || BIT 5,E
 +
|-
 +
| 6C || BIT 5,H
 +
|-
 +
| 6D || BIT 5,L
 +
|-
 +
| 6E || BIT 5,(HL)
 +
|-
 +
| 6F || BIT 5,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|LD SP, HL
+
| 70 || BIT 6,B
|2
+
|-
|1
+
| 71 || BIT 6,C
 +
|-
 +
| 72 || BIT 6,D
 +
|-
 +
| 73 || BIT 6,E
 +
|-
 +
| 74 || BIT 6,H
 +
|-
 +
| 75 || BIT 6,L
 +
|-
 +
| 76 || BIT 6,(HL)
 +
|-
 +
| 77 || BIT 6,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 +
|-
 +
| 78 || BIT 7,B
 +
|-
 +
| 79 || BIT 7,C
 +
|-
 +
| 7A || BIT 7,D
 +
|-
 +
| 7B || BIT 7,E
 +
|-
 +
| 7C || BIT 7,H
 +
|-
 +
| 7D || BIT 7,L
 +
|-
 +
| 7E || BIT 7,(HL)
 +
|-
 +
| 7F || BIT 7,A
 +
|}
 
|-
 
|-
| LD HX/LX/HY/LY, d
 
|3
 
|3
 
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|LD BC/DE/HL/SP/IX/IY, (aa)
+
| 80 || RES 0,B
|6
+
|-
|4
+
| 81 || RES 0,C
 +
|-
 +
| 82 || RES 0,D
 +
|-
 +
| 83 || RES 0,E
 +
|-
 +
| 84 || RES 0,H
 +
|-
 +
| 85 || RES 0,L
 +
|-
 +
| 86 || RES 0,(HL)
 +
|-
 +
| 87 || RES 0,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|LD HL, (aa)
+
| 88 || RES 1,B
|5
+
|-
|3
+
| 89 || RES 1,C
 +
|-
 +
| 8A || RES 1,D
 +
|-
 +
| 8B || RES 1,E
 +
|-
 +
| 8C || RES 1,H
 +
|-
 +
| 8D || RES 1,L
 +
|-
 +
| 8E || RES 1,(HL)
 +
|-
 +
| 8F || RES 1,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|LD A, I/R
+
| 90 || RES 2,B
|3
+
|-
|2
+
| 91 || RES 2,C
 +
|-
 +
| 92 || RES 2,D
 +
|-
 +
| 93 || RES 2,E
 +
|-
 +
| 94 || RES 2,H
 +
|-
 +
| 95 || RES 2,L
 +
|-
 +
| 96 || RES 2,(HL)
 +
|-
 +
| 97 || RES 2,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|LD I/R, A
+
| 98 || RES 3,B
|3
+
|-
|2
+
| 99 || RES 3,C
 +
|-
 +
| 9A || RES 3,D
 +
|-
 +
| 9B || RES 3,E
 +
|-
 +
| 9C || RES 3,H
 +
|-
 +
| 9D || RES 3,L
 +
|-
 +
| 9E || RES 3,(HL)
 +
|-
 +
| 9F || RES 3,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|LDD/LDI
+
| A0 || RES 4,B
|5
+
|-
|2
+
| A1 || RES 4,C
 +
|-
 +
| A2 || RES 4,D
 +
|-
 +
| A3 || RES 4,E
 +
|-
 +
| A4 || RES 4,H
 +
|-
 +
| A5 || RES 4,L
 +
|-
 +
| A6 || RES 4,(HL)
 +
|-
 +
| A7 || RES 4,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|LDDR/LDIR
+
| A8 || RES 5,B
|6/5
+
|-
|2
+
| A9 || RES 5,C
 +
|-
 +
| AA || RES 5,D
 +
|-
 +
| AB || RES 5,E
 +
|-
 +
| AC || RES 5,H
 +
|-
 +
| AD || RES 5,L
 +
|-
 +
| AE || RES 5,(HL)
 +
|-
 +
| AF || RES 5,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|NEG
+
| B0 || RES 6,B
|2
+
|-
|2
+
| B1 || RES 6,C
 +
|-
 +
| B2 || RES 6,D
 +
|-
 +
| B3 || RES 6,E
 +
|-
 +
| B4 || RES 6,H
 +
|-
 +
| B5 || RES 6,L
 +
|-
 +
| B6 || RES 6,(HL)
 +
|-
 +
| B7 || RES 6,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 +
|-
 +
| B8 || RES 7,B
 +
|-
 +
| B9 || RES 7,C
 +
|-
 +
| BA || RES 7,D
 +
|-
 +
| BB || RES 7,E
 +
|-
 +
| BC || RES 7,H
 +
|-
 +
| BD || RES 7,L
 +
|-
 +
| BE || RES 7,(HL)
 +
|-
 +
| BF || RES 7,A
 +
|}
 
|-
 
|-
|NOP
 
|1
 
|1
 
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|OUT (C), A/B/C/D/E/H/L
+
| C0 || SET 0,B
|4
+
|2
+
|3*
+
 
|-
 
|-
|OUT (C), 0
+
| C1 || SET 0,C
|4
+
|2
+
|3*
+
 
|-
 
|-
|OUT (d), A
+
| C2 || SET 0,D
|3
+
|2
+
|3
+
 
|-
 
|-
|OUTD/OUTI
+
| C3 || SET 0,E
|5
+
|2
+
|5
+
 
|-
 
|-
|OTDR/OTIR
+
| C4 || SET 0,H
|6/5
+
|2
+
|5
+
 
|-
 
|-
|POP AF/BC/DE/HL
+
| C5 || SET 0,L
|3
+
|-
|1
+
| C6 || SET 0,(HL)
 +
|-
 +
| C7 || SET 0,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|POP IX/IY
+
| C8 || SET 1,B
|4
+
|-
|2
+
| C9 || SET 1,C
 +
|-
 +
| CA || SET 1,D
 +
|-
 +
| CB || SET 1,E
 +
|-
 +
| CC || SET 1,H
 +
|-
 +
| CD || SET 1,L
 +
|-
 +
| CE || SET 1,(HL)
 +
|-
 +
| CF || SET 1,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|PUSH AF/BC/DE/HL
+
| D0 || SET 2,B
|4
+
|-
|1
+
| D1 || SET 2,C
 +
|-
 +
| D2 || SET 2,D
 +
|-
 +
| D3 || SET 2,E
 +
|-
 +
| D4 || SET 2,H
 +
|-
 +
| D5 || SET 2,L
 +
|-
 +
| D6 || SET 2,(HL)
 +
|-
 +
| D7 || SET 2,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|PUSH IX/IY
+
| D8 || SET 3,B
|5
+
|-
|2
+
| D9 || SET 3,C
 +
|-
 +
| DA || SET 3,D
 +
|-
 +
| DB || SET 3,E
 +
|-
 +
| DC || SET 3,H
 +
|-
 +
| DD || SET 3,L
 +
|-
 +
| DE || SET 3,(HL)
 +
|-
 +
| DF || SET 3,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|RES/SET x, (HL)
+
| E0 || SET 4,B
|4
+
|-
|2
+
| E1 || SET 4,C
 +
|-
 +
| E2 || SET 4,D
 +
|-
 +
| E3 || SET 4,E
 +
|-
 +
| E4 || SET 4,H
 +
|-
 +
| E5 || SET 4,L
 +
|-
 +
| E6 || SET 4,(HL)
 +
|-
 +
| E7 || SET 4,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|RES/SET x, (IX/IY+d)
+
| E8 || SET 5,B
|7
+
|-
|4
+
| E9 || SET 5,C
 +
|-
 +
| EA || SET 5,D
 +
|-
 +
| EB || SET 5,E
 +
|-
 +
| EC || SET 5,H
 +
|-
 +
| ED || SET 5,L
 +
|-
 +
| EE || SET 5,(HL)
 +
|-
 +
| EF || SET 5,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|RES/SET x, (IX/IY+d), A/B/C/D/E/H/L
+
| F0 || SET 6,B
|7
+
|-
|4
+
| F1 || SET 6,C
 +
|-
 +
| F2 || SET 6,D
 +
|-
 +
| F3 || SET 6,E
 +
|-
 +
| F4 || SET 6,H
 +
|-
 +
| F5 || SET 6,L
 +
|-
 +
| F6 || SET 6,(HL)
 +
|-
 +
| F7 || SET 6,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|RES/SET x, A/B/C/D/E/H/L
+
| F8 || SET 7,B
|2
+
|-
|2
+
| F9 || SET 7,C
 +
|-
 +
| FA || SET 7,D
 +
|-
 +
| FB || SET 7,E
 +
|-
 +
| FC || SET 7,H
 +
|-
 +
| FD || SET 7,L
 +
|-
 +
| FE || SET 7,(HL)
 +
|-
 +
| FF || SET 7,A
 +
|}
 +
|}
 +
 
 +
=== ED-prefixed opcodes ===
 +
 
 +
The opcodes that are not mentioned in the following table are EDNOP (ED-prefixed NOP instruction). Thay have no effect but take 8 cycles and increment the register R two times. EDED, EDDD, EDFD and EDCB are also EDNOP instructions.
 +
 
 +
{| style="white-space: nowrap;"
 +
|-
 +
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 +
|-
 +
| 40 || IN B,(C)
 +
|-
 +
| 41 || OUT (C),B
 +
|-
 +
| 42 || SBC HL,BC
 +
|-
 +
| 43 nn || LD (nn),BC
 +
|-
 +
| 44 || NEG
 +
|-
 +
| 45 || RETN
 +
|-
 +
| 46 || IM 0
 +
|-
 +
| 47 || LD I,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|RET
+
| 48 || IN C,(C)
|3
+
|-
|1
+
| 49 || OUT (C),C
 +
|-
 +
| 4A || ADC HL,BC
 +
|-
 +
| 4B nn || LD BC,(nn)
 +
|-
 +
| 4C || '''NEG'''
 +
|-
 +
| 4D || RETI
 +
|-
 +
| 4E || '''IM 0'''
 +
|-
 +
| 4F || LD R,A
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|RET cond
+
| 50 || IN D,(C)
|4/2
+
|-
|1
+
| 51 || OUT (C),D
 +
|-
 +
| 52 || SBC HL,DE
 +
|-
 +
| 53 nn || LD (nn),DE
 +
|-
 +
| 54 || '''NEG'''
 +
|-
 +
| 55 || '''RETN'''
 +
|-
 +
| 56 || IM 1
 +
|-
 +
| 57 || LD A,I
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|RETI/RETN
+
| 58 || IN E,(C)
|4
+
|-
|2
+
| 59 || OUT (C),E
 +
|-
 +
| 5A || ADC HL,DE
 +
|-
 +
| 5B nn || LD DE,(nn)
 +
|-
 +
| 5C || '''NEG'''
 +
|-
 +
| 5D || '''RETN'''
 +
|-
 +
| 5E || IM 2
 +
|-
 +
| 5F || LD A,R
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|RL/RLC/RR/RRC/SLA/SLL/SRA/SRL (HL)
+
| 60 || IN H,(C)
|4
+
|-
|2
+
| 61 || OUT (C),H
 +
|-
 +
| 62 || SBC HL,HL
 +
|-
 +
| 63 nn || LD (nn),HL
 +
|-
 +
| 64 || '''NEG'''
 +
|-
 +
| 65 || '''RETN'''
 +
|-
 +
| 66 || '''IM 0'''
 +
|-
 +
| 67 || RRD
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|RL/RLC/RR/RRC/SLA/SLL/SRA/SRL (IX/IY+d)
+
| 68 || IN L,(C)
|7
+
|-
|4
+
| 69 || OUT (C),L
 +
|-
 +
| 6A || ADC HL,HL
 +
|-
 +
| 6B nn || LD HL,(nn)
 +
|-
 +
| 6C || '''NEG'''
 +
|-
 +
| 6D || '''RETN'''
 +
|-
 +
| 6E || '''IM 0'''
 +
|-
 +
| 6F || RLD
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|RL/RLC/RR/RRC/SLA/SLL/SRA/SRL (IX/IY+d), A/B/C/D/E/H/L
+
| 70 || '''IN F,(C)'''
|7
+
|-
|4
+
| 71 || '''OUT (C),0'''
 +
|-
 +
| 72 || SBC HL,SP
 +
|-
 +
| 73 nn || LD (nn),SP
 +
|-
 +
| 74 || '''NEG'''
 +
|-
 +
| 75 || '''RETN'''
 +
|-
 +
| 76 || '''IM 1'''
 +
|-
 +
| 77 || '''EDNOP'''
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 +
|-
 +
| 78 || IN A,(C)
 +
|-
 +
| 79 || OUT (C),A
 +
|-
 +
| 7A || ADC HL,SP
 +
|-
 +
| 7B nn || LD SP,(nn)
 +
|-
 +
| 7C || '''NEG'''
 +
|-
 +
| 7D || '''RETN'''
 +
|-
 +
| 7E || '''IM 2'''
 +
|-
 +
| 7F || '''EDNOP'''
 +
|}
 
|-
 
|-
|RL/RLC/RR/RRC/SLA/SLL/SRA/SRL A/B/C/D/E/H/L
 
|2
 
|2
 
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|RLA/RLCA/RRA/RRCA
+
| A0 || LDI
|1
+
|-
|1
+
| A1 || CPI
 +
|-
 +
| A2 || INI
 +
|-
 +
| A3 || OUTI
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|RLD/RRD
+
| A8 || LDD
|5
+
|-
|2
+
| A9 || CPD
 +
|-
 +
| AA || IND
 +
|-
 +
| AB || OUTD
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 
|-
 
|-
|RST 0/08h/10h/18h/20h/28h/30h/38h
+
| B0 || LDIR
|4
+
|-
|1
+
| B1 || CPIR
 +
|-
 +
| B2 || INIR
 +
|-
 +
| B3 || OTIR
 +
|}
 
|
 
|
 +
{| class="wikitable"
 +
! Opcode !! Mnemonic
 +
|-
 +
| B8 || LDDR
 +
|-
 +
| B9 || CPDR
 +
|-
 +
| BA || INDR
 +
|-
 +
| BB || OTDR
 +
|}
 
|}
 
|}
  
Notes:
+
Notes:  
*x=[0..7], d=[0..ff], m=[0..2], aa=[0..ffff], a=[0..ff]
+
* The opcode ED70 reads the port indicated by the register C without keeping the result but modifies the register F
* * Some exceptions exist
+
* The opcode ED71 corresponds to the instruction OUT (C),255 on a CMOS Z80
* All instructions containing (IX/IY+d) add 3µs and 2 bytes compared to their (HL) variants
+
 
* Contrarily to what the syntax of the instructions JP (HL/IX/IY) suggest, PC will be loaded with the contents of the register itself, not the indexed value. Those instructions should be understood as JP HL/IX/IY
+
=== DD or FD-prefixed opcodes ===
* Despite having different names and opcodes, RETI and RETN are in fact the exact same instruction
+
 
 +
If an opcode is prefixed by DD, the instruction is changed as follows:
 +
* HL is replaced by IX
 +
* H is replaced by IXH
 +
* L is replaced by IXL
 +
* (HL) is replaced by (IX+d)
 +
 
 +
Same for the FD prefix but with IY instead of IX.
 +
 
 +
There are 3 exceptions:
 +
* In the instruction EX DE,HL, HL will not be replaced with IX or IY. The EXX instruction is not affected either.
 +
* If (HL) and L or H are used in the same instruction, L and H are not replaced with IXL or IXH. For instance LD L,(IX+d) stores the content of (IX+d) into L, not IXL.
 +
* If the next byte is a DD, '''ED''' or FD prefix, the current DD or FD prefix is ignored (it's equivalent to a NONI) and processing continues with the next byte. ED-prefixed opcodes cannot be altered by DD or FD prefixes.
 +
 
 +
=== DDCB or FDCB-prefixed opcodes ===
 +
 
 +
When a DD or FD prefix is followed by a CB byte, the CB acts as a second prefix. A mandatory displacement byte comes next, and then the actual opcode.
 +
 
 +
If the instruction produces output other than in the flags (i.e. all except BIT), then the result gets placed both into (IX+d) or (IY+d) and into the register one would normally expect to be altered.
 +
 
 +
DDCB and FDCB-prefixed instructions only increment the R register twice. [https://stackoverflow.com/questions/8540518/z80-memory-refresh-register#comment25506533_16222002 Source]
 +
 
 +
<br>
 +
 
 +
== Oddities ==
 +
 
 +
* RETI and RETN are identical instructions [https://floooh.github.io/2021/12/17/cycle-stepped-z80.html#the-ei-di-and-retiretn-instructions Source]. The only reason for RETI is so that some other hardware can detect the specific case of returning from the interrupt, by detecting the RETI opcode on the data bus.
 +
* EI has a 1-instruction delay. It is necessary for doing EI/RETI without any danger of nested interrupt routines.
 +
* At the end of an NMI service routine, the earliest moment a maskable interrupt will be triggered is at the end of the instruction following RETN. [https://spectrumcomputing.co.uk/forums/viewtopic.php?t=7086 Source]
 +
* RST instructions are just a CALL instruction to a fixed address baked in the instruction itself.
 +
* Despite what the syntax of the instructions JP (HL/IX/IY) suggests, PC will be loaded with the contents of the register itself, not the indexed value. Those instructions should be understood as JP HL/IX/IY.
 +
* The 16-bit commands ADD HL,ss, ADC HL,ss and SBC HL,ss exist but not the command SUB HL,ss.
 +
* While the syntax of the 8-bit ADD, ADC and SBC instructions all explicitly mention the A register, the SUB instruction does not mention it. On the Zilog eZ80, the SUB instruction explicitly mention the A register.
 +
* IN r,(C) and OUT (C),r instructions syntax is misleading as these instructions actually use the full 16-bit port address contained in BC. On the Zilog eZ80, these instructions are correctly named IN, r,(BC) and OUT (BC),r.
 +
* The Amstrad engineers chose to use the high byte of the address (register B) for chip selection instead of the low byte (register C) in I/O operations. As a result, OTIR / OTDR / INIR / INDR instructions cannot be used on Amstrad CPC for transferring or reading a sequence of values on a port as they use B as a counter.
 +
* INI/IND/INIR/INDR decrease B after storing the byte from the hardware port into memory. And OUTI/OUTD/OTIR/OTDR decrease B before sending the memory byte to the hardware port. [https://www.cpcwiki.eu/forum/programming/z80-documentation-errors/ Source]
 +
* All PUSH and POP instructions utilize a 16-bit operand and the high-order byte is always pushed first and popped last. PUSH HL is PUSH H then L. POP HL is POP L then H.
 +
* When an LDxR / CPxR / INxR / OTxR instruction is interrupted, the interrupt handler sees some flags in a different state. [https://github.com/hoglet67/Z80Decoder/wiki/Undocumented-Flags#interrupted-block-instructions Source]
 +
* LD A,I and LD A,R normally copy the state of IFF2 to the Parity flag. NMOS Z80 suffers a problem whereby LD A,I and LD A,R record the state of IFF2 after it has been reset if an interrupt is delivered during that instruction. [https://sinclair.wiki.zxnet.co.uk/wiki/Z80#LD_A,I_and_LD_A,R_bug Source]
 +
 
 +
<br>
 +
 
 +
== Block Diagram ==
 +
[[File:Z80 Block Diagram.gif]]
 +
 
 +
<br>
 +
 
 +
== CPU Pinout ==
 +
[[File:Z80 Pins.png]]
 +
 
 +
Note: A reset disables the maskable interrupt, selects interrupt mode 0, zeroes registers I & R and zeroes the program counter (PC).
 +
 
 +
<br>
 +
 
 +
== Chip Variants ==
 +
 
 +
The [[GBZ80]] (Sharp SM83) that powers the original [[Nintendo GameBoy]] is an in-between the [[Intel 8080]] and Z80. [https://gbdev.io/pandocs/CPU_Comparison_with_Z80.html Source]
 +
 
 +
The ASCII [[R800]] that powers the MSX TurboR is a seriously beefed up version of the Z80:
 +
 
 +
* The ALU of the R800 is 16-bit instead of 4-bit for the Z80. This change allows instructions that were being executed in 4 clocks to be done in 1 clock.
 +
 
 +
* The instruction set of the R800 is almost identical to the Z80. Only 2 instructions have been added: MULUB and MULUW. And many of the undocumented instructions of the Z80 were made official.
 +
 
 +
[[Zilog]] itself offers the [[eZ80]] processor, a binary-compatible upgrade of the Z80, which runs at up to 50MHz but performs like a 150MHz Z80 due to being 3 times faster at the same clock speed.
 +
 
 +
<br>
 +
 
 +
== Manuals ==
 +
 
 +
* [[Media:Um0080.pdf|Official Zilog Z80 CPU user manual (2016)]]
 +
* [[Media:Z80 CPU Technical Manual 1977.pdf]]
 +
* [[Media:Mostek Z80 Programming Manual.pdf]]
 +
* [[Media:Z80-Mostek-Technical-Manual.pdf]] [http://www.z80.info/z80ins.txt Text version] - provides a detailed breakdown of the machine cycles
 +
* [[Media:Mostek Z80 Micro-Reference Manual Feb78.pdf]]
 +
* [[Media:Z80 CPU Instant Reference Card (Color).pdf]]
 +
* [[Media:Z80 CPC Timings cheat sheet.20230709.pdf]]
 +
* [[Media:Memptr eng.txt|MEMPTR, esoteric register of the Z80 CPU]]
 +
* [[Media:Z80-documented-v0.91.pdf|The Undocumented Z80 Documented]]
 +
* [[Z80 - undocumented opcodes]]
 +
 
 +
<br>
 +
 
 +
== Weblinks ==
 +
 
 +
*[[Zilog]] [http://www.zilog.com]
 +
*[http://www.z80.info/z80cs.htm Computer Systems based on Z80 Family]
 +
*[http://en.wikipedia.org/wiki/Z80 The Z80 processor on Wikipedia]
 +
*[https://sinclair.wiki.zxnet.co.uk/wiki/Z80 Z80 article on Sinclair Wiki]
 +
*[https://www.grimware.org/doku.php/documentations/devices/z80 Z80 documentation from Grimware]
 +
*[http://www.z80.info/decoding.htm Decoding Z80 opcodes]
 +
*[http://z80.info/interrup.htm Interrupt behaviour of the Z80 CPU]
 +
*[https://github.com/hoglet67/Z80Decoder/wiki/Undocumented-Flags Behaviour of the undocumented flags]
 +
*[https://baltazarstudios.com/zilog-z80-undocumented-behavior/ Complete list of Z80 instructions and their bus responses and cycles dumped from real hardware]
 +
*[https://floooh.github.io/2021/12/06/z80-instruction-timing.html Detailed look at Z80 instruction timings with the help of a Z80 netlist simulation]
 +
*[https://floooh.github.io/2021/12/17/cycle-stepped-z80.html Cycle-stepped Z80 emulation how-to]
 +
*[https://github.com/SingleStepTests Tom Harte's SingleStepTests]
  
 
[[Category:Hardware]][[Category:Programming]][[Category:Datasheet]][[Category:CPC Internal Components]][[Category:Electronic Component]]
 
[[Category:Hardware]][[Category:Programming]][[Category:Datasheet]][[Category:CPC Internal Components]][[Category:Electronic Component]]

Latest revision as of 16:29, 9 October 2024

Zilog Z80A

The Z80 is an 8-bit microprocessor designed by Zilog founder and CEO Federico Faggin, first released in July 1976. It is the CPU used in the Amstrad CPC / Plus / PCW computers.

The Z80/Z80A was a very popular microprocessor, used in a wide range of applications, from gaming consoles like the ColecoVision or the Sega Master System to handhelds like the Sega GameGear or some TI calculators to personal computers like the ZX81, ZX Spectrum, MSX and VG 5000.

It was even used in the Sega MegaDrive as the sound CPU and in the Commodore C128 as a secondary processor in order to achieve CP/M compatibility. Similarly, the Acorn Z80 Second Processor expansion for the BBC Micro enables CP/M compatibility.


History

In the early 1970s, Intel developed the 8080, one of the first widely used microprocessors. However, a group of engineers led by Federico Faggin, the originator of the 8080 architecture in early 1972, left Intel to start their own company called Zilog in 1974.

At Zilog, Faggin and his team wanted to create an improved version of the 8080 that would be more efficient, flexible, and easier to use. This led to the development of the Z80, which was designed to be both backward-compatible with the 8080 and more powerful. This compatibility meant that any software written for the 8080 could run on the Z80, making it an attractive upgrade for manufacturers and developers.

The Z80 had several key improvements over the 8080. It featured more registers, block instructions, bitwise ops, indexed addressing, and improved interrupt handling. It also had built-in memory refresh for dynamic RAM, that made it easier to build systems around it.


Description

The Z80 microprocessor is an 8-bit CPU with a 4-bit ALU and a 16-bit address bus capable of direct access to 64KB of memory space. The Z80 is a little-endian CPU, meaning it stores 16-bit values with the least significant byte first, followed by the most significant byte.

It has a language of 252 root instructions and with the reserved 4 bytes as prefixes, access to an additional 308 instructions. Although it lacks the raw processing power of processors like the Intel 80x86 or the Motorola 68000 series, the Z80 is extremely useful for low cost control applications.

The Z80 has about 8500 transistors. To put it into perspective, 64KB of DRAM contains 524288 transistors, as 1 bit of DRAM needs 1 transistor. Fun fact: an Amstrad CPC equipped with a 4MB RAM expansion has 32 million transistors dedicated to RAM while the Z80 CPU still has only 8500 transistors.

The Z80 is mid-1970s technology while the 64KB DRAM is early-1980s technology and the 4MB DRAM is early-1990s technology.

The Z80 comes in a 40-pin DIP package. It has been manufactured in A, B, and C models, differing only in maximum clock speed. It also has been manufactured as a stand-alone microcontroller with various configurations of on-chip RAM and EPROM.


Part numbers used in the Amstrad CPC during its lifetime

The Z80 CPU has been manufactured by others, and various Z80s have been used in the construction of the CPC during its lifetime:

All the Z80 CPUs that have been used on CPC and Plus machines are NMOS. Source

Zilog ended the production of the Z80 in April 2024. This chip is still available in ample quantities through NOS chip suppliers. And Zilog continues to produce the eZ80 which is a modernized Z80 CPU.


Modern incarnations

Apart from surplus/new Z80-clones that are quite easy to find, many emulations depend on software implementations of the Z80:

  • The T80 is a VHDL implementation of the Z80 and Z80A, finished in 2002 on OpenCores
  • arnold uses InkZ80, written in C++ (apart from the author-designed C simulation)
  • On OpenCores, there is also a Verilog implementation of the Z80.


Registers

Register Size Description Notes
B, C, D, E, H, L 8-bit General-purpose registers Can form 16-bit pairs: BC, DE, HL
A (Accumulator) 8-bit Main register for arithmetic, logic, and data transfer Most used register
F (Flags) 8-bit
  • bit7 - SF - Sign Flag
  • bit6 - ZF - Zero Flag
  • bit5 - F5 - Undocumented by Zilog
  • bit4 - HF - Half Carry Flag
  • bit3 - F3 - Undocumented by Zilog
  • bit2 - PF - Parity Flag (also sometimes used for Overflow)
  • bit1 - NF - Negate Flag (last ALU op was subtract or compare)
  • bit0 - CF - Carry Flag
Flags (including F5 and F3) are affected by most operations.

HF and NF are used in the DAA algorithm.

AF', BC', DE', HL' 16-bit Alternate register set Swappable with primary registers for fast context switching
SP (Stack Pointer) 16-bit Points to top of the stack Used for subroutine calls and interrupt handling
PC (Program Counter) 16-bit Points to the next instruction Automatically increments as instructions execute
IX, IY (Index Registers) 16-bit Used for indexed addressing Can be split into IXH/IXL, IYH/IYL for 8-bit access
I (Interrupt Vector) 8-bit Holds base address for interrupt mode 2 Combined with external data to form an interrupt vector
R (Memory Refresh) 8-bit Increments after each M1 cycle (instruction or prefix fetch) to refresh DRAM Only the lower 7 bits are incremented. Bit7 can only be changed by writing to the R register.


Internal state

Register Size Description Notes
IM (Interrupt Mode) 2-bit Specifies the interrupt mode (0, 1, or 2) Controls how interrupts are handled:
  • IM 0: External devices provide an opcode to execute (most likely an RST instruction). This mode was originally implemented in the Intel 8080 CPU
  • IM 1: Fixed vector at 0038h
  • IM 2: Vector provided by I register and external data

The NMI vector is fixed at 0066h, regardless of the I register, and of the IM interrupt mode.

IFF1 1-bit Main Interrupt Flip-Flop Set when interrupts are enabled, cleared on disable.

When the CPU accepts a maskable interrupt, both IFF1 and IFF2 are automatically cleared, inhibiting further interrupts.

IFF2 1-bit Stores the state of IFF1 during Non-Maskable Interrupts (NMI) When an NMI occurs, the processor clears IFF1 to disable interrupts temporarily.

IFF2 stores the previous state of IFF1 so that after the NMI is handled, IFF1 can be restored to its original state.

A barebone Amstrad CPC doesn't use NMI. So IFF1 and IFF2 are always the same. However, NMI is used by the PlayCity and Play2CPC expansions.

WZ 16-bit Internal temporary register pair. Also known as MEMPTR Used for memory and address calculations.

Normally, you never see the content of this register. But it leaks through the flags F5 and F3 in the BIT b,(HL) instruction. Source

Q 8-bit Internal register where it assembles the new content of the F register, before moving it back to F
 On Zilog NMOS Z80, when the instruction doesn't compute new flags, this register is cleared instead. But not on NEC NMOS Z80. And CMOS Z80 behave in a different way too.
 Normally, you never see the content of this register. But it leaks through F5 and F3 in the SCF/CCF instructions. Source
 Emulating Q is not strictly necessary. A 1-bit flag, indicating whether the previous instruction computed flags, is enough to emulate the behaviour of SCF/CCF. Source
 Also note that while POP AF and EX AF,AF' modify F, they do not compute new flag values.

The explanation above is just an approximation. Latest research on the subject (May 2024) show that SCF/CCF instructions are unstable. Source

IR (Instruction Register) 8-bit Holds the opcode of the currently executing instruction Internally used, not accessible by the programmer. Not to be confused with I (Interrupt Vector) and R (Memory Refresh) registers.
EIP (Extended Instruction Prefix) 2-bit Holds the prefix for extended instructions (CB, ED, or none) Used for extended instruction sets like bitwise ops.
IMP (Indexing Mode Prefix) 2-bit Specifies the indexing mode (DD for IX+d, FD for IY+d, or none for HL) Indicates use of index registers (IX or IY) for memory access.

Notes:

  • EIP and IMP can be fusioned into a 3-bit internal state as there are only 7 possible values for the prefixes (none, ed, dd, fd, cb, ddcb, fdcb). Probably not a win though as it makes everything more confusing.
  • IFF1 / IFF2 are called IEF1 / IEF2 (Interrupt Enable Flip-flops) in the Zilog eZ80 manual.


Z80 Instructions

Legend

Notation Meaning Respective Opcode Bits
A 16-bit address or immediate alalalal ahahahah
B Bit number (0..7) bbb = 000..111
C Condition (nz, z, nc, c, po, pe, p, m)

nz: ZF=0, z: ZF=1, nc: CF=0, c: CF=1, po: PF=0, pe: PF=1, p: SF=0, m: SF=1

ccc = 000, 001, 010, 011, 100, 101, 110, 111
D 8-bit signed relative offset dddddddd
E 16-bit relative address dddddddd (E minus address of next instruction)
I Index register (ix, iy) i = 0, 1
J Half index register (ixh, ixl, iyh, iyl) (i, b) = (0, 0), (0, 1), (1, 0), (1, 1)
N 8-bit immediate nnnnnnnn
P 16-bit register pair (bc, de, hl, af) pp = 00, 01, 10, 11
Q 16-bit register (bc, de, hl/ix/iy, sp) qq = 00, 01, 10, 11
R 8-bit general purpose register (a, b, c, d, e, h, l) rrr (or sss) = 111, 000, 001, 010, 011, 100, 101
S Restart address (0x00, 0x08,..., 0x38) sss = 000, 001,..., 111

Flags

  • - = no change
  • + = change by definition (if noted, by the operation marked with '=> flags', otherwise by the only non-single-bit operation):
* S = sign, bit 7 of the result byte (accumulator or high byte for 16-bit operations)
* Z = zero, set if the result is zero (8 or 16-bit value)
* 5 = undocumented, bit 5 of the result byte
* H = half-carry, the carry (theoretical bit 4) of the low nibble of the result byte
* 3 = undocumented, bit 3 of the result byte
* P = parity (set if the result byte has an even number of bits set) or overflow (set when crossing the boundary of the signed range); always specified
* N = negative, set if the previous operation was a subtraction; always specified
* C = carry, the theoretical bit 8 of the result byte
  • 0 = always reset
  • 1 = always set
  • X = change described under Effect
  • P = parity (only for the parity flag)
  • V = overflow (only for the parity flag)
  • A = OR with the respective bit of the accumulator
  • C = set if the counter (bc) is nonzero after decrementing

Miscellaneous

  • () = indirection
  • (()) = I/O port
  • [] = operator precedence (to avoid confusion with indirection)
  • E.B = the Bth bit of the value of expression E
  • * = any bit value (0 or 1)
  • wz = an internal 16-bit register connected to 16-bit operations
  • tmp, tmp2 = temporary storage whose value is thrown away after each instruction

Letter A

Instruction Opcode NOPs Cycles S Z 5 H 3 P N C Effect Description
adc a,R 10001rrr 1 4 (4) + + + + + V 0 + a += R + cf Add with Carry
adc a,J 11i11101 1000110b 2 8 (4,4) + + + + + V 0 + a += J + cf
adc a,N 11001110 nnnnnnnn 2 7 (4,3) + + + + + V 0 + a += N + cf
adc a,(hl) 10001110 2 7 (4,3) + + + + + V 0 + a += (hl) + cf
adc a,(I+D) 11i11101 10001110 dddddddd 5 19 (4,4,3,5,3) + + + + + V 0 + a += (I+D) + cf
adc hl,Q 11101101 01qq1010 4 15 (4,4,4,3) + + + + + V 0 + hl += Q + cf
add a,R 10000rrr 1 4 (4) + + + + + V 0 + a += R Add
add a,J 11i11101 1000010b 2 8 (4,4) + + + + + V 0 + a += J
add a,N 11000110 nnnnnnnn 2 7 (4,3) + + + + + V 0 + a += N
add a,(hl) 10000110 2 7 (4,3) + + + + + V 0 + a += (hl)
add a,(I+D) 11i11101 10000110 dddddddd 5 19 (4,4,3,5,3) + + + + + V 0 + a += (I+D)
add hl,Q 00qq1001 3 11 (4,4,3) - - + + + - 0 + hl += Q
add I,Q 11i11101 00qq1001 4 15 (4,4,4,3) - - + + + - 0 + I += Q
and R 10100rrr 1 4 (4) + + + 1 + P 0 0 a := a AND R Logical AND
and J 11i11101 1010010b 2 8 (4,4) + + + 1 + P 0 0 a := a AND J
and N 11100110 nnnnnnnn 2 7 (4,3) + + + 1 + P 0 0 a := a AND N
and (hl) 10100110 2 7 (4,3) + + + 1 + P 0 0 a := a AND (hl)
and (I+D) 11i11101 10100110 dddddddd 5 19 (4,4,3,5,3) + + + 1 + P 0 0 a := a AND (I+D)

Letter B

Instruction Opcode NOPs Cycles S Z 5 H 3 P N C Effect Description
bit B,R 11001011 01bbbrrr 2 8 (4,4) + + + 1 + P 0 - tmp := R AND [1 << B] Test Bit
bit B,(hl) 11001011 01bbb110 3 12 (4,4,4) + + X 1 X P 0 - tmp := (hl) AND [1 << B],

f5 := wz.13, f3 := wz.11

bit B,(I+D) 11i11101 11001011 dddddddd 01bbb*** 6 20 (4,4,3,5,4) + + X 1 X P 0 - tmp := (I+D) AND [1 << B],

f5 := [I+D].13, f3 := [I+D].11

Letter C

Instruction Opcode NOPs Cycles S Z 5 H 3 P N C Effect Description
call A 11001101 alalalal ahahahah 5 17 (4,3,4,3,3) - - - - - - - - sp -= 2, (sp) := pc, pc := A Call
call C,A 11ccc100 alalalal ahahahah 5/3 17/10 (4,3,4,3,3)/(4,3,3) - - - - - - - - if C then sp -= 2, (sp) := pc, pc := A Conditional Call
ccf 00111111 1 4 (4) - - A X A - 0 X hf := cf, cf := ~cf Complement Carry Flag
cp R 10111rrr 1 4 (4) + + X + X V 1 + tmp := a - R, f5 := R.5, f3 := R.3 Compare
cp J 11i11101 1011110b 2 8 (4,4) + + X + X V 1 + tmp := a - J, f5 := J.5, f3 := J.3
cp N 11111110 nnnnnnnn 2 7 (4,3) + + X + X V 1 + tmp := a - N, f5 := N.5, f3 := N.3
cp (hl) 10111110 2 7 (4,3) + + X + X V 1 + tmp := a - (hl), f5 := (hl).5, f3 := (hl).3
cp (I+D) 11i11101 10111110 dddddddd 5 19 (4,4,3,5,3) + + X + X V 1 + tmp := a - (I+D), f5 := (I+D).5, f3 := (I+D).3
cpd 11101101 10101001 4 16 (4,4,3,5) + + X + X C 1 - tmp := a - (hl) => flags, bc -= 1, hl -= 1,

f5 := [tmp - hf].1, f3 = [tmp - hf].3

Compare and Decrement
cpdr 11101101 10111001 6/4 21/16 (4,4,3,5,5)/(4,4,3,5) + + X + X C 1 - cpd, if bc <> 0 and nz then pc -= 2 Compare and Decrement, Repeat
cpi 11101101 10100001 4 16 (4,4,3,5) + + X + X C 1 - tmp := a - (hl) => flags, bc -= 1, hl += 1,

f5 := [tmp - hf].1, f3 = [tmp - hf].3

Compare and Increment
cpir 11101101 10110001 6/4 21/16 (4,4,3,5,5)/(4,4,3,5) + + X + X C 1 - cpi, if bc <> 0 and nz then pc -= 2 Compare and Increment, Repeat
cpl 00101111 1 4 (4) - - + 1 + - 1 - a := ~a Complement

Letter D

Instruction Opcode NOPs Cycles S Z 5 H 3 P N C Effect Description
daa 00100111 1 4 (4) + + + X + P - X tmp := a,

if nf then

if hf or [a AND 0x0f > 9] then tmp -= 0x06
if cf or [a > 0x99] then tmp -= 0x60

else

if hf or [a AND 0x0f > 9] then tmp += 0x06
if cf or [a > 0x99] then tmp += 0x60

endif,

tmp => flags, cf := cf OR [a > 0x99],

hf := a.4 XOR tmp.4, a := tmp

Decimal Adjust Accumulator
dec R 00rrr101 1 4 (4) + + + + + V 1 - R -= 1 Decrement
dec J 11i11101 0010b101 2 8 (4,4) + + + + + V 1 - J -= 1
dec (hl) 00110101 3 11 (4,4,3) + + + + + V 1 - (hl) -= 1
dec (I+D) 11i11101 00110101 dddddddd 6 23 (4,4,3,5,4,3) + + + + + V 1 - (I+D) -= 1
dec Q 00qq1011 2 6 (6) - - - - - - - - Q -= 1
dec I 11i11101 00101011 3 10 (4,6) - - - - - - - - I -= 1
di 11110011 1 4 (4) - - - - - - - - iff1 := 0, iff2 := 0 Disable Interrupts
djnz E 00010000 dddddddd 4/3 13/8 (5,3,5)/(5,3) - - - - - - - - b -= 1, if b <> 0 then pc := E Decrement, Jump Non-Zero

Letter E

Instruction Opcode NOPs Cycles S Z 5 H 3 P N C Effect Description
ei 11111011 1 4 (4) - - - - - - - - iff1 := 1, iff2 := 1 after the next instruction Enable Interrupts
ex (sp),hl 11100011 6 19 (4,3,4,3,5) - - - - - - - - (sp) <=> hl Exchange
ex (sp),I 11i11101 11100011 7 23 (4,4,3,4,3,5) - - - - - - - - (sp) <=> I
ex af,af' 00001000 1 4 (4) X X X X X X X X af <=> af'
ex de,hl 11101011 1 4 (4) - - - - - - - - de <=> hl
exx 11011001 1 4 (4) - - - - - - - - bc, de, hl <=> bc', de', hl'

Letter H

Instruction Opcode NOPs Cycles S Z 5 H 3 P N C Effect Description
halt 01110110 1 4 (4) - - - - - - - - wait for interrupt Suspends CPU operation

Letter I

Instruction Opcode NOPs Cycles S Z 5 H 3 P N C Effect Description
im 0 11101101 01*0*110 2 8 (4,4) - - - - - - - - mode 0: execute instruction on bus Set Interrupt Mode
im 1 11101101 01*10110 2 8 (4,4) - - - - - - - - mode 1: execute rst 38h
im 2 11101101 01*11110 2 8 (4,4) - - - - - - - - mode 2: call (i * 256 + byte on bus)
in a,(N) 11011011 nnnnnnnn 3 11 (4,3,4) - - - - - - - - a := ((N)) I/O Input
in R,(c) 11101101 01rrr000 4 12 (4,4,4) + + + 0 + P 0 - R := ((c))
in f,(c) 11101101 01110000 4 12 (4,4,4) + + + 0 + P 0 - tmp := ((c))
inc R 00rrr100 1 4 (4) + + + + + V 0 - R += 1 Increment
inc J 11i11101 0010b100 2 8 (4,4) + + + + + V 0 - J += 1
inc (hl) 00110100 3 11 (4,4,3) + + + + + V 0 - (hl) += 1
inc (I+D) 11i11101 00110100 dddddddd 6 23 (4,4,3,5,4,3) + + + + + V 0 - (I+D) += 1
inc Q 00qq0011 2 6 (6) - - - - - - - - Q += 1
inc I 11i11101 00100011 3 10 (4,6) - - - - - - - - I += 1
ind 11101101 10101010 5 16 (4,5,3,4) + + + X + X X X tmp := ((c)), (hl) := tmp, hl -= 1,

b -= 1 => flags, nf := tmp.7,

tmp2 = tmp + [[c - 1] AND 0xff],

pf := parity of [[tmp2 AND 0x07] XOR b],

hf := cf := tmp2 > 255

I/O Input and Decrement
indr 11101101 10111010 6/5 21/16 (4,5,3,4,5)/(4,5,3,4) + + + X + X X X ind, if b <> 0 then pc -= 2 I/O Input and Decrement, Repeat
ini 11101101 10100010 5 16 (4,5,3,4) + + + X + X X X tmp := ((c)), (hl) := tmp, hl += 1,

b -= 1 => flags, nf := tmp.7,

tmp2 := tmp + [[c + 1] AND 0xff],

pf := parity of [[tmp2 AND 0x07] XOR b],

hf := cf := tmp2 > 255

I/O Input and Increment
inir 11101101 10110010 6/5 21/16 (4,5,3,4,5)/(4,5,3,4) + + + X + X X X ini, if b <> 0 then pc -= 2 I/O Input and Increment, Repeat

Letter J

Instruction Opcode NOPs Cycles S Z 5 H 3 P N C Effect Description
jp A 11000011 alalalal ahahahah 3 10 (4,3,3) - - - - - - - - pc := A Jump
jp (hl) 11101001 1 4 (4) - - - - - - - - pc := hl
jp (I) 11i11101 11101001 2 8 (4,4) - - - - - - - - pc := I
jp C,A 11ccc010 alalalal ahahahah 3 10 (4,3,3) - - - - - - - - if C then pc := A Conditional Jump
jr E 00011000 dddddddd 3 12 (4,3,5) - - - - - - - - pc := E Relative Jump
jr nz,E 00100000 dddddddd 3/2 12/7 (4,3,5)/(4,3) - - - - - - - - if nz then pc := E Conditional Relative Jump
jr z,E 00101000 dddddddd 3/2 12/7 (4,3,5)/(4,3) - - - - - - - - if zf then pc := E
jr nc,E 00110000 dddddddd 3/2 12/7 (4,3,5)/(4,3) - - - - - - - - if nc then pc := E
jr c,E 00111000 dddddddd 3/2 12/7 (4,3,5)/(4,3) - - - - - - - - if cf then pc := E

Letter L

Instruction Opcode NOPs Cycles S Z 5 H 3 P N C Effect Description
ld R1,R2 01rrrsss 1 4 (4) - - - - - - - - R1 := R2 Load
ld R,J 11i11101 01rrr10b 2 8 (4,4) - - - - - - - - R := J
ld J,R 11i11101 0110brrr 2 8 (4,4) - - - - - - - - J := R
ld ixh,ixl 11011101 01100101 2 8 (4,4) - - - - - - - - ixh := ixl
ld ixl,ixh 11011101 01101100 2 8 (4,4) - - - - - - - - ixl := ixh
ld iyh,iyl 11111101 01100101 2 8 (4,4) - - - - - - - - iyh := iyl
ld iyl,iyh 11111101 01101100 2 8 (4,4) - - - - - - - - iyl := iyh
ld R,N 00rrr110 nnnnnnnn 2 7 (4,3) - - - - - - - - R := N
ld R,(hl) 01rrr110 2 7 (4,3) - - - - - - - - R := (hl)
ld R,(I+D) 11i11101 01rrr110 dddddddd 5 19 (4,4,3,5,3) - - - - - - - - R := (I+D)
ld (hl),R 01110rrr 2 7 (4,3) - - - - - - - - (hl) := R
ld (hl),N 00110110 nnnnnnnn 3 10 (4,3,3) - - - - - - - - (hl) := N
ld (I+D),R 11i11101 01110rrr dddddddd 5 19 (4,4,3,5,3) - - - - - - - - (I+D) := R
ld (I+D),N 11i11101 00110110 dddddddd nnnnnnnn 6 19 (4,4,3,5,3) - - - - - - - - (I+D) := N
ld a,(bc) 00001010 2 7 (4,3) - - - - - - - - a := (bc)
ld a,(de) 00011010 2 7 (4,3) - - - - - - - - a := (de)
ld a,(A) 00111010 alalalal ahahahah 4 13 (4,3,3,3) - - - - - - - - a := (A)
ld (bc),a 00000010 2 7 (4,3) - - - - - - - - (bc) := a
ld (de),a 00010010 2 7 (4,3) - - - - - - - - (de) := a
ld (A),a 00110010 alalalal ahahahah 4 13 (4,3,3,3) - - - - - - - - (A) := a
ld i,a 11101101 01000111 3 9 (4,5) - - - - - - - - i := a
ld r,a 11101101 01001111 3 9 (4,5) - - - - - - - - r := a
ld a,i 11101101 01010111 3 9 (4,5) + + + 0 + X 0 - a := i, pf := iff2
ld a,r 11101101 01011111 3 9 (4,5) + + + 0 + X 0 - a := r, pf := iff2
ld Q,A 00qq0001 alalalal ahahahah 3 10 (4,3,3) - - - - - - - - Q := A
ld I,A 11i11101 00100001 alalalal ahahahah 4 14 (4,4,3,3) - - - - - - - - I := A
ld Q,(A) 11101101 01qq1011 alalalal ahahahah 6 20 (4,4,3,3,3,3) - - - - - - - - Q := (A)
ld hl,(A) 00101010 alalalal ahahahah 5 16 (4,3,3,3,3) - - - - - - - - hl := (A)
ld I,(A) 11i11101 00101010 alalalal ahahahah 6 20 (4,4,3,3,3,3) - - - - - - - - I := (A)
ld (A),Q 11101101 01qq0011 alalalal ahahahah 6 20 (4,4,3,3,3,3) - - - - - - - - (A) := Q
ld (A),hl 00100010 alalalal ahahahah 5 16 (4,3,3,3,3) - - - - - - - - (A) := hl
ld (A),I 11i11101 00100010 alalalal ahahahah 6 20 (4,4,3,3,3,3) - - - - - - - - (A) := I
ld sp,hl 11111001 2 6 (6) - - - - - - - - sp := hl
ld sp,I 11i11101 11111001 3 10 (4,6) - - - - - - - - sp := I
ldd 11101101 10101000 5 16 (4,4,3,5) - - X 0 X C 0 - tmp := (hl), (de) := tmp, de -= 1, hl -= 1,

bc -= 1, f5 := [tmp + a].1, f3 := [tmp + a].3

Load and Decrement
lddr 11101101 10111000 6/5 21/16 (4,4,3,5,5)/(4,4,3,5) - - X 0 X C 0 - ldd, if bc <> 0 then pc -= 2 Load and Decrement, Repeat
ldi 11101101 10100000 5 16 (4,4,3,5) - - X 0 X C 0 - tmp := (hl), (de) := tmp, de += 1, hl += 1,

bc -= 1, f5 := [tmp + a].1, f3 := [tmp + a].3

Load and Increment
ldir 11101101 10110000 6/5 21/16 (4,4,3,5,5)/(4,4,3,5) - - X 0 X C 0 - ldi, if bc <> 0 then pc -= 2 Load and Increment, Repeat

Letter N

Instruction Opcode NOPs Cycles S Z 5 H 3 P N C Effect Description
neg 11101101 01***100 2 8 (4,4) + + + + + V 1 + a := 0 - a Negate
nop 00000000 1 4 (4) - - - - - - - - nothing No Operation

Letter O

Instruction Opcode NOPs Cycles S Z 5 H 3 P N C Effect Description
or R 10110rrr 1 4 (4) + + + 0 + P 0 0 a := a OR R Logical Inclusive OR
or J 11i11101 1011010b 2 8 (4,4) + + + 0 + P 0 0 a := a OR J
or N 11110110 nnnnnnnn 2 7 (4,3) + + + 0 + P 0 0 a := a OR N
or (hl) 10110110 2 7 (4,3) + + + 0 + P 0 0 a := a OR (hl)
or (I+D) 11i11101 10110110 dddddddd 5 19 (4,4,3,5,3) + + + 0 + P 0 0 a := a OR (I+D)
out (N),a 11010011 nnnnnnnn 3 11 (4,3,4) - - - - - - - - ((N)) := a I/O Output
out (c),R 11101101 01rrr001 4 12 (4,4,4) - - - - - - - - ((c)) := R
out (c),0 11101101 01110001 4 12 (4,4,4) - - - - - - - - ((c)) := 0 (255 on CMOS CPU)
outd 11101101 10101011 5 16 (4,5,3,4) + + + X + X X X tmp := (hl), ((c)) := tmp, hl -= 1,

b -= 1 => flags, nf := tmp.7, tmp2 = tmp + l,

pf := parity of [[tmp2 AND 0x07] XOR b],

hf := cf := tmp2 > 255

I/O Output and Decrement
otdr 11101101 10111011 6/5 21/16 (4,5,3,4,5)/(4,5,3,4) + + + X + X X X outd, if b <> 0 then pc -= 2 I/O Output and Decrement, Repeat
outi 11101101 10100011 5 16 (4,5,3,4) + + + X + X X X tmp := (hl), ((c)) := tmp, hl += 1,

b -= 1 => flags, nf := tmp.7, tmp2 = tmp + l,

pf := parity of [[tmp2 AND 0x07] XOR b],

hf := cf := tmp2 > 255

I/O Output and Increment
otir 11101101 10110011 6/5 21/16 (4,5,3,4,5)/(4,5,3,4) + + + X + X X X outi, if b <> 0 then pc -= 2 I/O Output and Increment, Repeat

Letter P

Instruction Opcode NOPs Cycles S Z 5 H 3 P N C Effect Description
pop P 11pp0001 3 10 (4,3,3) - - - - - - - - P := (sp), sp += 2 Pop a value from the stack
pop I 11i11101 11100001 4 14 (4,4,3,3) - - - - - - - - I := (sp), sp += 2
push P 11pp0101 4 11 (5,3,3) - - - - - - - - sp -= 2, (sp) := P Push a value onto the stack
push I 11i11101 11100101 5 15 (4,5,3,3) - - - - - - - - sp -= 2, (sp) := I

Letter R

Instruction Opcode NOPs Cycles S Z 5 H 3 P N C Effect Description
res B,R 11001011 10bbbrrr 2 8 (4,4) - - - - - - - - R := R AND ~[1 << B] Reset Bit
res B,(hl) 11001011 10bbb110 4 15 (4,4,4,3) - - - - - - - - (hl) := (hl) AND ~[1 << B]
res B,(I+D) 11i11101 11001011 dddddddd 10bbb110 7 23 (4,4,3,5,4,3) - - - - - - - - (I+D) := (I+D) AND ~[1 << B]
res B,(I+D)->R 11i11101 11001011 dddddddd 10bbbrrr 7 23 (4,4,3,5,4,3) - - - - - - - - (I+D) := R := (I+D) AND ~[1 << B]
ret 11001001 3 10 (4,3,3) - - - - - - - - pc := (sp), sp += 2 Return
ret C 11ccc000 4/2 11/5 (5,3,3)/(5) - - - - - - - - if C then pc := (sp), sp += 2 Conditional Return
reti 11101101 01001101 4 14 (4,4,3,3) - - - - - - - - pc := (sp), sp += 2, iff1 := iff2 Return from Interrupt
retn 11101101 01***101 4 14 (4,4,3,3) - - - - - - - - pc := (sp), sp += 2, iff1 := iff2 Return from NMI
rla 00010111 1 4 (4) - - + 0 + - 0 X ocf := cf, cf := a.7, a := [a << 1] + ocf Rotate Left Accumulator
rl R 11001011 00010rrr 2 8 (4,4) + + + 0 + P 0 X ocf := cf, cf := R.7, R := [R << 1] + ocf Rotate Left
rl (hl) 11001011 00010110 4 15 (4,4,4,3) + + + 0 + P 0 X ocf := cf, cf := (hl).7, (hl) := [(hl) << 1] + ocf
rl (I+D) 11i11101 11001011 dddddddd 00010110 7 23 (4,4,3,5,4,3) + + + 0 + P 0 X ocf := cf, cf := (I+D).7, (I+D) := [(I+D) << 1] + ocf
rl (I+D)->R 11i11101 11001011 dddddddd 00010rrr 7 23 (4,4,3,5,4,3) + + + 0 + P 0 X ocf := cf, cf := (I+D).7, (I+D) := R := [(I+D) << 1] + ocf
rlca 00000111 1 4 (4) - - + 0 + - 0 X cf := a.7, a := [a << 1] + cf Rotate Left Carry Accumulator
rlc R 11001011 00000rrr 2 8 (4,4) + + + 0 + P 0 X cf := R.7, R := [R << 1] + cf Rotate Left Carry
rlc (hl) 11001011 00000110 4 15 (4,4,4,3) + + + 0 + P 0 X cf := (hl).7, (hl) := [(hl) << 1] + cf
rlc (I+D) 11i11101 11001011 dddddddd 00000110 7 23 (4,4,3,5,4,3) + + + 0 + P 0 X cf := (I+D).7, (I+D) := [(I+D) << 1] + cf
rlc (I+D)->R 11i11101 11001011 dddddddd 00000rrr 7 23 (4,4,3,5,4,3) + + + 0 + P 0 X cf := (I+D).7, (I+D) := R := [(I+D) << 1] + cf
rld 11101101 01101111 5 18 (4,4,3,4,3) + + + 0 + P 0 - tmp := [(hl) << 4] + [a AND 0x0f], (hl) := tmp,

a := [a AND 0xf0] + [tmp >> 8] => flags

Rotate Left Decimal
rra 00011111 1 4 (4) - - + 0 + - 0 X ocf := cf, cf := a.0, a := [a >> 1] + [ocf << 7] Rotate Right Accumulator
rr R 11001011 00011rrr 2 8 (4,4) + + + 0 + P 0 X ocf := cf, cf := R.0, R := [R >> 1] + [ocf << 7] Rotate Right
rr (hl) 11001011 00011110 4 15 (4,4,4,3) + + + 0 + P 0 X ocf := cf, cf := (hl).0, (hl) := [(hl) >> 1] + [ocf << 7]
rr (I+D) 11i11101 11001011 dddddddd 00011110 7 23 (4,4,3,5,4,3) + + + 0 + P 0 X ocf := cf, cf := (I+D).0, (I+D) := [(I+D) >> 1] + [ocf << 7]
rr (I+D)->R 11i11101 11001011 dddddddd 00011rrr 7 23 (4,4,3,5,4,3) + + + 0 + P 0 X ocf := cf, cf := (I+D).0, (I+D) := R := [(I+D) >> 1] + [ocf << 7]
rrca 00001111 1 4 (4) - - + 0 + - 0 X cf := a.0, a := [a >> 1] + [cf << 7] Rotate Right Carry Accumulator
rrc R 11001011 00001rrr 2 8 (4,4) + + + 0 + P 0 X cf := R.0, R := [R >> 1] + [cf << 7] Rotate Right Carry
rrc (hl) 11001011 00001110 4 15 (4,4,4,3) + + + 0 + P 0 X cf := (hl).0, (hl) := [(hl) >> 1] + [cf << 7]
rrc (I+D) 11i11101 11001011 dddddddd 00001110 7 23 (4,4,3,5,4,3) + + + 0 + P 0 X cf := (I+D).0, (I+D) := [(I+D) >> 1] + [cf << 7]
rrc (I+D)->R 11i11101 11001011 dddddddd 00001rrr 7 23 (4,4,3,5,4,3) + + + 0 + P 0 X cf := (I+D).0, (I+D) := R := [(I+D) >> 1] + [cf << 7]
rrd 11101101 01100111 5 18 (4,4,3,4,3) + + + 0 + P 0 - tmp := (hl), (hl) := [tmp >> 4] + [[a AND 0x0f] << 4],

a := [a AND 0xf0] + [tmp AND 0x0f] => flags

Rotate Right Decimal
rst S 11sss111 4 11 (5,3,3) - - - - - - - - sp -= 2, (sp) := pc, pc := S Restart

Letter S

Instruction Opcode NOPs Cycles S Z 5 H 3 P N C Effect Description
sbc a,R 10011rrr 1 4 (4) + + + + + V 1 + a -= R + cf Subtract with Carry
sbc a,J 11i11101 1001110b 2 8 (4,4) + + + + + V 1 + a -= J + cf
sbc a,N 11011110 nnnnnnnn 2 7 (4,3) + + + + + V 1 + a -= N + cf
sbc a,(hl) 10011110 2 7 (4,3) + + + + + V 1 + a -= (hl) + cf
sbc a,(I+D) 11i11101 10011110 dddddddd 5 19 (4,4,3,5,3) + + + + + V 1 + a -= (I+D) + cf
sbc hl,Q 11101101 01qq0010 4 15 (4,4,4,3) + + + + + V 1 + hl -= Q + cf
scf 00110111 1 4 (4) - - A 0 A - 0 1 nothing else Set Carry Flag
set B,R 11001011 11bbbrrr 2 8 (4,4) - - - - - - - - R := R OR [1 << B] Set Bit
set B,(hl) 11001011 11bbb110 4 15 (4,4,4,3) - - - - - - - - (hl) := (hl) OR [1 << B]
set B,(I+D) 11i11101 11001011 dddddddd 11bbb110 7 23 (4,4,3,5,4,3) - - - - - - - - (I+D) := (I+D) OR [1 << B]
set B,(I+D)->R 11i11101 11001011 dddddddd 11bbbrrr 7 23 (4,4,3,5,4,3) - - - - - - - - (I+D) := R := (I+D) OR [1 << B]
sla R 11001011 00100rrr 2 8 (4,4) + + + 0 + P 0 X cf := R.7, R := R << 1 Shift Left Arithmetic
sla (hl) 11001011 00100110 4 15 (4,4,4,3) + + + 0 + P 0 X cf := (hl).7, (hl) := (hl) << 1
sla (I+D) 11i11101 11001011 dddddddd 00100110 7 23 (4,4,3,5,4,3) + + + 0 + P 0 X cf := (I+D).7, (I+D) := (I+D) << 1
sla (I+D)->R 11i11101 11001011 dddddddd 00100rrr 7 23 (4,4,3,5,4,3) + + + 0 + P 0 X cf := (I+D).7, (I+D) := R := (I+D) << 1
sra R 11001011 00101rrr 2 8 (4,4) + + + 0 + P 0 X cf := R.0, R := R >> 1, R.7 := R.6 Shift Right Arithmetic
sra (hl) 11001011 00101110 4 15 (4,4,4,3) + + + 0 + P 0 X cf := (hl).0, (hl) := (hl) >> 1, (hl).7 := (hl).6
sra (I+D) 11i11101 11001011 dddddddd 00101110 7 23 (4,4,3,5,4,3) + + + 0 + P 0 X cf := (I+D).0,

(I+D) := (I+D) >> 1, (I+D).7 := (I+D).6

sra (I+D)->R 11i11101 11001011 dddddddd 00101rrr 7 23 (4,4,3,5,4,3) + + + 0 + P 0 X cf := (I+D).0,

tmp := (I+D) >> 1, tmp.7 := tmp.6,

(I+D) := R := tmp

sll R 11001011 00110rrr 2 8 (4,4) + + + 0 + P 0 X cf := R.7, R := [R << 1] + 1 Shift Left Logical
sll (hl) 11001011 00110110 4 15 (4,4,4,3) + + + 0 + P 0 X cf := (hl).7, (hl) := [(hl) << 1] + 1
sll (I+D) 11i11101 11001011 dddddddd 00110110 7 23 (4,4,3,5,4,3) + + + 0 + P 0 X cf := (I+D).7, (I+D) := [(I+D) << 1] + 1
sll (I+D)->R 11i11101 11001011 dddddddd 00110rrr 7 23 (4,4,3,5,4,3) + + + 0 + P 0 X cf := (I+D).7, (I+D) := R := [(I+D) << 1] + 1
srl R 11001011 00111rrr 2 8 (4,4) 0 + + 0 + P 0 X cf := R.0, R := R >> 1 Shift Right Logical
srl (hl) 11001011 00111110 4 15 (4,4,3) 0 + + 0 + P 0 X cf := (hl).0, (hl) := (hl) >> 1
srl (I+D) 11i11101 11001011 dddddddd 00111110 7 23 (4,4,3,5,4,3) 0 + + 0 + P 0 X cf := (I+D).0, (I+D) := (I+D) >> 1
srl (I+D)->R 11i11101 11001011 dddddddd 00111rrr 7 23 (4,4,3,5,4,3) 0 + + 0 + P 0 X cf := (I+D).0, (I+D) := R := (I+D) >> 1
sub R 10010rrr 1 4 (4) + + + + + V 1 + a -= R Subtract
sub J 11i11101 1001010b 2 8 (4,4) + + + + + V 1 + a -= J
sub N 11010110 nnnnnnnn 2 7 (4,3) + + + + + V 1 + a -= N
sub (hl) 10010110 2 7 (4,3) + + + + + V 1 + a -= (hl)
sub (I+D) 11i11101 10010110 dddddddd 5 19 (4,4,3,5,3) + + + + + V 1 + a -= (I+D)

Letter X

Instruction Opcode NOPs Cycles S Z 5 H 3 P N C Effect Description
xor R 10101rrr 1 4 (4) + + + 0 + P 0 0 a := a XOR R Logical eXclusive OR
xor J 11i11101 1010110b 2 8 (4,4) + + + 0 + P 0 0 a := a XOR J
xor N 11101110 nnnnnnnn 2 7 (4,3) + + + 0 + P 0 0 a := a XOR N
xor (hl) 10101110 2 7 (4,3) + + + 0 + P 0 0 a := a XOR (hl)
xor (I+D) 11i11101 10101110 dddddddd 5 19 (4,4,3,5,3) + + + 0 + P 0 0 a := a XOR (I+D)


Timings

On CPC, bus arbitration is done on every CPU bus access. On MSX, bus arbitration only applies to M1 machine cycles but access to VRAM has other limitations. On ZX Spectrum, bus arbitration is done not by using the /WAIT pin but by disabling the CPU clock when needed.

The NOPs column corresponds to CPC timings, which account for the bus arbitration managed by the Gate Array. The NOP instruction takes 4 cycles. This is the minimum amount of cycles an instruction can take.

Every M-cycle that involves a memory or I/O access will be stretched due to bus arbitration. But beware, some M-cycles are purely internal and don't involve a memory or I/O access.

Nevertheless, a few CPC timings can appear surprising at first glance:

  • Instructions LD (IX+d),r and LD (IX+d),n take 5 and 6 NOPs respectively, even though they are both listed as 19 (4,4,3,5,3) cycles in the datasheet. This happens because LD (IX+d),r has one less memory access operation to do compared to LD (IX+d),n as it does not have to fetch its operand from memory.
  • Instructions IN r,(C) and OUT (C),r take 4 NOPs with CPC timings, even though they are listed as 12 (4,4,4) cycles in the datasheet. This happens because I/O access is not aligned with memory access. On Zilog manual, it is precised that one wait-state TW is automatically inserted after T2 on I/O access.

The CPC timings of some instructions will be altered if an interrupt happens. The interrupt test occurs on the last T-State of the instruction, and if it's low, the Z80 will insert 2 wait states to acknowledge the interrupt.

So, instructions which end in the third or fourth T-State relative to the read alignment for the next instruction fetch will be delayed by an extra 4 T-States. The few instructions which end in the first or second T-State won't since the first instruction fetch/read in the interrupt won't be delayed an extra 4 T-States. Source


Opcodes

The Z80 follows a 2-3-3 opcode bit pattern.

All CB-prefixed opcodes and half of the standard opcodes (from &40 to &BF) follow a strict uniform layout. The sole exception is the HALT instruction (opcode &76), which replaces the expected LD (HL),(HL) instruction.

The rest of the opcode table is also neatly organised but in an horizontal way instead of vertical.

Any instruction in bold is undocumented by Zilog.

Standard opcodes

Opcode Mnemonic
00 NOP
01 nn LD BC,nn
02 LD (BC),A
03 INC BC
04 INC B
05 DEC B
06 n LD B,n
07 RLCA
Opcode Mnemonic
08 EX AF,AF'
09 ADD HL,BC
0A LD A,(BC)
0B DEC BC
0C INC C
0D DEC C
0E n LD C,n
0F RRCA
Opcode Mnemonic
10 e DJNZ e
11 nn LD DE,nn
12 LD (DE),A
13 INC DE
14 INC D
15 DEC D
16 n LD D,n
17 RLA
Opcode Mnemonic
18 e JR e
19 ADD HL,DE
1A LD A,(DE)
1B DEC DE
1C INC E
1D DEC E
1E n LD E,n
1F RRA
Opcode Mnemonic
20 e JR NZ,e
21 nn LD HL,nn
22 nn LD (nn),HL
23 INC HL
24 INC H
25 DEC H
26 n LD H,n
27 DAA
Opcode Mnemonic
28 e JR Z,e
29 ADD HL,HL
2A nn LD HL,(nn)
2B DEC HL
2C INC L
2D DEC L
2E n LD L,n
2F CPL
Opcode Mnemonic
30 e JR NC,e
31 nn LD SP,nn
32 nn LD (nn),A
33 INC SP
34 INC (HL)
35 DEC (HL)
36 n LD (HL),n
37 SCF
Opcode Mnemonic
38 e JR C,e
39 ADD HL,SP
3A nn LD A,(nn)
3B DEC SP
3C INC A
3D DEC A
3E n LD A,n
3F CCF
Opcode Mnemonic
40 LD B,B
41 LD B,C
42 LD B,D
43 LD B,E
44 LD B,H
45 LD B,L
46 LD B,(HL)
47 LD B,A
Opcode Mnemonic
48 LD C,B
49 LD C,C
4A LD C,D
4B LD C,E
4C LD C,H
4D LD C,L
4E LD C,(HL)
4F LD C,A
Opcode Mnemonic
50 LD D,B
51 LD D,C
52 LD D,D
53 LD D,E
54 LD D,H
55 LD D,L
56 LD D,(HL)
57 LD D,A
Opcode Mnemonic
58 LD E,B
59 LD E,C
5A LD E,D
5B LD E,E
5C LD E,H
5D LD E,L
5E LD E,(HL)
5F LD E,A
Opcode Mnemonic
60 LD H,B
61 LD H,C
62 LD H,D
63 LD H,E
64 LD H,H
65 LD H,L
66 LD H,(HL)
67 LD H,A
Opcode Mnemonic
68 LD L,B
69 LD L,C
6A LD L,D
6B LD L,E
6C LD L,H
6D LD L,L
6E LD L,(HL)
6F LD L,A
Opcode Mnemonic
70 LD (HL),B
71 LD (HL),C
72 LD (HL),D
73 LD (HL),E
74 LD (HL),H
75 LD (HL),L
76 HALT
77 LD (HL),A
Opcode Mnemonic
78 LD A,B
79 LD A,C
7A LD A,D
7B LD A,E
7C LD A,H
7D LD A,L
7E LD A,(HL)
7F LD A,A
Opcode Mnemonic
80 ADD A,B
81 ADD A,C
82 ADD A,D
83 ADD A,E
84 ADD A,H
85 ADD A,L
86 ADD A,(HL)
87 ADD A,A
Opcode Mnemonic
88 ADC A,B
89 ADC A,C
8A ADC A,D
8B ADC A,E
8C ADC A,H
8D ADC A,L
8E ADC A,(HL)
8F ADC A,A
Opcode Mnemonic
90 SUB B
91 SUB C
92 SUB D
93 SUB E
94 SUB H
95 SUB L
96 SUB (HL)
97 SUB A
Opcode Mnemonic
98 SBC A,B
99 SBC A,C
9A SBC A,D
9B SBC A,E
9C SBC A,H
9D SBC A,L
9E SBC A,(HL)
9F SBC A,A
Opcode Mnemonic
A0 AND B
A1 AND C
A2 AND D
A3 AND E
A4 AND H
A5 AND L
A6 AND (HL)
A7 AND A
Opcode Mnemonic
A8 XOR B
A9 XOR C
AA XOR D
AB XOR E
AC XOR H
AD XOR L
AE XOR (HL)
AF XOR A
Opcode Mnemonic
B0 OR B
B1 OR C
B2 OR D
B3 OR E
B4 OR H
B5 OR L
B6 OR (HL)
B7 OR A
Opcode Mnemonic
B8 CP B
B9 CP C
BA CP D
BB CP E
BC CP H
BD CP L
BE CP (HL)
BF CP A
Opcode Mnemonic
C0 RET NZ
C1 POP BC
C2 nn JP NZ,nn
C3 nn JP nn
C4 nn CALL NZ,nn
C5 PUSH BC
C6 n ADD A,n
C7 RST 00H
Opcode Mnemonic
C8 RET Z
C9 RET
CA nn JP Z,nn
CB Instruction prefix
CC nn CALL Z,nn
CD nn CALL nn
CE n ADC A,n
CF RST 08H
Opcode Mnemonic
D0 RET NC
D1 POP DE
D2 nn JP NC,nn
D3 n OUT (n),A
D4 nn CALL NC,nn
D5 PUSH DE
D6 n SUB n
D7 RST 10H
Opcode Mnemonic
D8 RET C
D9 EXX
DA nn JP C,nn
DB n IN A,(n)
DC nn CALL C,nn
DD Instruction prefix
DE n SBC A,n
DF RST 18H
Opcode Mnemonic
E0 RET PO
E1 POP HL
E2 nn JP PO,nn
E3 EX (SP),HL
E4 nn CALL PO,nn
E5 PUSH HL
E6 n AND n
E7 RST 20H
Opcode Mnemonic
E8 RET PE
E9 JP (HL)
EA nn JP PE,nn
EB EX DE,HL
EC nn CALL PE,nn
ED Instruction prefix
EE n XOR n
EF RST 28H
Opcode Mnemonic
F0 RET P
F1 POP AF
F2 nn JP P,nn
F3 DI
F4 nn CALL P,nn
F5 PUSH AF
F6 n OR n
F7 RST 30H
Opcode Mnemonic
F8 RET M
F9 LD SP,HL
FA nn JP M,nn
FB EI
FC nn CALL M,nn
FD Instruction prefix
FE n CP n
FF RST 38H

CB-prefixed opcodes

Opcode Mnemonic
00 RLC B
01 RLC C
02 RLC D
03 RLC E
04 RLC H
05 RLC L
06 RLC (HL)
07 RLC A
Opcode Mnemonic
08 RRC B
09 RRC C
0A RRC D
0B RRC E
0C RRC H
0D RRC L
0E RRC (HL)
0F RRC A
Opcode Mnemonic
10 RL B
11 RL C
12 RL D
13 RL E
14 RL H
15 RL L
16 RL (HL)
17 RL A
Opcode Mnemonic
18 RR B
19 RR C
1A RR D
1B RR E
1C RR H
1D RR L
1E RR (HL)
1F RR A
Opcode Mnemonic
20 SLA B
21 SLA C
22 SLA D
23 SLA E
24 SLA H
25 SLA L
26 SLA (HL)
27 SLA A
Opcode Mnemonic
28 SRA B
29 SRA C
2A SRA D
2B SRA E
2C SRA H
2D SRA L
2E SRA (HL)
2F SRA A
Opcode Mnemonic
30 SLL B
31 SLL C
32 SLL D
33 SLL E
34 SLL H
35 SLL L
36 SLL (HL)
37 SLL A
Opcode Mnemonic
38 SRL B
39 SRL C
3A SRL D
3B SRL E
3C SRL H
3D SRL L
3E SRL (HL)
3F SRL A
Opcode Mnemonic
40 BIT 0,B
41 BIT 0,C
42 BIT 0,D
43 BIT 0,E
44 BIT 0,H
45 BIT 0,L
46 BIT 0,(HL)
47 BIT 0,A
Opcode Mnemonic
48 BIT 1,B
49 BIT 1,C
4A BIT 1,D
4B BIT 1,E
4C BIT 1,H
4D BIT 1,L
4E BIT 1,(HL)
4F BIT 1,A
Opcode Mnemonic
50 BIT 2,B
51 BIT 2,C
52 BIT 2,D
53 BIT 2,E
54 BIT 2,H
55 BIT 2,L
56 BIT 2,(HL)
57 BIT 2,A
Opcode Mnemonic
58 BIT 3,B
59 BIT 3,C
5A BIT 3,D
5B BIT 3,E
5C BIT 3,H
5D BIT 3,L
5E BIT 3,(HL)
5F BIT 3,A
Opcode Mnemonic
60 BIT 4,B
61 BIT 4,C
62 BIT 4,D
63 BIT 4,E
64 BIT 4,H
65 BIT 4,L
66 BIT 4,(HL)
67 BIT 4,A
Opcode Mnemonic
68 BIT 5,B
69 BIT 5,C
6A BIT 5,D
6B BIT 5,E
6C BIT 5,H
6D BIT 5,L
6E BIT 5,(HL)
6F BIT 5,A
Opcode Mnemonic
70 BIT 6,B
71 BIT 6,C
72 BIT 6,D
73 BIT 6,E
74 BIT 6,H
75 BIT 6,L
76 BIT 6,(HL)
77 BIT 6,A
Opcode Mnemonic
78 BIT 7,B
79 BIT 7,C
7A BIT 7,D
7B BIT 7,E
7C BIT 7,H
7D BIT 7,L
7E BIT 7,(HL)
7F BIT 7,A
Opcode Mnemonic
80 RES 0,B
81 RES 0,C
82 RES 0,D
83 RES 0,E
84 RES 0,H
85 RES 0,L
86 RES 0,(HL)
87 RES 0,A
Opcode Mnemonic
88 RES 1,B
89 RES 1,C
8A RES 1,D
8B RES 1,E
8C RES 1,H
8D RES 1,L
8E RES 1,(HL)
8F RES 1,A
Opcode Mnemonic
90 RES 2,B
91 RES 2,C
92 RES 2,D
93 RES 2,E
94 RES 2,H
95 RES 2,L
96 RES 2,(HL)
97 RES 2,A
Opcode Mnemonic
98 RES 3,B
99 RES 3,C
9A RES 3,D
9B RES 3,E
9C RES 3,H
9D RES 3,L
9E RES 3,(HL)
9F RES 3,A
Opcode Mnemonic
A0 RES 4,B
A1 RES 4,C
A2 RES 4,D
A3 RES 4,E
A4 RES 4,H
A5 RES 4,L
A6 RES 4,(HL)
A7 RES 4,A
Opcode Mnemonic
A8 RES 5,B
A9 RES 5,C
AA RES 5,D
AB RES 5,E
AC RES 5,H
AD RES 5,L
AE RES 5,(HL)
AF RES 5,A
Opcode Mnemonic
B0 RES 6,B
B1 RES 6,C
B2 RES 6,D
B3 RES 6,E
B4 RES 6,H
B5 RES 6,L
B6 RES 6,(HL)
B7 RES 6,A
Opcode Mnemonic
B8 RES 7,B
B9 RES 7,C
BA RES 7,D
BB RES 7,E
BC RES 7,H
BD RES 7,L
BE RES 7,(HL)
BF RES 7,A
Opcode Mnemonic
C0 SET 0,B
C1 SET 0,C
C2 SET 0,D
C3 SET 0,E
C4 SET 0,H
C5 SET 0,L
C6 SET 0,(HL)
C7 SET 0,A
Opcode Mnemonic
C8 SET 1,B
C9 SET 1,C
CA SET 1,D
CB SET 1,E
CC SET 1,H
CD SET 1,L
CE SET 1,(HL)
CF SET 1,A
Opcode Mnemonic
D0 SET 2,B
D1 SET 2,C
D2 SET 2,D
D3 SET 2,E
D4 SET 2,H
D5 SET 2,L
D6 SET 2,(HL)
D7 SET 2,A
Opcode Mnemonic
D8 SET 3,B
D9 SET 3,C
DA SET 3,D
DB SET 3,E
DC SET 3,H
DD SET 3,L
DE SET 3,(HL)
DF SET 3,A
Opcode Mnemonic
E0 SET 4,B
E1 SET 4,C
E2 SET 4,D
E3 SET 4,E
E4 SET 4,H
E5 SET 4,L
E6 SET 4,(HL)
E7 SET 4,A
Opcode Mnemonic
E8 SET 5,B
E9 SET 5,C
EA SET 5,D
EB SET 5,E
EC SET 5,H
ED SET 5,L
EE SET 5,(HL)
EF SET 5,A
Opcode Mnemonic
F0 SET 6,B
F1 SET 6,C
F2 SET 6,D
F3 SET 6,E
F4 SET 6,H
F5 SET 6,L
F6 SET 6,(HL)
F7 SET 6,A
Opcode Mnemonic
F8 SET 7,B
F9 SET 7,C
FA SET 7,D
FB SET 7,E
FC SET 7,H
FD SET 7,L
FE SET 7,(HL)
FF SET 7,A

ED-prefixed opcodes

The opcodes that are not mentioned in the following table are EDNOP (ED-prefixed NOP instruction). Thay have no effect but take 8 cycles and increment the register R two times. EDED, EDDD, EDFD and EDCB are also EDNOP instructions.

Opcode Mnemonic
40 IN B,(C)
41 OUT (C),B
42 SBC HL,BC
43 nn LD (nn),BC
44 NEG
45 RETN
46 IM 0
47 LD I,A
Opcode Mnemonic
48 IN C,(C)
49 OUT (C),C
4A ADC HL,BC
4B nn LD BC,(nn)
4C NEG
4D RETI
4E IM 0
4F LD R,A
Opcode Mnemonic
50 IN D,(C)
51 OUT (C),D
52 SBC HL,DE
53 nn LD (nn),DE
54 NEG
55 RETN
56 IM 1
57 LD A,I
Opcode Mnemonic
58 IN E,(C)
59 OUT (C),E
5A ADC HL,DE
5B nn LD DE,(nn)
5C NEG
5D RETN
5E IM 2
5F LD A,R
Opcode Mnemonic
60 IN H,(C)
61 OUT (C),H
62 SBC HL,HL
63 nn LD (nn),HL
64 NEG
65 RETN
66 IM 0
67 RRD
Opcode Mnemonic
68 IN L,(C)
69 OUT (C),L
6A ADC HL,HL
6B nn LD HL,(nn)
6C NEG
6D RETN
6E IM 0
6F RLD
Opcode Mnemonic
70 IN F,(C)
71 OUT (C),0
72 SBC HL,SP
73 nn LD (nn),SP
74 NEG
75 RETN
76 IM 1
77 EDNOP
Opcode Mnemonic
78 IN A,(C)
79 OUT (C),A
7A ADC HL,SP
7B nn LD SP,(nn)
7C NEG
7D RETN
7E IM 2
7F EDNOP
Opcode Mnemonic
A0 LDI
A1 CPI
A2 INI
A3 OUTI
Opcode Mnemonic
A8 LDD
A9 CPD
AA IND
AB OUTD
Opcode Mnemonic
B0 LDIR
B1 CPIR
B2 INIR
B3 OTIR
Opcode Mnemonic
B8 LDDR
B9 CPDR
BA INDR
BB OTDR

Notes:

  • The opcode ED70 reads the port indicated by the register C without keeping the result but modifies the register F
  • The opcode ED71 corresponds to the instruction OUT (C),255 on a CMOS Z80

DD or FD-prefixed opcodes

If an opcode is prefixed by DD, the instruction is changed as follows:

  • HL is replaced by IX
  • H is replaced by IXH
  • L is replaced by IXL
  • (HL) is replaced by (IX+d)

Same for the FD prefix but with IY instead of IX.

There are 3 exceptions:

  • In the instruction EX DE,HL, HL will not be replaced with IX or IY. The EXX instruction is not affected either.
  • If (HL) and L or H are used in the same instruction, L and H are not replaced with IXL or IXH. For instance LD L,(IX+d) stores the content of (IX+d) into L, not IXL.
  • If the next byte is a DD, ED or FD prefix, the current DD or FD prefix is ignored (it's equivalent to a NONI) and processing continues with the next byte. ED-prefixed opcodes cannot be altered by DD or FD prefixes.

DDCB or FDCB-prefixed opcodes

When a DD or FD prefix is followed by a CB byte, the CB acts as a second prefix. A mandatory displacement byte comes next, and then the actual opcode.

If the instruction produces output other than in the flags (i.e. all except BIT), then the result gets placed both into (IX+d) or (IY+d) and into the register one would normally expect to be altered.

DDCB and FDCB-prefixed instructions only increment the R register twice. Source


Oddities

  • RETI and RETN are identical instructions Source. The only reason for RETI is so that some other hardware can detect the specific case of returning from the interrupt, by detecting the RETI opcode on the data bus.
  • EI has a 1-instruction delay. It is necessary for doing EI/RETI without any danger of nested interrupt routines.
  • At the end of an NMI service routine, the earliest moment a maskable interrupt will be triggered is at the end of the instruction following RETN. Source
  • RST instructions are just a CALL instruction to a fixed address baked in the instruction itself.
  • Despite what the syntax of the instructions JP (HL/IX/IY) suggests, PC will be loaded with the contents of the register itself, not the indexed value. Those instructions should be understood as JP HL/IX/IY.
  • The 16-bit commands ADD HL,ss, ADC HL,ss and SBC HL,ss exist but not the command SUB HL,ss.
  • While the syntax of the 8-bit ADD, ADC and SBC instructions all explicitly mention the A register, the SUB instruction does not mention it. On the Zilog eZ80, the SUB instruction explicitly mention the A register.
  • IN r,(C) and OUT (C),r instructions syntax is misleading as these instructions actually use the full 16-bit port address contained in BC. On the Zilog eZ80, these instructions are correctly named IN, r,(BC) and OUT (BC),r.
  • The Amstrad engineers chose to use the high byte of the address (register B) for chip selection instead of the low byte (register C) in I/O operations. As a result, OTIR / OTDR / INIR / INDR instructions cannot be used on Amstrad CPC for transferring or reading a sequence of values on a port as they use B as a counter.
  • INI/IND/INIR/INDR decrease B after storing the byte from the hardware port into memory. And OUTI/OUTD/OTIR/OTDR decrease B before sending the memory byte to the hardware port. Source
  • All PUSH and POP instructions utilize a 16-bit operand and the high-order byte is always pushed first and popped last. PUSH HL is PUSH H then L. POP HL is POP L then H.
  • When an LDxR / CPxR / INxR / OTxR instruction is interrupted, the interrupt handler sees some flags in a different state. Source
  • LD A,I and LD A,R normally copy the state of IFF2 to the Parity flag. NMOS Z80 suffers a problem whereby LD A,I and LD A,R record the state of IFF2 after it has been reset if an interrupt is delivered during that instruction. Source


Block Diagram

Z80 Block Diagram.gif


CPU Pinout

Z80 Pins.png

Note: A reset disables the maskable interrupt, selects interrupt mode 0, zeroes registers I & R and zeroes the program counter (PC).


Chip Variants

The GBZ80 (Sharp SM83) that powers the original Nintendo GameBoy is an in-between the Intel 8080 and Z80. Source

The ASCII R800 that powers the MSX TurboR is a seriously beefed up version of the Z80:

  • The ALU of the R800 is 16-bit instead of 4-bit for the Z80. This change allows instructions that were being executed in 4 clocks to be done in 1 clock.
  • The instruction set of the R800 is almost identical to the Z80. Only 2 instructions have been added: MULUB and MULUW. And many of the undocumented instructions of the Z80 were made official.

Zilog itself offers the eZ80 processor, a binary-compatible upgrade of the Z80, which runs at up to 50MHz but performs like a 150MHz Z80 due to being 3 times faster at the same clock speed.


Manuals


Weblinks