Total n00b at Assembly, but I feel like I'm getting the hang of it. However I have a question about best practices for using registers in a function.
As I understand it: of the 13 available general purpose registers on the ARM11, by convention registers 0-3 are meant to be used for passing in arguments (with 0 & 1 also being used for return values) while 4-12 are meant to be used for storing working values for the duration of the function.
However I've also seen code examples where people use registers 0-3 for working values as well, so long as any of them are available, since they do not require a push & pop of the previous value onto the stack.
While I can understand why someone might want to avoid the extra push & pop steps, it seems that using r0-r3 for anything aside from passing values in and out of a function could lead to problems down the road (since you have no guarantee that any function you call will preserve their values).
So what then is the best practice here? When should I (if ever) use registers 0-3 for working values and when should I dip into registers 4-12?
it seems that using r0-r3 for anything aside from passing values in and out of a function could lead to problems down the road (since you have no guarantee that any function you call will preserve their values).
That's exactly when you could use r4-r11 since the ABI specifies that the callee must preserve these values :)
Registers r0-r3 are caller saved so the caller must ensure that any important values stored in those registers are saved before a function call. As the callee, you can do whatever you want on these registers.