Squidge
Certified Guru
The usual uses for registers are as follows:
R0 - R3 - Working registers & function call parameters (No need to save across function calls)
R4 - R9 - Working registers (Must be saved across function calls)
R10 SP Stack Limit
R11 FP Frame pointer
R12 IP Scratch Register
R13 SP Stack Pointer
R14 LR Link Register
R15 PC Program Counter
Although you can use any register as your stack, R13 is the normal, and if you want compatibility with GCC, it should be the one you use.
The BL (Branch with Link) instruction will copy the address of the next instruction to R14 before calling the function. Exceptions (such as interrupts) copy the current contents of R15 to R14 in the bank of the exception handler. This may or may not be the address of the next instruction, depending on the type of exception.
Setting up R13 on startup rather than each time the interrupt occurs will save you an instruction, and thus give you less interrupt latency to get to your proper code, but setting it up everytime on interrupt entry will always ensure it points to a valid place (ie. you can then exit your interrupt without restoring R13 to the default value).
Personally, I prefer to setup R13 once in the startup code for each processor state (SVC, IRQ, etc), and leave it at that.
R0 - R3 - Working registers & function call parameters (No need to save across function calls)
R4 - R9 - Working registers (Must be saved across function calls)
R10 SP Stack Limit
R11 FP Frame pointer
R12 IP Scratch Register
R13 SP Stack Pointer
R14 LR Link Register
R15 PC Program Counter
Although you can use any register as your stack, R13 is the normal, and if you want compatibility with GCC, it should be the one you use.
The BL (Branch with Link) instruction will copy the address of the next instruction to R14 before calling the function. Exceptions (such as interrupts) copy the current contents of R15 to R14 in the bank of the exception handler. This may or may not be the address of the next instruction, depending on the type of exception.
Setting up R13 on startup rather than each time the interrupt occurs will save you an instruction, and thus give you less interrupt latency to get to your proper code, but setting it up everytime on interrupt entry will always ensure it points to a valid place (ie. you can then exit your interrupt without restoring R13 to the default value).
Personally, I prefer to setup R13 once in the startup code for each processor state (SVC, IRQ, etc), and leave it at that.