Passing arguments

Nov 05, 2003 6 Replies

If I pass an argument using r0 to r3, how can I keep from overwritting a register that might be used someplace else such as during an interupt routine?


Sean


Interrupt service routines should save machine flags plus any registers that they alter on the stack, and restore these on exit. Apart from ISRs, if you are coding in assembly language, or mixing this with C, you *must* be aware of who does what with particular registers. If you wish to preserve a register that a subroutine will overwrite, the subroutine can always push it on the stack on entry, and restore it on exit. Alternatively, you can get the calling routine to do it.

I hope that is of some help.

Tanya

Always make sure that your interrupt routines save/restore any registers or flags that they use?

Ron Sharp.

An interrupt routine is responsible to save and restore all the processor state (including registers) it's clobbering.

Next time tell which processor you're using. It's much easier to give meaningful replies to very chip-architecture dependent questions like this if it were known which chip it is.

Tauno Voipio tauno voipio @ iki fi

You have all answered my question and I greatly appreciate it. The processor is, FYI, an ARM 7. But I see how the solution is genericly used.

Thanks,

Sean

Get the ATPCS document from the ARM wbsite:

formatting link
$File/ATPCS.pdf

It describes in detail the standard for parameter passing, register saving etc in the ARM and Thumb modes.

Regards, Arie de Muynck

The ARM switches in a different bank of registers for some of the registers in interrupt mode. Hence if you have only one level of interrupts it is not necessary to save all the registers.

Regards Anton Erasmus

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required