# `cpd`

[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/cpd

**Compare and decrement**

Category: Block and string

Compares A with the byte at (HL), then decrements HL and BC, setting P/V while BC is not zero.

2 bytes · 16 cycles

## 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

- `cpd` · Compares the value of the memory location pointed to by HL with A. Then HL and BC are decremented. p/v is reset if BC becomes zero and set otherwise.

## Example

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