A subroutine call and return
To call a subroutine, you push the return address on the stack. CISC processors implement a subroutine call with bsr target
. Because the ARM lacks a subroutine call instruction, you can write the following ARM code. Remember that we are dealing with 32-bit word push and pulls, and the stack must be incremented or decremented by four. Remember that r15
and SP
and r13
and lr
are interchangeable terms in ARM literature:
sub r13,r13,#4 @ Pre-decrement the stack pointer (r13 is used as the SP)
str r15,[r13] @ Push the return address in r15 on the stack
b Target @ Jump to the target address
... &...