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.

#DescriptionLink
1Hello, World (syscall only)View
2Registers and Sub-RegistersView
3Data Definitions and SizesView
4Arithmetic and the FlagsView

Control Flow

From PHASE 3: comparisons, branches, and loops.

#DescriptionLink
5Conditional Branches (if / else)View
6Loops: while, for, and counting downView

Subprograms

From PHASE 4: calls, frames, and recursion.

#DescriptionLink
7Functions, Arguments, and Return ValuesView
8A Full Stack FrameView
9Recursion: FactorialView
10Macros and Local LabelsView

Input & Output

From PHASE 5: the syscall interface in practice.

#DescriptionLink
11write: Formatted Output by HandView
12read: Echo One LineView
13Print an Unsigned IntegerView

Data & Algorithms

Putting addressing modes to work.

#DescriptionLink
14Array Sum with Scaled IndexingView
15String Length and CopyView
16Jump Table DispatchView

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.

#DescriptionLink
17Hello, World (ARM64)View
18Loop and Sum (ARM64)View
19Function Call and Link RegisterView
20Array Sum with Scaled IndexingView
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.