Skip to content
Tutorials Center
My learning

Topics

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

  1. 1 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.
  2. 2 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.
  3. 3 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.
  4. 4 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

  1. 5 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.
  2. 6 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.
  3. 7 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.
  4. 8 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

  1. 9 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.
  2. 10 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.
  3. 11 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.
  4. 12 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

  1. 13 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.
  2. 14 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.
  3. 15 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

  1. 16 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.
  2. 17 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.
  3. 18 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.
  4. 19 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

  1. 20 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.
  2. 21 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.
  3. 22 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

  1. 23 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.
  2. 24 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.
  3. 25 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

  1. 26 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.
  2. 27 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.
  3. 28 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

  1. 29 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.
  2. 30 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.
  3. 31 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.
  4. 32 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

  1. 33 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.
  2. 34 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.
  3. 35 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.
  4. 36 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.
  5. 37 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

  1. 38 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.
  2. 39 Assembly Interview Questions Prepare for low-level interviews: registers, the stack, calling conventions, flags, endianness, x86 vs ARM, debugging and security, with runnable proofs.
  3. 40 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.