[prev] 25 [next]

Rendering C in MIPS: Functions (cont)

Each function allocates a small section of the stack (a frame)
  • used for: saved registers, local variables, parameters to callees
  • created in the function prologue   (pushed)
  • removed in the function epilogue   (popped)

Why we use a stack:
  • function f() calls g() which calls h()
  • h() runs, then finishes and returns to g()
  • g() continues, then finishes and returns to f()
i.e. last-called, exits-first (last-in, first-out) behaviour