14

I read here that if the Z80 encounters e.g. multiple 0xdd prefixes in sequence, for each 0xxdd except the last it acts almost like a NOP, but does not allow interrupts to occur immediately after "executing" the discarded byte.

My question is: If an instruction is prefixed by 0xdd, but not affected by the prefix (i.e. it does not act on the HL register), does the 0xdd also act like a NOP and disallow interrupts? Or is it a simple NOP in this case? Or does it not have an effect at all? The documentation I could find was not very clear on this.

2
  • 5
    I'd bet money that 0xdd always disallows interrupts, because otherwise it'd have to time travel into the following opcode to learn whether that opcode acts on the HL register. Although 0xdd is an instruction prefix, in terms of implementation I'm sure it's an actual complete opcode that sets an internal flag for the next opcode to use. That's my guess. I think it's a good guess, but not adding as an answer because it's only a guess. Feb 17, 2020 at 21:26
  • 4
    Good first question, by the way. It's an interesting question and you've stated it well. Welcome! Feb 17, 2020 at 21:27

2 Answers 2

11

The 0xDD does not allow an interrupt to happen after it's been fetched, no matter what comes next in the instruction stream.

As Wayne Conrad pointed out, otherwise the CPU would have to time travel into the future to find out what instruction is going to get fetched.

3
  • Does this mean you can use a sequence of 0xDD as a nop-sled that "disables" interrupts? Nov 12, 2021 at 2:13
  • @puppydrum64 sounds like it
    – user253751
    Nov 21, 2022 at 16:35
  • @puppydrum64 Yes, you can use a sequence of 0xDD bytes as a NOP-sled that ignores interrupts. (This source)[z80.info/decoding.htm] calls this NONI. Nov 21 at 13:35
5

The Z80 increments the program counter while it is performing an opcode fetch. As a consequence, by the time an opcode byte is fetched, the Z80 will be committed to completing the instruction before any interrupt may occur. If a DD or FD happened to be followed by an opcode byte whose meaning would not be affected by it (including another DD or FD prefix), program behavior would not be adversely affected if the Z80 were to take an interrupt before fetching the next opcode byte, but there would be no way the Z80 could know that until after the byte was fetched, rendering the question moot.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .