I am writing a Z80 emulator and I am confused as to how large the instruction register is.
In the Z80 manual it states that the instructions are from 1 to 4 bytes long, am I given to assume that the Z80 has a 32Bit instruction register? If not then how does it execute instructions like this?
There's no instruction register, and you don't fetch the entire instruction at once. Instead, you fetch it piece-by-piece.
Let's walk through your example instruction:
LD (IX+d),n
with the encoding 0xDD 0x36 dd nn
.dd
and nn
bytes, writes nn
to (IX+dd)
, increments the cycle counter and proceeds to the next instruction.If you want to write a cycle-accurate emulator things get a bit more complicated, but I wouldn't recommend that if you're a beginner when it comes to emulation.