Chapter 17: Assembly Basics and Calling Conventions
Vol 3: Computer Core Expedition · Chapter 17
Metadata Card
| Attribute | Value |
|---|---|
| Keywords | ABI, Registers, Calling Conventions, Stack Frames, Inline Assembly |
Your Progress
"Assembly reveals the true nature of CPU execution. Every C statement, every function call, every variable access — all become explicit register operations and memory accesses."
Encounter 1: RISC-V Registers
| Name | Usage |
|---|---|
| x0 (zero) | Always zero |
| x1 (ra) | Return address |
| x2 (sp) | Stack pointer |
| x3 (gp) | Global pointer |
| x5-x7, x28-x31 (t0-t6) | Temporaries |
| x8-x9, x18-x27 (s0-s11) | Saved registers |
| x10-x17 (a0-a7) | Function arguments / return values |
Encounter 2: Calling Convention
- Caller saves any temporaries needed after the call
- Arguments in a0-a7
jaljumps to function, saves return address in ra- Callee saves s0-s11 it will use
- Callee adjusts sp for local variables
- Return value in a0
- Callee restores sp, s0-s11, then
ret
Encounter 3: Stack Frame Structure
High addresses
... (caller's frame)
return address (ra)
saved s0
local variables
argument build area
SP → (empty for next call)
Low addressesVerification Checklist
- [ ] Can identify common RISC-V registers
- [ ] Can describe the calling convention (who saves what)
- [ ] Can draw a stack frame diagram
- [ ] Can read basic RISC-V assembly
→ Next Stop Preview
Chapter 18: Performance Engineering