Before you start
Setup
You need no toolchain to use this site — every snippet compiles in the browser. But assembly is the one subject where the instrument can lie to you, so it is worth knowing what each one actually measures.
Nothing. Every C and Rust snippet here has x86-64 andARM64 buttons that compile it on Compiler Explorer and show you the assembly. Install the rest when you want to check your own code rather than mine.
The instruments
| Tool | Answers | Lies about |
|---|---|---|
| Compiler Explorer | What did the compiler emit? | Your machine. It targets a generic CPU, not your M1. |
objdump -d / otool -tv | What is in this binary, on this machine? | Nothing — but it shows the linked result, not per-function source mapping. |
llvm-mca | Throughput and port pressure for a block | Caches and branches. It models the pipeline, not memory. |
perf (Linux) / Instruments (macOS) | Where time actually went | Nothing, and this is the only one that measures reality. |
| uops.info | Measured latency/throughput per instruction per microarchitecture | Your specific chip, unless you pick the right one. |
That last column is the point. Lesson3.1 is entirely about not mistaking the instrument for the territory, and lesson6.2 is about the one tool that measures rather than models.
On your own machine
You are on an Apple M1, which is ARM64. That is a real advantage: half of this course is ARM64, and you can disassemble it natively.
# compile without assembling, and look
clang -O2 -S -o - example.c | less
# or build and disassemble the real thing
clang -O2 -c example.c -o example.o
objdump -d example.o # llvm objdump, ARM64
otool -tv example.o # the macOS native toolFor x86-64 on an M1 you want Compiler Explorer rather than local tools — cross-assembling is possible but the setup cost is not worth it for reading.
Syntax: you will meet both
x86-64 has two assembly syntaxes for the same instructions, and the operand order is reversed between them. This site usesIntel syntax throughout, because it is what Compiler Explorer defaults to and what most documentation uses.
| Intel (this site) | AT&T (gcc default, gdb) | |
|---|---|---|
| Direction | mov dst, src | mov src, dst |
| Move 5 into rax | mov rax, 5 | movq $5, %rax |
| Registers | rax | %rax |
| Constants | 5 | $5 |
| Memory | [rdi+8] | 8(%rdi) |
| Width | implied by register | suffix: movq, movl |
If you ever read assembly that looks backwards, that is why. In gdb,set disassembly-flavor intel.
When a Predict box asks how many instructions something becomes, write a number before you press a compile button. Not “a few” — an actual number. Being wrong by 10× is the most useful thing that can happen to you here, and it only happens if you commit first.