x86 ISA
Introduction
This blog post provides a summary of x86-64 assembly language, covering instruction sets, registers, addressing modes, and calling conventions essential for understanding low-level system programming.
Registers
General Purpose Registers
x86-64 provides 16 general-purpose registers, each accessible at multiple sizes: 64-bit, 32-bit, 16-bit, and 8-bit. Registers serve specific roles in the calling convention: argument passing, return values, and preservation across function calls.

Figure: x86-64 general-purpose registers showing different sizes and their roles in the calling convention.
Argument registers: The first six function arguments are passed in %rdi, %rsi, %rdx, %rcx, %r8, and %r9. The return value is stored in %rax.
Callee-saved registers: %rbx, %rbp, and %r12 through %r15 must be preserved by callee functions. If a function modifies these registers, it must save and restore their values.
Caller-saved registers: %rax, %rcx, %rdx, %r8, %r9, %r10, and %r11 may be modified by callee functions. Callers must save these values if they need to be preserved across function calls.
Special registers: %rsp is the stack pointer, pointing to the top of the stack. %rbp base pointer is typically used as a frame pointer, though it can be used as a general-purpose callee-saved register.
Flags Register
The flags register (RFLAGS) contains condition codes that are set by arithmetic and logical operations. These flags enable conditional branching and overflow detection.
| Flag | Name | Description | Condition for |
|---|---|---|---|
| CF | Carry flag | The most recent operation generated a carry out of the most significant bit | (unsigned overflow) |
| ZF | Zero flag | The most recent operation yielded zero | |
| SF | Sign flag | The most recent operation yielded a negative value | |
| OF | Overflow flag | The most recent operation caused a two’s-complement overflow | (signed overflow) |
The carry flag (CF) detects overflow for unsigned operations, while the overflow flag (OF) detects two’s-complement signed overflow.
Addressing Modes
x86-64 supports three types of operands: immediate values, register contents, and memory references. The most general form for memory addressing combines an immediate offset, base register, index register, and scale factor:
where Imm is an immediate constant, is the base register value, is the index register value, and is a scale factor (1, 2, 4, or 8). This form is commonly used for array element access.
| Type | Form | Operand Value | Name |
|---|---|---|---|
| Immediate | $ | Imm | Immediate |
| Register | Register | ||
| Memory | Absolute | ||
| Memory | Indirect | ||
| Memory | Base + displacement | ||
| Memory | Indexed | ||
| Memory | Indexed | ||
| Memory | Scaled indexed | ||
| Memory | Scaled indexed | ||
| Memory | Scaled indexed | ||
| Memory | Scaled indexed |
Summary: Immediate operands are prefixed with $ in AT&T syntax. Register operands access register contents directly. Memory addressing modes compute an effective address to access memory locations.
The general form allows flexible address computation by combining displacement, base, index, and scaling, making it ideal for array indexing and structure member access. Simpler addressing modes are special cases where some components are omitted.
Instructions
Data Movement
Data movement instructions transfer values between registers and memory. The move instructions support different operand sizes, indicated by the suffix.
| Instruction | Effect | Description |
|---|---|---|
| MOV | Move | |
| movb | Move byte | |
| movw | Move word | |
| movl | Move double word | |
| movq | Move quad word | |
| movabsq | Move absolute quad word |
When moving 32-bit data to a 64-bit register using movl, the high 32 bits of the destination register are automatically set to 0. This zero-extension behavior ensures that 32-bit values are properly extended to 64 bits.
Zero Extension
Zero-extension instructions move smaller values to larger registers by filling the upper bits with zeros. These instructions are useful when converting unsigned values to larger sizes.
| Instruction | Effect | Description |
|---|---|---|
| MOVZ | Move with zero extension | |
| movzbw | Move zero-extended byte to word | |
| movzbl | Move zero-extended byte to double word | |
| movzwl | Move zero-extended word to double word | |
| movzbq | Move zero-extended byte to quad word | |
| movzwq | Move zero-extended word to quad word |
Sign Extension
Sign-extension instructions move smaller signed values to larger registers by replicating the sign bit into the upper bits. This preserves the sign and magnitude of two’s-complement numbers.
| Instruction | Effect | Description |
|---|---|---|
| MOVS | Move with sign extension | |
| movsbw | Move sign-extended byte to word | |
| movsbl | Move sign-extended byte to double word | |
| movswl | Move sign-extended word to double word | |
| movsbq | Move sign-extended byte to quad word | |
| movswq | Move sign-extended word to quad word | |
| movslq | Move sign-extended double word to quad word | |
| cltq | %rax %eax | Sign-extend %eax to %rax |
Stack Management
Stack operations manipulate the stack pointer %rsp to push and pop quad-word values. The stack grows downward in memory.
| Instruction | Effect | Description |
|---|---|---|
| pushq | Push quad word | |
| popq | Pop quad word |
Operation order: pushq first decrements the stack pointer by 8, then writes the value to the new stack location. popq first reads the value from the current stack location, then increments the stack pointer by 8.
Arithmetic
Arithmetic and logical instructions perform computations on operands, with most instructions using the destination as both source and destination. The leaq instruction computes effective addresses without accessing memory.
| Instruction | Effect | Description |
|---|---|---|
| leaq | Load effective address | |
| INC | Increment | |
| DEC | Decrement | |
| NEG | Negate | |
| NOT | Complement | |
| ADD | Add | |
| SUB | Subtract | |
| IMUL | Multiply | |
| XOR | Exclusive Or | |
| OR | Or | |
| AND | And | |
| SAL | Left shift | |
| SHL | Left shift (same as SAL) | |
| SAR | Arithmetic right shift | |
| SHR | Logical right shift |
Special Arithmetic Operations
Multiplication and division operations that produce 128-bit results require special register usage. For 64×64-bit multiplication, one operand must be in %rax, and the 128-bit result is stored with the low 64 bits in %rax and the high 64 bits in %rdx.
| Instruction | Effect | Description |
|---|---|---|
| imulq | Signed full multiply | |
| mulq | Unsigned full multiply | |
| cqto | Convert to oct word | |
| idivq | Signed divide | |
| divq | Unsigned divide |
Multiplication: The two-operand IMUL instruction (mentioned earlier) produces a 64-bit result. For full 64×64-bit multiplication requiring a 128-bit result, use imulq or mulq with one operand in %rax. The result spans %rdx (high 64 bits) and %rax (low 64 bits).
Division: Division requires a 128-bit dividend in %rdx:%rax. The quotient is stored in %rax and the remainder in %rdx. For signed division, use cqto to sign-extend %rax into %rdx:%rax before calling idivq.
cqto: The cqto instruction sign-extends the 64-bit value in %rax to a 128-bit value spanning %rdx:%rax, preparing the dividend for signed division operations.
Branching and Control
Comparison and Test Instructions
Comparison and test instructions set condition flags without storing results, enabling conditional branching. Both instruction types modify flags but differ in their underlying operation.
| Instruction | Based on | Description |
|---|---|---|
| CMP | Compare | |
| cmpb | Compare byte | |
| cmpw | Compare word | |
| cmpl | Compare double word | |
| cmpq | Compare quad word | |
| TEST | Test | |
| testb | Test byte | |
| testw | Test word | |
| testl | Test double word | |
| testq | Test quad word |
Difference: CMP performs subtraction () to set flags based on the relationship between operands, useful for comparing values. TEST performs bitwise AND () to set flags, useful for testing specific bits or checking if a value is zero.
Conditional Set
SET instructions set a byte destination to 0 or 1 based on condition flags, enabling conditional data movement without branching.
| Instruction | Synonym | Effect | Set condition |
|---|---|---|---|
| sete | setz | Equal / zero | |
| setne | setnz | Not equal / not zero | |
| sets | Negative | ||
| setns | Nonnegative | ||
| setg | setnle | Greater (signed ) | |
| setge | setnl | Greater or equal (signed ) | |
| setl | setnge | Less (signed ) | |
| setle | setng | Less or equal (signed ) | |
| seta | setnbe | Above (unsigned ) | |
| setae | setnb | Above or equal (unsigned ) | |
| setb | setnae | Below (unsigned ) | |
| setbe | setna | Below or equal (unsigned ) |
SET instructions evaluate condition flags and set the destination byte to 1 if the condition is true, 0 otherwise. Signed comparisons use SF and OF flags, while unsigned comparisons use CF and ZF flags.
Conditional Jump
Jump instructions transfer control to a target address based on condition flags. Unconditional jumps always execute, while conditional jumps execute only when specific flag conditions are met.
| Instruction | Synonym | Jump condition | Description |
|---|---|---|---|
| jmp Label | Direct jump | ||
| jmp | Indirect jump | ||
| je Label | jz | Equal / zero | |
| jne Label | jnz | Not equal / not zero | |
| js Label | Negative | ||
| jns Label | Nonnegative | ||
| jg Label | jnle | Greater (signed ) | |
| jge Label | jnl | Greater or equal (signed ) | |
| jl Label | jnge | Less (signed ) | |
| jle Label | jng | Less or equal (signed ) | |
| ja Label | jnbe | Above (unsigned ) | |
| jae Label | jnb | Above or equal (unsigned ) | |
| jb Label | jnae | Below (unsigned ) | |
| jbe Label | jna | Below or equal (unsigned ) |
Jump instructions enable control flow by conditionally or unconditionally changing the instruction pointer. Direct jumps use a label address, while indirect jumps use an address stored in a register or memory location.
Conditional Move
Conditional move instructions transfer data from source to destination only when specific condition flags are set, enabling branchless conditional data movement for improved performance.
| Instruction | Synonym | Move condition | Description |
|---|---|---|---|
| cmove | cmovz | Equal / zero | |
| cmovne | cmovnz | Not equal / not zero | |
| cmovs | Negative | ||
| cmovns | Nonnegative | ||
| cmovg | cmovnle | Greater (signed ) | |
| cmovge | cmovnl | Greater or equal (signed ) | |
| cmovl | cmovnge | Less (signed ) | |
| cmovle | cmovng | Less or equal (signed ) | |
| cmova | cmovnbe | Above (unsigned ) | |
| cmovae | cmovnb | Above or equal (unsigned ) | |
| cmovb | cmovnae | Below (unsigned ) | |
| cmovbe | cmovna | Below or equal (unsigned ) |
Conditional move instructions provide a branchless alternative to conditional jumps followed by moves, reducing pipeline stalls and improving performance on modern processors.
Procedures
The runtime stack manages function calls, storing arguments, return addresses, saved registers, and local variables. The stack grows downward toward lower memory addresses, with %rsp pointing to the current top of the stack.
Figure: Stack frame layout showing the structure of nested function calls, with earlier frames, calling function’s frame, and executing function’s frame.
Each stack frame contains the return address, saved registers, local variables, and space for building arguments for subsequent function calls. When function P calls function Q, P’s frame includes arguments for Q, and Q’s frame contains its own local data.
| Instruction | Description |
|---|---|
| call Label | Procedure call |
| call | Procedure call |
| ret | Return from call |
The call instruction pushes the return address onto the stack and transfers control to the target procedure. The ret instruction pops the return address from the stack and resumes execution at that address.
Linux X86-64 Stack Frame
References
Bryant, R. E., & O’Hallaron, D. R. (2016). Computer Systems: A Programmer’s Perspective, Third Edition. Pearson. https://csapp.cs.cmu.edu/
CMU 15-213: Introduction to Computer Systems. Carnegie Mellon University. https://www.cs.cmu.edu/~213/
Harvard CS 61: Assembly. Harvard University. https://cs61.seas.harvard.edu/site/2025/Asm/
Intel 80386 Programmer’s Reference Manual. Intel Corporation. https://pdos.csail.mit.edu/6.828/2018/readings/i386.pdf
Last modified: 29 Nov 2026