5.3.2 Function call mechanism ¶
When executing ‘call <address>’:
- 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)
- Jump to function: Set ‘PC = <address>’
When executing ‘Ret’:
- Pop frame: Retrieve ‘(saved_PC, saved_SP)’ from call stack
- Restore context:
- Set ‘PC = saved_PC’ (return to caller)
- Set ‘SP = saved_SP’ (restore stack state)
- Check termination: If call stack is empty after pop, terminate
program