cpir

Compare, increment and repeat

Repeats CPI, scanning up 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

  • cpir

    Compares the value of the memory location pointed to by HL with A. Then HL is incremented and BC is 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
        ld bc, 4
        cpir
        halt
source: .byte 1, 2, 3, 4