x86 ISA

Updated: 29 Nov 2026
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.

x86-64 General-Purpose Registers

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.

FlagNameDescriptionCondition for t=a+bt = a + b
CFCarry flagThe most recent operation generated a carry out of the most significant bit(unsigned)t<(unsigned)a(unsigned) t < (unsigned) a (unsigned overflow)
ZFZero flagThe most recent operation yielded zerot==0t == 0
SFSign flagThe most recent operation yielded a negative valuet<0t < 0
OFOverflow flagThe most recent operation caused a two’s-complement overflow(a<0==b<0)∧(t<0≠a<0)(a < 0 == b < 0) \land (t < 0 \neq a < 0) (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:

Effective Address=Imm+R[rb]+R[ri]×s\text{Effective Address} = \text{Imm} + R[r_b] + R[r_i] \times s

where Imm is an immediate constant, R[rb]R[r_b] is the base register value, R[ri]R[r_i] is the index register value, and ss is a scale factor (1, 2, 4, or 8). This form is commonly used for array element access.

TypeFormOperand ValueName
Immediate$ImmImmImmImmediate
Registerrar_aR[ra]R[r_a]Register
MemoryImmImmM[Imm]M[\text{Imm}]Absolute
Memory(ra)(r_a)M[R[ra]]M[R[r_a]]Indirect
MemoryImm(rb)Imm(r_b)M[Imm+R[rb]]M[\text{Imm} + R[r_b]]Base + displacement
Memory(rb,ri)(r_b, r_i)M[R[rb]+R[ri]]M[R[r_b] + R[r_i]]Indexed
MemoryImm(rb,ri)Imm(r_b, r_i)M[Imm+R[rb]+R[ri]]M[\text{Imm} + R[r_b] + R[r_i]]Indexed
Memory(,ri,s)(, r_i, s)M[R[ri]×s]M[R[r_i] \times s]Scaled indexed
MemoryImm(,ri,s)Imm(, r_i, s)M[Imm+R[ri]×s]M[\text{Imm} + R[r_i] \times s]Scaled indexed
Memory(rb,ri,s)(r_b, r_i, s)M[R[rb]+R[ri]×s]M[R[r_b] + R[r_i] \times s]Scaled indexed
MemoryImm(rb,ri,s)Imm(r_b, r_i, s)M[Imm+R[rb]+R[ri]×s]M[\text{Imm} + R[r_b] + R[r_i] \times s]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 Imm(rb,ri,s)Imm(r_b, r_i, s) 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.

InstructionEffectDescription
MOV S,DS, DD←SD \leftarrow SMove
movbMove byte
movwMove word
movlMove double word
movqMove quad word
movabsq I,RI, RR←IR \leftarrow IMove 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.

InstructionEffectDescription
MOVZ S,RS, RR←ZeroExtend(S)R \leftarrow \text{ZeroExtend}(S)Move with zero extension
movzbwMove zero-extended byte to word
movzblMove zero-extended byte to double word
movzwlMove zero-extended word to double word
movzbqMove zero-extended byte to quad word
movzwqMove 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.

InstructionEffectDescription
MOVS S,RS, RR←SignExtend(S)R \leftarrow \text{SignExtend}(S)Move with sign extension
movsbwMove sign-extended byte to word
movsblMove sign-extended byte to double word
movswlMove sign-extended word to double word
movsbqMove sign-extended byte to quad word
movswqMove sign-extended word to quad word
movslqMove sign-extended double word to quad word
cltq%rax ←SignExtend(\leftarrow \text{SignExtend}(%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.

InstructionEffectDescription
pushq SSR[rsp]←R[rsp]−8;R[\text{rsp}] \leftarrow R[\text{rsp}] - 8;
M[R[rsp]]←SM[R[\text{rsp}]] \leftarrow S
Push quad word
popq DDD←M[R[rsp]];D \leftarrow M[R[\text{rsp}]];
R[rsp]←R[rsp]+8R[\text{rsp}] \leftarrow R[\text{rsp}] + 8
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.

InstructionEffectDescription
leaq S,DS, DD←&SD \leftarrow \&SLoad effective address
INC DDD←D+1D \leftarrow D + 1Increment
DEC DDD←D−1D \leftarrow D - 1Decrement
NEG DDD←−DD \leftarrow -DNegate
NOT DDD←∼DD \leftarrow \sim DComplement
ADD S,DS, DD←D+SD \leftarrow D + SAdd
SUB S,DS, DD←D−SD \leftarrow D - SSubtract
IMUL S,DS, DD←D×SD \leftarrow D \times SMultiply
XOR S,DS, DD←D^SD \leftarrow D \mathbin{\hat{}} SExclusive Or
OR S,DS, DD←D∣SD \leftarrow D \mid SOr
AND S,DS, DD←D&SD \leftarrow D \mathbin{\&} SAnd
SAL k,Dk, DD←D≪kD \leftarrow D \ll kLeft shift
SHL k,Dk, DD←D≪kD \leftarrow D \ll kLeft shift (same as SAL)
SAR k,Dk, DD←D≫AkD \leftarrow D \gg_A kArithmetic right shift
SHR k,Dk, DD←D≫LkD \leftarrow D \gg_L kLogical 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.

InstructionEffectDescription
imulq SSR[%rdx]:R[%rax]←S×R[%rax]R[\text{\%rdx}]:R[\text{\%rax}] \leftarrow S \times R[\text{\%rax}]Signed full multiply
mulq SSR[%rdx]:R[%rax]←S×R[%rax]R[\text{\%rdx}]:R[\text{\%rax}] \leftarrow S \times R[\text{\%rax}]Unsigned full multiply
cqtoR[%rdx]:R[%rax]←SignExtend(R[%rax])R[\text{\%rdx}]:R[\text{\%rax}] \leftarrow \text{SignExtend}(R[\text{\%rax}])Convert to oct word
idivq SSR[%rdx]←R[%rdx]:R[%rax] mod S;R[\text{\%rdx}] \leftarrow R[\text{\%rdx}]:R[\text{\%rax}] \bmod S;
R[%rax]←R[%rdx]:R[%rax]÷SR[\text{\%rax}] \leftarrow R[\text{\%rdx}]:R[\text{\%rax}] \div S
Signed divide
divq SSR[%rdx]←R[%rdx]:R[%rax] mod S;R[\text{\%rdx}] \leftarrow R[\text{\%rdx}]:R[\text{\%rax}] \bmod S;
R[%rax]←R[%rdx]:R[%rax]÷SR[\text{\%rax}] \leftarrow R[\text{\%rdx}]:R[\text{\%rax}] \div S
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.

InstructionBased onDescription
CMPS2−S1S_2 - S_1Compare
cmpbCompare byte
cmpwCompare word
cmplCompare double word
cmpqCompare quad word
TESTS1&S2S_1 \& S_2Test
testbTest byte
testwTest word
testlTest double word
testqTest quad word

Difference: CMP performs subtraction (S2−S1S_2 - S_1) to set flags based on the relationship between operands, useful for comparing values. TEST performs bitwise AND (S1&S2S_1 \& S_2) 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.

InstructionSynonymEffectSet condition
sete DDsetzD←ZFD \leftarrow ZFEqual / zero
setne DDsetnzD←∼ZFD \leftarrow \sim ZFNot equal / not zero
sets DDD←SFD \leftarrow SFNegative
setns DDD←∼SFD \leftarrow \sim SFNonnegative
setg DDsetnleD←∼(SF⊕OF)∧∼ZFD \leftarrow \sim (SF \oplus OF) \land \sim ZFGreater (signed >>)
setge DDsetnlD←∼(SF⊕OF)D \leftarrow \sim (SF \oplus OF)Greater or equal (signed ≥\geq)
setl DDsetngeD←SF⊕OFD \leftarrow SF \oplus OFLess (signed <<)
setle DDsetngD←(SF⊕OF)∨ZFD \leftarrow (SF \oplus OF) \lor ZFLess or equal (signed ≤\leq)
seta DDsetnbeD←∼CF∧∼ZFD \leftarrow \sim CF \land \sim ZFAbove (unsigned >>)
setae DDsetnbD←∼CFD \leftarrow \sim CFAbove or equal (unsigned ≥\geq)
setb DDsetnaeD←CFD \leftarrow CFBelow (unsigned <<)
setbe DDsetnaD←CF∨ZFD \leftarrow CF \lor ZFBelow or equal (unsigned ≤\leq)

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.

InstructionSynonymJump conditionDescription
jmp Label11Direct jump
jmp ∗Operand*Operand11Indirect jump
je LabeljzZFZFEqual / zero
jne Labeljnz∼ZF\sim ZFNot equal / not zero
js LabelSFSFNegative
jns Label∼SF\sim SFNonnegative
jg Labeljnle∼(SF⊕OF)∧∼ZF\sim (SF \oplus OF) \land \sim ZFGreater (signed >>)
jge Labeljnl∼(SF⊕OF)\sim (SF \oplus OF)Greater or equal (signed ≥\geq)
jl LabeljngeSF⊕OFSF \oplus OFLess (signed <<)
jle Labeljng(SF⊕OF)∨ZF(SF \oplus OF) \lor ZFLess or equal (signed ≤\leq)
ja Labeljnbe∼CF∧∼ZF\sim CF \land \sim ZFAbove (unsigned >>)
jae Labeljnb∼CF\sim CFAbove or equal (unsigned ≥\geq)
jb LabeljnaeCFCFBelow (unsigned <<)
jbe LabeljnaCF∨ZFCF \lor ZFBelow or equal (unsigned ≤\leq)

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.

InstructionSynonymMove conditionDescription
cmove S,RS, RcmovzZFZFEqual / zero
cmovne S,RS, Rcmovnz∼ZF\sim ZFNot equal / not zero
cmovs S,RS, RSFSFNegative
cmovns S,RS, R∼SF\sim SFNonnegative
cmovg S,RS, Rcmovnle∼(SF⊕OF)∧∼ZF\sim (SF \oplus OF) \land \sim ZFGreater (signed >>)
cmovge S,RS, Rcmovnl∼(SF⊕OF)\sim (SF \oplus OF)Greater or equal (signed ≥\geq)
cmovl S,RS, RcmovngeSF⊕OFSF \oplus OFLess (signed <<)
cmovle S,RS, Rcmovng(SF⊕OF)∨ZF(SF \oplus OF) \lor ZFLess or equal (signed ≤\leq)
cmova S,RS, Rcmovnbe∼CF∧∼ZF\sim CF \land \sim ZFAbove (unsigned >>)
cmovae S,RS, Rcmovnb∼CF\sim CFAbove or equal (unsigned ≥\geq)
cmovb S,RS, RcmovnaeCFCFBelow (unsigned <<)
cmovbe S,RS, RcmovnaCF∨ZFCF \lor ZFBelow or equal (unsigned ≤\leq)

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.

Stack Frame Layout

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.

InstructionDescription
call LabelProcedure call
call ∗Operand*OperandProcedure call
retReturn 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

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

Suggest an edit

Last modified: 29 Nov 2026