/* ------------------------------------------------------------------------ Show how to access parameters and local variables in the program stack ------------------------------------------------------------------------ */ .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 /* ================================================= Method A store params and local vars 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 // How to to access parameters and local variables // stored in the program stack ldr r0, [fp, #8] // Get parameter 1 = 1111 str r0, [fp, #-12] // Store in local variable 1 ldr r1, [fp, #12] // Get parameter 2 = 2222 str r1, [fp, #-8] // Store in local variable 2 add r0, r0, r1 str r0, [fp, #-4] // Store sum in local variable 3 /* ================================================= 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 pop {fp} pop {pc} // Return CodeEnd: nop /* -------------------------------------------------- Begin of the permanent program variables -------------------------------------------------- */ .data DataStart: DataEnd: .end