/* -------------------------------------------------- Show how to manage the program stack to store parameters and local variables -------------------------------------------------- */ .global main, Stop, CodeEnd, DataStart, DataEnd .global A /* -------------------------------------------------- Begin of the program instructions -------------------------------------------------- */ .text main: mov r0, #2222 // Pass 2222 as parameter 2 on stack push {r0} mov r0, #1111 // Pass 1111 as parameter 1 on stack push {r0} bl A // Call function A add sp, sp, #8 // Clean up parameters on the stack // When A returns, you will see the return value in r0 = 9999 nop nop Stop: nop /* ============================================== Function A: param and locals in stack ============================================== */ A: // When run in EGTAPI - you will see {1111, 2222} on stack /* **************************************** 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, #12 // I create 3 local variable in stack nop // These instructions in A( ) can use stack nop // to access parameters and local variables /* ==================================================== We can use a register to return the return value ==================================================== */ mov r0, #9999 // Pass return value in register r0 /* ************************************************ 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: DataEnd: .end