|
I.e.: we can use the non-leaf function technique to implement a leaf function
Example: (expressed in Java)
public static void main(String[] args) { A( ); } public static void A( ) { ... B( ); // Calls B( ) ... } public static void B( ) { ... // Does not call any method/function ... } |
Example: using the non-leaf technique in the leaf function B( )
mov r0, #4
mov r1, #4
bl A
mov r2, #4
mov r3, #4
Stop:
A:
push {lr} // Save return address
mov r0, #44
mov r1, #44
bl B // Overwrites lr, it's OK, we saved it !!!
mov r2, #44
mov r3, #44
pop {pc} // A returns to main !!!
B:
push {lr} // Save return address
mov r0, #4444
mov r1, #4444
pop {pc} // B returns to A !!!
|
DEMO: /home/cs255001/demo/asm/8-sub/bl+popX.s
|