/* -------------------------------------------------------------- Program file used to demo (1) Pass by value (a.k.a.: pass by copy) (2) Pass by reference -------------------------------------------------------------- */ .global main, Stop, CodeEnd, DataStart, DataEnd .global f, k /* -------------------------------------------------- Begin of the program instructions -------------------------------------------------- */ .text main: /* ========================================= Pass k to f( ) by value or by ref ========================================= */ nop nop Stop: nop /* ================================================ Function f that gets a parameter Stack frame of f( ): FP--> +-----------+ | old FP | FP + 0 +-----------+ | ret addr | FP + 4 +-----------+ | param a | FP + 8 +-----------+ ================================================ */ f: /* **************************************** Prelude: build stack frame **************************************** */ push {lr} // Save return address in LR push {fp} // Save Frame Pointer in FP mov fp, sp // Initialize my own FP sub sp, sp, #0 // I create 0 local variable in stack /* ======================================= F() executes: a = a + 1 ======================================= */ /* ************************************************ Postlude: break down stack frame ************************************************ */ mov sp, fp // De-allocate the local variables pop {fp} // Restore old FP pop {pc} // Return CodeEnd: nop /* -------------------------------------------------- Begin of the permanent program variables -------------------------------------------------- */ .data DataStart: k: .4byte 7 DataEnd: .end