# `cpdr`

[Z80 Documentation](https://asm-editor.specy.app/documentation/z80.md) › [Instructions](https://asm-editor.specy.app/documentation/z80/instruction.md)

Web page: https://asm-editor.specy.app/documentation/z80/instruction/cpdr

**Compare, decrement and repeat**

Category: Block and string

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

## Flags

| Flag | Effect |
| --- | --- |
| S | set from the result |
| Z | set from the result |
| H | set from the result |
| P/V | changed in a way of its own, as the form says |
| N | always 1 |
| C | 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.

## Example

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