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 bytes · 21/16 cycles21 cycles for a pass that repeats, 16 for the last

SZHP/VNC ●●●●1–
  • ● set from the result
  • 1 always 1
  • – not changed

Forms

  • cpdr

    Compares the value of the memory location pointed to by HL with A. Then HL and BC are decremented. If BC is not zero and z is not set, this operation is repeated. p/v is reset if BC becomes zero and set otherwise, acting as an indicator 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