Assembly
Quick references
These notes target Linux on x86-64 (AMD64), using Intel syntax with the GNU assembler (as). Keep in mind that assembler syntax and directives may differ when using another assembler, such as NASM, or when targeting a different CPU architecture.
Registers
| Register | Common role | Important details |
|---|---|---|
rax |
|
Caller-saved |
rbx |
General-purpose storage | Callee-saved |
rcx |
|
|
rdx |
|
Caller-saved |
rsi |
|
Caller-saved |
rdi |
|
Caller-saved |
rsp |
Stack pointer | Must be restored before returning from a function |
rbp |
General-purpose or optional frame pointer | Callee-saved |
r8 |
|
Caller-saved |
r9 |
|
Caller-saved |
r10 |
Fourth syscall argument |
Caller-saved |
r11 |
Temporary value |
|
r12-r15 |
Long-lived general-purpose values | Callee-saved |
rip |
Address of the next instruction | Changed by jumps, calls, returns and exceptions |
rflags |
Condition and control flags | Read by conditional jumps and setcc |
Partial register access
| 64-bit | Low 32-bit | Low 16-bit | High 8-bit | Low 8-bit |
|---|---|---|---|---|
rax |
eax |
ax |
ah |
al |
rbx |
ebx |
bx |
bh |
bl |
rcx |
ecx |
cx |
ch |
cl |
rdx |
edx |
dx |
dh |
dl |
rsp |
esp |
sp |
spl |
|
rbp |
ebp |
bp |
bpl |
|
rsi |
esi |
si |
sil |
|
rdi |
edi |
di |
dil |
|
r8 |
r8d |
r8w |
r8b |
|
r9 |
r9d |
r9w |
r9b |
|
r10 |
r10d |
r10w |
r10b |
|
r11 |
r11d |
r11w |
r11b |
|
r12 |
r12d |
r12w |
r12b |
|
r13 |
r13d |
r13w |
r13b |
|
r14 |
r14d |
r14w |
r14b |
|
r15 |
r15d |
r15w |
r15b |
Function registers: System V AMD64
| Value | Register |
|---|---|
| Integer/pointer return value | rax |
| Argument 1 | rdi |
| Argument 2 | rsi |
| Argument 3 | rdx |
| Argument 4 | rcx |
| Argument 5 | r8 |
| Argument 6 | r9 |
| Caller-saved | rax, rcx, rdx, rsi, rdi, r8, r9, r10, r11 |
| Callee-saved | rbx, rbp, r12, r13, r14, r15 |
Linux x86-64 syscall registers
| Value | Register |
|---|---|
|
rax |
| Argument 1 | rdi |
| Argument 2 | rsi |
| Argument 3 | rdx |
| Argument 4 | r10 |
| Argument 5 | r8 |
| Argument 6 | r9 |
Operand sizes
| x86 name | Bits | Bytes | Low part of rax |
Memory specifier |
|---|---|---|---|---|
| Byte | 8 | 1 | al |
BYTE PTR |
| Word | 16 | 2 | ax |
WORD PTR |
| Doubleword | 32 | 4 | eax |
DWORD PTR |
| Quadword | 64 | 8 | rax |
QWORD PTR |
Unsigned and signed ranges
| Width | Unsigned range | Two's complement signed range |
|---|---|---|
| 8 bits | 0 to 255 | −128 to 127 |
| 16 bits | 0 to 65,535 | −32,768 to 32,767 |
| 32 bits | 0 to 4,294,967,295 | −2,147,483,648 to 2,147,483,647 |
| 64 bits | 0 to 18,446,744,073,709,551,615 | −9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
Assembler directives
| Directive | Purpose | Example |
|---|---|---|
.section |
Select a section | .section .rodata |
.global |
Export a symbol | .global solve |
.type |
Attach a symbol type | .type solve, @function |
.byte |
Emit one or more bytes | .byte 0x41, 0x42 |
.word |
Emit 16-bit values | .word 0x1234 |
.long |
Emit 32-bit values | .long 0x12345678 |
.quad |
Emit 64-bit values | .quad 0x1122334455667788 |
.ascii |
Emit string bytes without terminating zero | .ascii "Hello\n" |
.asciz |
Emit string bytes followed by a zero byte | .asciz |
.equ /.set |
Define aan assembly-time constant | .equ BUFFER_SIZE, 128 |
Last updated: