cpdr

Compare, decrement and repeat

Repeats CPD, scanning down memory from HL for a byte equal to A, until a match is found or BC is zero.

2 bytes21/16 cycles21 cycles each time it repeats, 16 the last time

SZHP/VNC ●●●●1–
  • ● depends on the result
  • 1 always 1
  • – not changed

Forms

  • cpdr

    Compares the value of the memory location pointed to by HL with A. Then decrements HL and BC. Repeats this operation until BC is zero or the zero flag is set. Resets the parity/overflow flag if BC becomes zero and sets it otherwise, so a set flag shows that HL reached a memory location whose value equalled A before the counter went to zero. Interrupts can trigger while this instruction is processing.

        .org 0x8000
        ld a, 3
        ld hl, source + 3
        ld bc, 4
        cpdr
        halt
source: .byte 1, 2, 3, 4