
Of course in this particular case, we could have just used r3, but it is something that needs to be considered. This means both that do_something needs to preserve the result of r0 + r1 in a register that will not be destroyed by abs, and that We must also preserve the contents of whichever register we use to hold that result.

The program stores r4, because the Arm procedure call standard specifies that r4-r11 must be preserved between function calls and that the called function is responsible for that preservation. In do_something we push the link register to the stack, so that we can pop it back off again to return, even though the call to abs will have overwritten the original contents of the link register.
Arm assembly readwrite code#
Once the routine we are calling has been executed, lr can be copied back to pc, which will enable the CPU to continue from the code after the bl instruction. blspan>, as you may have guessed, is no more than branch with link, where the address of the next instruction after the branch is loaded into the link register lr. They simply take the provided register list and push them onto the stack - or pop them off and into the provided registers. If you are familiar with other assembler languages, then I suspect push and pop are no mystery. The interesting instructions, at least when we are talking about the link register and the stack, are push pop and bl. ascii "The answer is returns r0 = x, r1 = y, r2 = z To start, here is a small example in Arm Assembler with one function calling another.


As lower power and smaller code sizes are often closely tied, it is not long before you will need to make effective and efficient use of the processor by calling functions from your carefully hand-crafted code. Macros are good for short repeated sequences, but often quickly increase the size of your code. Once you move beyond short sequences of optimised Arm assembler, the next likely step will be to managing more complex, optimised routines using macros and functions.
