RISC-V Two-Argument Function Call with RV64 Stack Frame Demo
Example: caller calls foo(3, 5). Arguments use a0/a1; stack memory shows foo saving ra/s0, restoring them, and freeing a 16-byte-aligned stack frame.
This page uses RV64 instructions and a 32-byte stack frame; real compilers may emit shorter sequences depending on optimization level, frame-pointer use, and leaf-function rules.
caller
focusfoo
quietBoundaries that often get mixed up
When addi sp is highlighted, this page shows the before-execution state; by the next instruction, sp has moved to the new value.
call writes ra; ret returns through ra. Saving ra is the function's own state preservation, not an automatic push by call.
s0/fp is the callee-saved register shown in this example; real functions save only registers they modify and must preserve by the ABI.
This page demonstrates an ordinary function call, not ECALL/trap. A function call does not switch privilege level or write EPC/cause trap state automatically.