


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Assembly code for x86 summary document
Typology: Summaries
1 / 4
This page cannot be seen from the preview
Don't miss anything!



1. Registers
1.1 General-Purpose Registers Register (64-bit) 32 / 16 / 8-bit aliases Conventional use RAX (^) EAX / AX / AL Accumulator — return values, arithmetic RBX (^) EBX / BX / BL Base — callee-saved, general use RCX (^) ECX / CX / CL Counter — loop counter, 4th argument (Windows) RDX (^) EDX / DX / DL Data — I/O, 3rd argument, high half of mul/div RSI (^) ESI / SI / SIL Source index — 2nd argument (Linux), string ops RDI (^) EDI / DI / DIL Destination index — 1st argument (Linux), string ops RSP (^) ESP / SP / SPL Stack pointer — always points to top of stack RBP (^) EBP / BP / BPL Base pointer — stack frame base (callee-saved) R8–R15 (^) R8D–R15D / R8W–R15W / R8B–R15B Additional GPRs (x86-64 only) 1.2 Special-Purpose Registers Register Purpose RIP (^) Instruction pointer — address of the next instruction to execute. Not directly writable; changed by JMP, CALL, RET. RFLAGS (^) Status flags register — individual bits record the outcome of the last operation (Zero Flag, Carry Flag, Sign Flag, Overflow Flag, etc.). XMM0–XMM15 (^) 128-bit SIMD registers used for floating-point and packed integer operations (SSE/SSE2). 1.3 Key RFLAGS Bits Flag Bit Set when… ZF — Zero (^6) Result of last operation was zero CF — Carry (^0) Unsigned overflow (carry out of MSB) SF — Sign (^7) Result was negative (MSB = 1) OF — Overflow (^11) Signed overflow occurred
Flag Bit Set when… PF — Parity (^2) Least-significant byte has even number of 1 bits
2. Addressing Modes
Mode Syntax example Meaning Immediate (^) MOV RAX, 42 Operand is a constant embedded in the instruction Register (^) MOV RAX, RBX Operand lives in a named register Direct / Absolute (^) MOV RAX, [0x4000] Operand is at a fixed memory address Register Indirect (^) MOV RAX, [RBX] Address is the value stored in RBX Base + Displacement (^) MOV RAX, [RBX+8] Address = RBX + constant offset (accessing struct fields) Base + Index (^) MOV RAX, [RBX+RCX] Address = RBX + RCX (two registers added) Base+Index×Scale+Di sp MOV RAX, [RBX+RCX*4+8] Full form: base + (index × 1/2/4/8) + displacement RIP-relative (^) MOV RAX, [RIP+offset] 64-bit mode: address relative to next instruction (used for globals)
3. Core Instructions 3.1 Data Movement Instruction Example Effect MOV dst, src (^) MOV RAX, RBX Copy src into dst (src unchanged) MOVZX dst, src (^) MOVZX EAX, BL Move with zero-extension (fills upper bits with 0) MOVSX dst, src (^) MOVSX RAX, EBX Move with sign-extension (fills upper bits with sign bit) LEA dst, [mem] (^) LEA RAX, [RBX+8] Load Effective Address — stores the computed address, not the value at it XCHG a, b (^) XCHG RAX, RBX Atomically swap two operands PUSH src (^) PUSH RAX Decrement RSP by 8, write src to [RSP] POP dst (^) POP RBX Read [RSP] into dst, increment RSP by 8
4. Calling Conventions (Quick Reference)
System V AMD64 (Linux / macOS) Microsoft x64 (Windows) Integer args (order)
Float args (^) XMM0–XMM7 XMM0–XMM Return value (^) RAX (int) / XMM0 (float) RAX (int) / XMM0 (float) Callee-saved (^) RBX, RBP, R12–R15 RBX, RBP, RDI, RSI, R12–R Caller-saved (^) RAX, RCX, RDX, RSI, RDI, R8–R11 RAX, RCX, RDX, R8–R Stack alignment (^) 16-byte aligned before CALL 16-byte aligned; 32-byte shadow space
5. Common Idioms & Tips Idiom / Pattern Explanation XOR RAX, RAX (^) Zero a register — faster and shorter than MOV RAX, 0 TEST RAX, RAX (^) Check if RAX is zero without modifying it (sets ZF if zero). Equivalent to CMP RAX, 0 but one byte shorter. LEA RCX, [RAX+RAX2] (^) Compute RAX3 without a MUL instruction — LEA is often used for cheap arithmetic. PUSH RBP / MOV RBP, RSP (^) Standard function prologue: save old base pointer, set new frame. MOV RSP, RBP / POP RBP / RET Standard function epilogue: restore stack and return. SHL RAX, 2 (^) Multiply RAX by 4 (2^2) — shift is faster than IMUL for powers of two. AND RAX, -1 (^) No-op in terms of value but useful to set flags. AND RAX, 0xF masks to lower nibble. CDQE / CDQ (^) Sign-extend EAX into RAX (CDQE) or RAX into RDX:RAX (CDQ) before a signed divide. Notation: dst = destination operand, src = source operand, [ ] = memory dereference, cnt = shift count (immediate or CL register). Intel syntax used throughout (destination first).