Skip to content

Chapter 17: Assembly Basics and Calling Conventions

Vol 3: Computer Core Expedition · Chapter 17


Metadata Card

AttributeValue
KeywordsABI, 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

NameUsage
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

  1. Caller saves any temporaries needed after the call
  2. Arguments in a0-a7
  3. jal jumps to function, saves return address in ra
  4. Callee saves s0-s11 it will use
  5. Callee adjusts sp for local variables
  6. Return value in a0
  7. 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 addresses

Verification 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

Built with VitePress | Software Systems Atlas