dec
Decrement by 1
Subtracts 1 from the operand and stores the result there, leaving the carry flag unchanged.
8086 and latertakes lock
Used in
- Loopsx86-64 assembly
- Arithmetic, logic and bitsx86-64 assembly
- Arrays, strings and the string instructionsx86-64 assembly
- call, ret and the System V conventionx86-64 assembly
- Length of a stringx86-64 assembly
- Reverse a string in placex86-64 assembly
- Even or odd, count the set bits, multiply by shiftingx86-64 assembly
- Recursion: factorial and Fibonaccix86-64 assembly
- Bubble sortx86-64 assembly
- Print an unsigned number in bases 2 through 36x86-64 assembly
CFPFAFZFSFDFOF –●●●●–●
- ● set from the result
- – not changed
Forms
Operands
r/m- A general-purpose register or memory location matching the operation’s size, for example
raxorqword [rbp-8]. The byte registersah,bh,chanddhcannot be used with a REX prefix, including when the memory address usesr8–r15.
It does not affect the
carry flag: to affect the carry flag, use SUB something,1. 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.
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