Assembly Demo Examples
Practice programs, one file each: the x86-64 examples are assembled on Linux with
nasm -f elf64 and linked with ld, and the ARM64 examples are assembled with the GNU cross-assembler. Every file is self-contained, commented, and safe to modify.
Foundations
From PHASE 1–2: a first program, registers, data definitions, and arithmetic.
| # | Description | Link |
|---|---|---|
| 1 | Hello, World (syscall only) | View |
| 2 | Registers and Sub-Registers | View |
| 3 | Data Definitions and Sizes | View |
| 4 | Arithmetic and the Flags | View |
Control Flow
From PHASE 3: comparisons, branches, and loops.
| # | Description | Link |
|---|---|---|
| 5 | Conditional Branches (if / else) | View |
| 6 | Loops: while, for, and counting down | View |
Subprograms
From PHASE 4: calls, frames, and recursion.
| # | Description | Link |
|---|---|---|
| 7 | Functions, Arguments, and Return Values | View |
| 8 | A Full Stack Frame | View |
| 9 | Recursion: Factorial | View |
| 10 | Macros and Local Labels | View |
Input & Output
From PHASE 5: the syscall interface in practice.
| # | Description | Link |
|---|---|---|
| 11 | write: Formatted Output by Hand | View |
| 12 | read: Echo One Line | View |
| 13 | Print an Unsigned Integer | View |
Data & Algorithms
Putting addressing modes to work.
| # | Description | Link |
|---|---|---|
| 14 | Array Sum with Scaled Indexing | View |
| 15 | String Length and Copy | View |
| 16 | Jump Table Dispatch | View |
ARM64 Examples
The same ideas in a RISC dialect. Assemble on an ARM64 Linux host with as, or cross-assemble with aarch64-linux-gnu-as and run under QEMU (qemu-aarch64 ./app). CPUlator runs them in the browser with no toolchain at all.
| # | Description | Link |
|---|---|---|
| 17 | Hello, World (ARM64) | View |
| 18 | Loop and Sum (ARM64) | View |
| 19 | Function Call and Link Register | View |
| 20 | Array Sum with Scaled Indexing | View |
How to use a demo: open it in the code viewer, read the comments top to bottom, download it, assemble it, run it — then break it on purpose. Change a size qualifier, swap a signed jump for an unsigned one, leave out a
cqo. Watching the program fail in a predictable way is how the rules become permanent.
What to Do Next
Work the list in order. Each demo file ends with a short Try this comment suggesting one deliberate modification; do them all before moving on to the Study Projects page.
- Assemble and run every x86-64 demo on Linux or WSL2.
- Assemble and run at least two ARM64 demos in CPUlator or under QEMU.
- Compare the x86-64 array loop (14) with the ARM64 one (20) — the addressing is where the two dialects differ most.