Course

x86-64 assembly from the ground up

The language the processor actually runs

  • Beginner
  • 12 chapters
  • 197 min read

Learn x86-64 assembly by running it: registers and the mov instruction, the write and exit kernel calls, arithmetic with cdq and idiv, comparisons and the flags, loops with a counter, the stack with call and ret, memory addressing and lea, the four widths from db to dq, turning an integer into digits, the section layout with equ, and a capstone that sums a table and prints the total.

What You'll Learn

  • Read and write a NASM file, and know what the processor does with each line
  • Move values between registers and immediates, and know why one name has four widths
  • Print bytes with the write call and end a program with the exit call
  • Add, subtract, multiply and divide, with cdq or a cleared edx in front of a division
  • Compare two values and branch on the flags, signed or unsigned
  • Repeat work with a label and a jump back, keeping the counter where a syscall cannot reach it
  • Use push and pop, call a function, return from it and give the caller its registers back
  • Reach into memory with base, index and displacement, and compute addresses with lea
  • Choose between db, dw, dd and dq, and widen a small load with movzx or movsx
  • Turn an integer into decimal digits and print the text
  • Lay out a file in text, data and reserved sections and name its constants with equ
  • Build a capstone: a table, a loop, a division and one computed line of output

Prerequisites

  • No assembly at all — the course starts at the first register
  • Some experience with one programming language makes the early chapters quicker, but none is assumed

Course Content

  1. 01
    Your first program

    What the processor is doing while your code runs, what a register is, and your first program: four register values and two calls into the kernel.

    Beginner · 12 min read

    Not started
  2. 02
    Registers and mov

    The sixteen registers, why one of them has four names, and what mov really does: it copies a value without touching the place the value came from.

    Beginner · 12 min read

    Not started
  3. 03
    Writing and exiting

    The two kernel calls every program here needs: write sends bytes out, and exit hands a status back. Also why a program that never exits does not simply stop.

    Beginner · 14 min read

    Not started
  4. 04
    Arithmetic in registers

    Adding, subtracting, multiplying and dividing in registers, and the one instruction that surprises everybody: division reads two registers and writes two back.

    Beginner · 16 min read

    Not started
  5. 05
    Comparisons and branches

    cmp keeps the flags and throws the answer away, a jump reads one of those flags, and the pair is how a program chooses between two paths.

    Intermediate · 16 min read

    Not started
  6. 06
    Loops with a counter

    A loop is a label and a jump back to it, plus a counter that says when to stop. The chapter also covers the register the kernel quietly steals.

    Intermediate · 15 min read

    Not started
  7. 07
    The stack and functions

    push and pop on the stack, call and ret as a pair, and a function that the program can use twice without writing the write call twice.

    Intermediate · 18 min read

    Not started
  8. 08
    Memory addressing and lea

    Brackets turn a number into a place, a base register plus an index reaches into a block of bytes, and lea computes an address without reading one.

    Intermediate · 18 min read

    Not started
  9. 09
    Bytes, words and quadwords

    The four widths a value can have, the data directives that reserve them, and the size word that keeps the assembler from guessing what a store should write.

    Advanced · 18 min read

    Not started
  10. 10
    Numbers into text

    A byte holding a digit is a character, not a number. Dividing by ten peels the digits off one at a time, and a buffer filled from the end turns an integer into a line of text.

    Advanced · 20 min read

    Not started
  11. 11
    Sections and equ

    What goes in each section and why, and how equ gives a number a name at assembly time so a program has no magic constants left in it.

    Advanced · 16 min read

    Not started
  12. 12
    Capstone: summing an array

    A table of numbers, a loop that adds them, a division that splits the total into digits, and one write that prints the answer. Every earlier chapter has a line in it.

    Pro · 22 min read

    Not started