# `dec`

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

Web page: https://asm-editor.specy.app/documentation/x86/instruction/dec

**Decrement by 1**

Category: Arithmetic

Subtracts 1 from the operand and stores the result there, leaving the carry flag unchanged.

8086 and later · accepts the `lock` prefix with a memory operand

[Intel's reference: DEC](https://intel.github.io/SDM/instruction/DEC.html)

Used in: [Loops](https://asm-editor.specy.app/learn/courses/x86/think-in-assembly/loops.md) (x86-64 assembly), [Arithmetic, logic and bits](https://asm-editor.specy.app/learn/courses/x86/think-in-assembly/arithmetic-logic-and-bits.md) (x86-64 assembly), [Arrays, strings and the string instructions](https://asm-editor.specy.app/learn/courses/x86/think-in-assembly/arrays-strings-and-the-string-instructions.md) (x86-64 assembly), [call, ret and the System V convention](https://asm-editor.specy.app/learn/courses/x86/think-in-assembly/call-ret-and-the-system-v-convention.md) (x86-64 assembly), [Length of a string](https://asm-editor.specy.app/learn/courses/x86/examples/string-length.md) (x86-64 assembly), [Reverse a string in place](https://asm-editor.specy.app/learn/courses/x86/examples/reverse-a-string.md) (x86-64 assembly), [Even or odd, count the set bits, multiply by shifting](https://asm-editor.specy.app/learn/courses/x86/examples/bit-tricks.md) (x86-64 assembly), [Recursion: factorial and Fibonacci](https://asm-editor.specy.app/learn/courses/x86/examples/factorial-and-fibonacci.md) (x86-64 assembly), [Bubble sort](https://asm-editor.specy.app/learn/courses/x86/examples/bubble-sort.md) (x86-64 assembly), [Print an unsigned number in bases 2 through 36](https://asm-editor.specy.app/learn/courses/x86/examples/number-to-string.md) (x86-64 assembly)

## Flags

| Flag | Effect |
| --- | --- |
| CF | not changed |
| PF | depends on the result |
| AF | depends on the result |
| ZF | depends on the result |
| SF | depends on the result |
| DF | not changed |
| OF | depends on the result |

## Forms

- `dec r/m` (8, 16, 32, 64)
  - `dec r/m8`
  - `dec r/m16`
  - `dec r/m32`: 386 and later
  - `dec r/m64`

## Operands

- `r/m`: A general-purpose register or memory location matching the operation’s size, for example `rax` or `qword [rbp-8]`.

## Description

It does *not* affect the
carry flag: to affect the carry flag, use [`SUB something,1`](https://asm-editor.specy.app/documentation/x86/instruction/sub.md). `DEC` affects all the other flags according to the result.

This instruction can be used with a `LOCK` prefix to allow atomic
execution.

See also [`INC`](https://asm-editor.specy.app/documentation/x86/instruction/inc.md).

## Example

```x86
global _start

section .text
_start:
        mov rax, 12
        mov rbx, 5
        mov rcx, 3
        mov rsi, 9

        dec rax

        mov rax, 60         ; syscall 60: exit
        xor rdi, rdi
        syscall
```
