Instructions with either the DD
or FD
prefixes affect those instructions that operate
against the memory addressed by HL
,
changing them to use either the IX
or IY
registers with an offset.
Instructions that refer directly to the HL
register will then act directly against either
IX
or IY
.
For those that refer to (HL)
, i.e. the memory pointed to by HL
then the instructions use an additional relative offset that's added to either the
IX
or IY
registers, and are written as
(IX+d)
or (IY+d)
.
Instructions with the DD
prefix use the IX
register,
whilst the FD
prefix uses the IY
register.
DDCB and FDCB Prefixes
The DD
and FD
prefixes extends though the CB
prefix as it does for normal instructions.
Just like the CB prefix
The format of the instruction also changes slightly as they change the behaviour of the existing instructions with
the CB
prefix.
These instructions are all four bytes long with the third byte consisting of the offset.
For example: The RLC (HL)
is encoded as CB06.
With the DD
prefix this becomes RLC (IX+d)
but the instruction is formatted as
DDCBdd06.
With the FD
prefix this becomes RLC (IY+d)
, formatted as
FDCBdd06.
Note that the offset d
is before the final part of the operand, not after as you might expect.
Decoder
All of these have either DD or FD as the previous prefix byte and a displacement immediately after them.
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | ||
---|---|---|---|---|---|---|---|---|---|
0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | LD | |
0 | 0 | 1 | 0 | X | 0 | 1 | 1 | INC DEC | |
0 | 0 | 1 | 0 | x | x | 1 | 0 | LD | |
0 | 0 | 1 | 1 | 0 | 1 | 0 | D | IncDec | |
0 | 0 | 1 | 1 | 0 | 1 | 1 | 0 | LD | |
0 | 0 | x | x | 1 | 0 | 0 | 1 | ADD | |
0 | 1 | 0 | 0 | 0 | 1 | 0 | x | INC DEC | |
0 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | ||
0 | 1 | 1 | 1 | 0 | x | x | x | LD | |
0 | 1 | x | x | x | 1 | 1 | 0 | LD | |
1 | 0 | x | x | 0 | 1 | 1 | 0 | LD | |
1 | 1 | 0 | 0 | 1 | 0 | 1 | 1 | CB Prefix | |
1 | 1 | 1 | 0 | 0 | 0 | 1 | 1 | EX | |
1 | 1 | 1 | 0 | 0 | x | 0 | 1 | Stack Instructions | |
1 | 1 | 1 | 0 | 1 | 0 | 0 | 1 | Flow | |
1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | LD |