Skip to main content
Logo image

Section C.6 M3: Function Calls

Synopsis.

  • Explain function call mechanism. jal and jr and the return address.
  • Mention the problem that we want to preserve values over calls (first and foremost the return address).
  • Such values have to be saved somewhere; registers may be overwritten by called function.
  • So we need a convention which registers are preserved and which can be overwritten.
  • Overwritten registers must be saved somewhere. Global data not possible because recursive calls would overwrite saved values.
  • Need call stack. Explain allocation/deallocation of stack frame, usage of stack pointer. Show how saving/restoring is done (relative addressing to stack pointer.)
  • Discuss recursion and tail recursion in this context. Live code factorial recursively and tail recursively. Step through program and show the difference.
  • Goal is to understand that recursion requires book keeping and has an overhead.

Sections Covered.