Decoding Instructions

How to decode instructions from binary

This section lists how the instructions are laid out at the bit level.

Normally if you are manually disassembling code you just need to use the list by Opcodes, however this section will be useful if you are implementing a Z80 emulator as you can see how the instruction decoding works including how the undocumented instructions work due to how the bits are organised.

How to use these decoding tables

To decode an opcode, convert it to binary then run through it from left to right, e.g. start at Bit 7 and move towards Bit 0.

As you run through the bits, start on the table from the top-left and go down then right as you find each bit. Bits are ordered with 0 first, then 1 & finally x which indicates that bit can be either 0 or 1.

When you find a match then go with that. If more than one entry matches then go for the one higher in the table as that will have higher precedence.

Z80 Instruction Decode table

To decode an instruction:

  • If the opcode is CB, DD, ED or FD then go to that prefix page and decode the next byte.
  • Using the table below, locate the pattern that matches the opcode. It's usually best to start from the left (bit 7) and go right until you find the opcode.

    An X means a bit that can be either 0 or 1, however check adjacent rows first and always take an entry that has a 0 or 1 as higher precedence to the X.

76543210
00000000 Nop
00001000 EX
0001x000 Flow
000xx111 Rotate
001xx111 Misc
00xx0001 LD Instructions
00xx0011 Arithmetic Instructions
00xx0100 Arithmetic Instructions
00xx0101 Arithmetic Instructions
00xx0110 LD Instructions
00xx1001 Arithmetic Instructions
00xxx000 Flow
00xxx010 LD Instructions
01110110 Halt
01xxxxxx LD Instructions
10xxxxxx Arithmetic Instructions
11000011 Flow
11001011 CB Prefix
11001101 Flow
11011001 EXX
1101x011 I/O
11101101 ED Prefix
1110x011 EX
11111001 LD Instructions
1111x011 Interrupts
11x01001 Flow
11x11101 DD FD Prefix
11xx0x01 Stack Instructions
11xxx000 Flow
11xxx010 Flow
11xxx100 Flow
11xxx110 Arithmetic Instructions
11xxx111 Flow

Notes:

  1. Halt 0x76 is where the invalid LD (HL),(HL) instruction would have been.
Last modified December 24, 2021: Add missing arithmetic in decode table (e1c0c90)