Assembly
Assembly language is a thin, human-readable layer over a processor's machine code. Each line is one instruction, the CPU runs them in order, and a program counter moves forward unless a jump changes it. That makes it the most literal form of linear programming.
Paradigm: Linear Programming
What Makes Assembly Special
- One line, one instruction. A line such as
mov rax, 1maps almost directly to a machine instruction. There are no expressions, functions or types, only registers, memory and operations. - Labels and jumps are all the control flow. A label like
_start:names an address, andjmp,jeorloopmove the program counter there. Decisions and loops are built from compare-and-jump pairs. - Tied to one architecture. x86-64, ARM and RISC-V each have their own instruction set, registers and calling conventions. Assembly is not portable.
- You see the machine. Registers, the stack, flags and system calls are all explicit. Nothing is hidden by a runtime.
- Assemblers differ by syntax. NASM, MASM, GAS and others use different syntax for the same instructions. The example below is NASM for 64-bit Linux.
Example: Hello, world with system calls
section .data
msg db "Hello, linear world!", 10
len equ $ - msg
section .text
global _start
_start:
mov rax, 1 ; system call number: write
mov rdi, 1 ; file descriptor 1: stdout
mov rsi, msg ; address of the text
mov rdx, len ; number of bytes
syscall
mov rax, 60 ; system call number: exit
xor rdi, rdi ; exit code 0
syscall
How It Works
section .datareserves the message bytes;lenis computed by the assembler from the current address minus the start ofmsg.- Execution starts at the
_startlabel and simply falls from one instruction to the next. - Each
movloads a register with an argument;syscallasks the Linux kernel to act. The registers are the parameters. - There is no
return: the program ends only because the second system call tells the kernel to exit.
History and Where It Is Used
Assembly is used where you need exact control or the smallest possible code: boot loaders, operating system kernels, interrupt handlers, firmware, cryptographic and multimedia kernels, and compiler back ends. Even if you never write it, reading assembly output explains what higher-level code costs. See the Assembly roadmap for a full course.
Learn More
- NASM documentation
- Assembly language (Wikipedia)
- Back to Linear Programming or the PGP roadmap.