gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

ASM > registers in ARM mode

#81482 - Fry_Day - Sat Apr 29, 2006 1:55 pm

well, this is my first time coding for the platform, and I just wondered if using all the registers was safe.

let me emphasize that I know ARM assembly, it's just an odd wonder about the environment.
The reason I ask is that I noticed the BIOS's interrupt handler doesn't push all the high registers, and, whilst I know a function is supposed to preserve registers it changes on the stack, I really don't know if they have any special meaning (e.g., in the RealView ARM C compiler (The official compiler), it uses R9 as a pointer to imagebase when generating PIC code, so it mustn't be changed ever).
_________________
"Facts Shmacts! They can prove even remotely true things!" -Homer Simpson

#81503 - poslundc - Sat Apr 29, 2006 4:25 pm

The BIOS interrupt handler observes the ARM intra-procedure call standard (you can google it).

The short of it is that any function that's called gets r0-r3 and r12 for free, but is responsible for preserving r4-r11 and sp across the function call. (The link register r14 does not need to be preserved, but contains the return address so usually at least needs to be stored.)

This applies to ISRs as well as normal functions. So if your ISR needs to use r9, then it needs to save r9's value and restore it before exiting to the calling procedure.

This is also why functions that are going to require use of all of the registers are typically framed at the beginning and end with:

Code:
stmfd     sp!, {r4-r11, lr}
...
ldmfd     sp!, {r4-r11, pc}

# (or for Thumb compatibility)
ldmfd     sp!, {r4-r11, lr}
bx     lr


Dan.