Skip to content
LumenaryAcademy

Lumenary CS · Programming languages

Assembly

x86-64 assembly on Linux, from a first system call to reading what compilers write, with a look at ARM64 and RISC-V.

An assembly language is a readable spelling of a processor's machine code: one line, one instruction, with names instead of numbers. There is no single assembly language. Every processor family has its own, and this course teaches the one inside most laptops, desktops and servers: x86-64, written for Linux with the GNU assembler in Intel syntax, with no C library underneath. You will talk to the operating system directly through system calls, build every number you print digit by digit, and learn the calling convention that lets assembly and C call each other. The last lessons compare x86-64 with ARM64 and RISC-V and end with a complete program.

Few people write whole programs in assembly today. Many professionals read it every week: compiler and runtime engineers, people tuning hot loops, security researchers reversing malware or writing exploits for authorised tests, embedded engineers bringing up a new board, and anyone who has stared at a crash in a debugger. This course assumes the Start level of Lumenary CS or equivalent experience: you know what a variable, a loop and a function are. Knowing a little C helps in the later lessons but is not required.

To run the programs you need an x86-64 Linux system with GNU Binutils (the binutils package on Debian, Ubuntu and Fedora). On Windows, WSL 2 gives you one; on a Mac, use a Linux virtual machine or an x86-64 Linux container. There is no official online playground for assembly, but Compiler Explorer shows the assembly that compilers produce for any C function you type, and it is used throughout the later lessons.

AI-draftedAwaiting review by a computer scientist
  • Chloe · The Designer
    “Why is the language built this way?”
  • Margaret · The Profiler
    “What does it print, and what does it cost?”
  • Gideon · The Language Lawyer
    “What exactly does the language guarantee?”

Foundations · 4 lessons

Talking to the processor

What assembly is and why it is still worth learning, then registers, arithmetic, memory, addressing, flags and jumps: enough to compute anything and print the answer.

  1. 1First steps in assemblyWhat assembly language is, why people still learn it, and a first x86-64 program that talks to Linux with no library at all. 50 min
  2. 2Registers and arithmeticThe sixteen general-purpose registers, their 32-, 16- and 8-bit names, and the instructions that add, multiply, divide and shift. 55 min
  3. 3Memory and addressingBytes at addresses, data directives, little-endian order, and the addressing modes that make arrays, tables and records cheap. 55 min
  4. 4Flags, compares and jumpsHow the processor remembers what the last calculation looked like, and how if, while and for become compare-and-jump. 60 min

Practice · 3 lessons

Functions, the kernel and the compiler

The stack and the System V calling convention, system calls as the door into the kernel, and how assembly and C call each other and how to read what a compiler writes.

  1. 5The stack and the calling conventionpush, pop, call and ret, and the System V AMD64 rules that let functions written by different people, in different languages, call each other. 65 min
  2. 6System callsThe door between your program and the Linux kernel, how to pass it arguments, read its answers and errors, and ask it for memory. 60 min
  3. 7Calling C, and reading what compilers writeAssembly functions called from C, C functions called from assembly, and a guided tour of real compiler output and its idioms. 65 min

Professional · 2 lessons

Other machines and a complete program

How ARM64 and RISC-V differ from x86-64 and why, then a complete text-statistics tool in idiomatic x86-64 with notes on debugging, performance and where to go next.

  1. 8ARM64 and RISC-VTwo younger instruction sets compared with x86-64, from registers and encodings to calls, system calls and memory ordering. 60 min
  2. 9Project: text statistics, tests and speedA complete x86-64 program in idiomatic style, a test harness for it, a SIMD version of its inner loop, and where to go next. 75 min

Further reading and resources