Assembly (x86-64 and ARM) Tutorial
Learn Assembly (x86-64 and ARM) step by step: 40 lessons in 11 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
First Steps
- What Is Assembly Language? Learn what assembly language is, how it differs from machine code and C, what an instruction set architecture is, and where assembly is still used today.
- How a CPU Runs Instructions Understand the fetch-decode-execute cycle, the program counter, registers versus RAM and instruction encoding, then run a tiny CPU loop in JavaScript.
- Meet the Toy CPU: Our Runnable Assembly Meet the toy CPU used in this tutorial: registers, flags, a stack and memory, a readable instruction set you can run in the browser and map to x86-64 and ARM64.
- Reading Real Assembly from a C Compiler Learn to read real x86-64 and ARM64 assembly produced by a C compiler: gcc -S, optimization levels, Intel versus AT&T syntax and line-by-line annotation.
Data, Numbers and Registers
- Binary, Hex and Two's Complement Learn bits, bytes and hex, how two's complement stores negative numbers, sign and zero extension, overflow and wraparound, and endianness with runnable examples.
- Registers: The CPU's Working Memory Learn what CPU registers are, the difference between general-purpose and special-purpose registers, the program counter, stack pointer and flags, with a runnable toy register file.
- The x86-64 Register Set Learn the sixteen x86-64 general-purpose registers, their 64, 32, 16 and 8-bit names, the zero-extension rule for 32-bit writes, rip, rflags and xmm.
- Memory, Addresses and Endianness How assembly sees memory: byte addresses, loads and stores, little-endian byte order, alignment, and the virtual address space, with a runnable toy memory.
Core Instructions
- MOV, LEA and Moving Data Master mov, lea, movzx, movsx and xchg in x86-64: immediate, register and memory operands, effective addresses, and why lea is really arithmetic.
- Arithmetic: ADD, SUB, MUL, DIV Learn x86-64 arithmetic: add, sub, inc, dec, neg, imul, mul and div with rdx:rax, how carry and borrow work, and adc/sbb for numbers wider than a register.
- Logic, Shifts and Bit Tricks Learn the x86-64 bitwise instructions and, or, xor, not, test, shl, shr, sar and rotates, plus masks, xor zeroing, popcount and power-of-two bit tricks.
- Flags: ZF, SF, CF, OF and How They Are Set Understand the x86 status flags ZF, SF, CF and OF, how cmp works as a hidden sub, signed vs unsigned conditions, overflow detection, and a flag-driven toy CPU.
Control Flow
- Compare and Jump Learn how assembly makes decisions: CMP and TEST set flags, then JE, JNE, JL, JG, JA and JB jump. Includes labels, relative jumps and a runnable toy CPU.
- Writing Loops Build loops in assembly with a compare and a backward jump: counting loops, while vs do-while shapes, the LOOP instruction, nested loops, factorial and gcd.
- How if, switch and Ternaries Compile See how compilers turn if/else, switch and the ternary operator into compare-and-jump code, jump tables and branchless CMOV, and why branch prediction matters.
The Stack and Functions
- The Stack: push, pop and rsp Learn how the stack works in x86-64 assembly: push and pop move rsp, the stack grows downward, 16-byte alignment, the red zone, and scratch space. Runnable toy CPU.
- CALL and RET See how call pushes a return address and ret pops it, how nested calls and recursion use the stack, and how a stack overflow or bad ret happens, with a toy CPU.
- Calling Conventions: System V, Windows x64 and AAPCS64 Compare the System V, Windows x64 and ARM64 calling conventions: argument registers, return values, caller- vs callee-saved registers, shadow space and variadics.
- Stack Frames, Prologues and Epilogues See how a function builds its stack frame with push rbp, mov rbp, rsp and sub rsp, where locals live, what leaf functions skip, and how a debugger walks frames.
Arrays, Strings and Structs
- Arrays and Addressing Modes Learn the x86-64 address form base + index*scale + displacement, how a[i] and 2D arrays compile, why scales stop at 8, and pointer walking versus indexing.
- Strings and Byte Processing Process NUL-terminated strings in assembly: write strlen, strcpy, upper-casing and reverse loops, then see what rep movsb, stosb and scasb really do.
- Structs, Padding and Alignment See how a C struct becomes field offsets in assembly, the alignment rules that create padding, and how structs are passed and returned on x86-64.
ARM Assembly
- ARM64 (AArch64) Basics Meet 64-bit ARM: the 31 registers x0-x30, w registers, xzr and sp, fixed 32-bit instructions, and mov, add, sub, ldr and str, with runnable toy examples.
- ARM Load/Store, Conditions and Branches Learn ARM64 addressing modes (offset, pre-index, post-index), flags with cmp and b.cond, cbz, csel and cset, and how bl and ret use the link register.
- x86-64 vs ARM64: Side by Side Compare x86-64 and ARM64 assembly: CISC vs RISC, instruction length, memory operands, flags, calling conventions and memory ordering, with runnable demos.
Tools and Toolchain
- Assemblers, Syntax Flavors and Object Files How assembly text becomes a program: NASM vs GAS, Intel vs AT&T syntax, sections, symbols, directives, and the assemble-and-link pipeline, with demos.
- Inline Assembly in C Embed assembly in C with GCC extended asm: operands, constraints, clobbers, volatile, rdtsc and cpuid examples, and why intrinsics are usually safer.
- Debugging at the Instruction Level Debug at the instruction level with gdb and lldb: disassemble, stepi, info registers, x/ memory dumps, breakpoints and crashes, plus a runnable toy debugger.
Systems and Performance
- System Calls and Talking to the OS How assembly asks the operating system for help: the syscall instruction, Linux x86-64 and ARM64 numbers, write and exit, kernel vs user mode, with demos.
- Floating Point and SIMD Learn how assembly handles floating-point numbers and SIMD: xmm registers, addsd, packed SSE and AVX operations, ARM NEON, and compiler vectorization.
- Performance: Pipelines, Caches and Branches Why the same instructions can run at very different speeds: pipelines, latency vs throughput, branch misprediction and cache lines, with runnable simulators.
- Security: Buffer Overflows and Defenses See how a buffer overflow overwrites a return address at the instruction level, then how canaries, NX, ASLR and constant-time code defend. Safe toy simulations.
Projects
- Project: A Stack-Based Calculator Build a postfix (RPN) calculator in toy assembly that uses the stack to evaluate expressions, handles errors, and is tested against JavaScript.
- Project: Prime Sieve in Toy Assembly Write the Sieve of Eratosthenes in toy assembly: an array in memory, nested loops, indexed stores. Verify it against JavaScript and a C program.
- Project: A String Toolkit Build a string library in toy assembly: strlen, strcmp, strcpy, upper, reverse, atoi and itoa, all sharing one calling convention, with tests.
- Project: Build Your Own Tiny CPU Emulator Write a fetch-decode-execute emulator in JavaScript with registers, flags, a stack and memory, assemble programs for it, then add new instructions.
- Project: Hello World the Real Way Build a real hello world in x86-64 and ARM64 Linux assembly with raw system calls, step by step, then run a matching toy version right here.
Practice and Review
- Practice Exercises with Solutions Twenty graded assembly exercises on a runnable toy CPU: sums, gcd, fibonacci, popcount, array and string routines, with a checker and full solutions.
- Assembly Interview Questions Prepare for low-level interviews: registers, the stack, calling conventions, flags, endianness, x86 vs ARM, debugging and security, with runnable proofs.
- Assembly Cheat Sheet One-page x86-64 and ARM64 reference: registers, instructions side by side, condition codes, calling conventions, Linux syscall numbers and gdb commands.