# `dec`

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

**Decrement**

Category: Arithmetic

Subtracts one from a register, register pair or the byte at (HL), leaving C unchanged.

Used in: [Registers, pairs and the shadow set](https://asm-editor.specy.app/learn/courses/z80/introduction/registers-pairs-and-the-shadow-set.md) (Z80 assembly), [Loops and djnz](https://asm-editor.specy.app/learn/courses/z80/think-in-assembly/loops-and-djnz.md) (Z80 assembly), [The screen, keyboard and mouse through ports](https://asm-editor.specy.app/learn/courses/z80/talking-to-the-outside-world/screen-keyboard-and-mouse.md) (Z80 assembly), [Reverse a string in place](https://asm-editor.specy.app/learn/courses/z80/examples/reverse-a-string.md) (Z80 assembly), [Stack arguments and a stack frame](https://asm-editor.specy.app/learn/courses/z80/examples/subroutine-with-stack-arguments.md) (Z80 assembly), [Recursion: factorial and Fibonacci](https://asm-editor.specy.app/learn/courses/z80/examples/factorial-and-fibonacci.md) (Z80 assembly), [Bubble sort](https://asm-editor.specy.app/learn/courses/z80/examples/bubble-sort.md) (Z80 assembly), [Print a number in any base without help](https://asm-editor.specy.app/learn/courses/z80/examples/number-to-string.md) (Z80 assembly), [The snake game](https://asm-editor.specy.app/learn/courses/z80/examples/snake.md) (Z80 assembly)

## Flags

| Flag | Effect |
| --- | --- |
| S | set from the result |
| Z | set from the result |
| H | set from the result |
| P/V | holds the signed overflow |
| N | always 1 |
| C | not changed |

## Forms

- `dec r` · 1 byte · 4 cycles · Subtracts one from `r`.
  - `dec b`
  - `dec c`
  - `dec d`
  - `dec e`
  - `dec h`
  - `dec l`
  - `dec a`

- `dec (hl)` · 1 byte · 11 cycles · Subtracts one from (HL).

- `dec (ix+dd)` · 3 bytes · 23 cycles · Subtracts one from the memory location pointed to by IX plus `dd`.
  - `dec (ix+dd)`
  - `dec (iy+dd)`

- `dec rr` · 1 byte · 6 cycles · Flags: S: not changed, Z: not changed, H: not changed, P/V: not changed, N: not changed, C: not changed · Subtracts one from `rr`.
  - `dec bc`
  - `dec de`
  - `dec hl`
  - `dec sp`

- `dec ix` · 2 bytes · 10 cycles · Flags: S: not changed, Z: not changed, H: not changed, P/V: not changed, N: not changed, C: not changed · Subtracts one from IX.
  - `dec ix`
  - `dec iy`

## Undocumented

Left out of Zilog's manual, but the Z80 runs them, and so does this emulator.

- `dec ixh/l` · 2 bytes · 8 cycles · Subtracts one from `ixh/l`.
  - `dec ixh`
  - `dec ixl`
  - `dec iyh`
  - `dec iyl`

## Operands

- `r`: An 8-bit register: `a`, `b`, `c`, `d`, `e`, `h` or `l`.
- [`(hl)`](https://asm-editor.specy.app/documentation/z80/registers/operand-hl.md): The byte in memory at the address stored in `hl`.
- [`(ix+dd)`](https://asm-editor.specy.app/documentation/z80/registers/operand-ix-dd.md): The byte in memory at `ix + dd`, where `dd` is a signed displacement from `-128` to `127`, for example `(ix+5)` or `(ix-3)`. `(iy+dd)` works the same way.
- `rr`: A register pair: `bc`, `de`, `hl` or `sp`.
- [`ix`](https://asm-editor.specy.app/documentation/z80/registers/register-ix.md): The `ix` index register. You can also use `iy`, with the same instruction size and timing.
- [`ixh/l`](https://asm-editor.specy.app/documentation/z80/registers/register-ixh.md): The high or low byte of `ix`: `ixh` or `ixl`. For `iy`, use `iyh` or `iyl`.

## Example

```z80
        .org 0x8000
        ld b, 3
        dec b
        halt
```
