# `cpi`

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

**Compare and increment**

Category: Block and string

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

2 bytes · 16 cycles

## Flags

| Flag | Effect |
| --- | --- |
| S | depends on the result |
| Z | depends on the result |
| H | depends on the result |
| P/V | changed as the description says |
| N | always 1 |
| C | not changed |

## Forms

- `cpi` · Compares the value of the memory location pointed to by HL with A. Then increments HL and decrements BC. Resets the parity/overflow flag if BC becomes zero, and sets it otherwise.

## Example

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