ADD
By Vesper Vei
1 minute read
Table of Contents
ADD (add)
Basic function
The ADD instruction performs addition, writing the result of x1 + x2 into x1.
At the same time, it affects multiple EFLAGS flags.
Instruction format
add x1, x2x1 = x1 + x2x1, x2 types:
- Register
- Memory
- Immediate value
(the two cannot both be memory)
Instruction execution process
x1 ← x1 + x2EFLAGS ← 根据结果更新The affected flags include:
- OF (overflow)
- SF (sign)
- ZF (zero)
- CF (carry)
- AF, PF
Example
add eax, ebx ;寄存器 寄存器add rax, 0x20. ;寄存器 立即数add [rbp-0x4], 1 ; 内存 立即数Equivalent expansion example
add rax, rbx; 等价于tmp = rax + rbxrax = tmp更新 EFLAGSCommon uses
- Pointer offset
- Incrementing, accumulation
- Integer arithmetic
- Constructing loop counters
- Stack address calculation (such as
add rsp, 0x20)