Caveat: registers are shared among all functions (subroutines):
|
This has consequences on the value inside a register before and after a function call instruction
An important effect when you call a function shown with an example:
f1: ... ... mov r0,#1 // Before function call to f2 ... bl f2 ... // After function call to f2 ... add r1, r1, r0 |
Question: will the instruction add r1, r1, r0 always add 1 to register R1 ???
An important error explained with an example:
f1: +----> f2: push {lr} ... | ... ... | ... mov r0,#1 | mov r0, #9 ... | ... bl f2 ----------+ ... ... <--------------+ ... ... | ... add r1, r1, r0 +------ pop {pc} |
Answer: NO !!! --- After the function call bl f2, the register r0 can be overwritten !!!
Recall: an important rule in assembler programming:
|
|