add
Adds the source (second) operand to the destination (first) operand and leaves the sum in the destination.
8086 and later
- Getting started with x86-64x86-64 assembly
- Memory, little endian and sizesx86-64 assembly
- Bytes, words, dwords and qwordsx86-64 assembly
- The x86-64 instruction setx86-64 assembly
- The flags registerx86-64 assembly
- Loopsx86-64 assembly
- Arithmetic, logic and bitsx86-64 assembly
- Arrays, strings and the string instructionsx86-64 assembly
- The stack, push and popx86-64 assembly
- call, ret and the System V conventionx86-64 assembly
- ● depends on 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]. reg- A general-purpose register matching the operation’s size, for example
al,ax,eaxorrax. imm- An immediate value: a constant written in the instruction as a number, a character or a label, for example
10,0x1f,'a'ormsg. Open a row to see the size it has in each form, such asimm8orimm32. acc- The accumulator:
al,ax,eaxorrax, whichever matches the operation’s size. The form accepts no other register in this position.
CF reports unsigned carry; OF reports signed overflow.
The destination is a register or memory operand; the source is a register, memory operand or immediate, with at most one memory operand. Register and memory operands have the same width. When the instruction writes a 32-bit register, that write clears the upper half of its 64-bit register.
An 8-bit immediate used with a wider operand is sign-extended from −128 through 127. For a 64-bit operation, the longer immediate field is only 32 bits and is also sign-extended; there is no full 64-bit immediate form. The encoded bits determine the value used by the operation. For example, a 32-bit field of 0xffffffff becomes 0xffffffffffffffff (−1), not positive 4294967295. An out-of-range constant can produce a warning and truncated bits; use a register for a value that cannot be represented by these sign extensions.
NASM normally chooses the short immediate encoding when it preserves the value; a byte qualifier is not required. strict with an immediate size can prevent that shortening.
global _start
section .text
_start:
mov rax, 12
mov rbx, 5
mov rcx, 3
mov rsi, 9
add rax, rbx
mov rax, 60 ; syscall 60: exit
xor rdi, rdi
syscall