6.2.3.  A more detailed look at APCS register usage

Although sb, sl, fp, ip, sp and lr are dedicated registers, the example in Example 6.2 shows ip and lr being used as temporary registers. Sometimes these registers are not used for their APCS roles. The details given below will enable you to write efficient and safe code that uses as many of the registers as possible, and avoids unnecessary saving and restoring of registers:


Is used only during function calls, so it is not preserved across function calls. It is conventionally used as a local code generation temporary register. At other times it can be used as a corruptible temporary register. ip is not preserved in either its dedicated or non-dedicated APCS role.


Holds the address to which control must return on function exit. It can be (and often is) used as a temporary register after pushing its contents onto the stack. This value can be loaded directly into the program counter when returning. lr is not preserved in either its dedicated or non-dedicated APCS role.


Is the stack pointer. It is always valid in strictly conforming code, but need only be preserved in handwritten code. Note, however, that if any handwritten code makes use of the stack, or if interrupts can use the user mode stack, sp must be valid. In its non-dedicated APCS role, sp must be preserved. sp must be preserved on function exit for APCS conforming code.


Is the stack limit register. If stack limit checking is enabled sl must be valid whenever sp is valid. In its non-dedicated APCS role, sl must be preserved.


Is the frame pointer register. In the obsolete APCS variants that use fp, this register contains either zero, or a pointer to the most recently created stack backtrace data structure. As with the stack pointer, the frame pointer must be preserved, but in handwritten code it does not need to be available at every instant. However, it must be valid whenever any strictly conforming function is called. fp must always be preserved.


Is the static base register. This register is used to access static data. If sb is not used, it is available as an additional register variable, v6, that must be preserved across function calls. sb must always be preserved.

Copyright © 1997, 1998 ARM Limited. All rights reserved.ARM DUI 0040D