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.

  • 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. – Wayne Conrad Feb 17 at 21:26
  • 4
    Good first question, by the way. It's an interesting question and you've stated it well. Welcome! – Wayne Conrad Feb 17 at 21:27
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.

| improve this answer | |
3

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.