|
|
As you can see:
|
So we must "tear down" the stack frame (carefully !!!) before we can return from a subroutine
Fortunately, the sequence of (assembler) instruction used is the same because the structure of the stack frame always has a specific structure
|
|
mov sp, fp // De-allocate the local variables
pop {fp} // Restore thd old FP register for the caller
pop {pc} // return to the caller
|
pop {pc}
|
the program stack will contain the following:
|
I.e.:
|
|
That means that the sequence of instructions used by the caller function to pass parameters on the stack are as follows:
push parameters on stack
bl callee-function
clean up the parameters pushed on the stack !!!
|
You can use this assembler instruction to clean up the parameters:
add sp, sp, #N // N = #bytes pushed
|
Use N = 4 if you pushed 1 int parameter, use N = 4 if you pushed 2 int parameter, and so on.