5.3.2 Function call mechanism

When executing ‘call <address>’:

  1. Save current context: Push ‘(PC + 1, SP)’ onto the call stack
    • PC + 1’: Address of the instruction following CALL
    • SP’: Current stack pointer (preserves caller’s stack)
  2. Jump to function: Set ‘PC = <address>

When executing ‘Ret’:

  1. Pop frame: Retrieve ‘(saved_PC, saved_SP)’ from call stack
  2. Restore context:
    • Set ‘PC = saved_PC’ (return to caller)
    • Set ‘SP = saved_SP’ (restore stack state)
  3. Check termination: If call stack is empty after pop, terminate program