In general, an interrupt service routine (ISR) must return to what was 
interrupted with all the registers unchanged. For example, if you use R7 and R9 
inside the ISR, you should push R7 and R9 before you use them and pop R9 and R7 
afterwards. This way, R7 and R9 are unchanged from the point of view of the 
code being interrupted. The other registers, R4…R6, R8, and R10...R15, are 
never changed and thus remain unchanged without push and pop.
  If the ISR calls subroutines and the subroutines may change, for example, 
R15, then you have to push R15 before the calls and pop R15 afterwards.
  If you do not care about efficiency, you can push all the registers at the 
beginning of the ISR and pop all of them (in reverse order) near the end of the 
ISR. This way you can be sure that all registers are unchanged. To push and 
later pop registers that you never changed is not wrong, only inefficient. But 
to change the contents of a register without first saving (push) and later 
restoring (pop) the original value is a cardinal sin. You may think everything 
works out fine, but eventually you will pay for you sin.
  But there are exceptions. For example, if you are 100% sure that a certain 
register is not being used in the interrupted code, then you can change that 
register in you ISR without saving and restoring it. Another example goes even 
further, you can designate a register exclusively as the messenger for that 
ISR. You deliberately change its value as a message to other routines.

Kris Heidenstrom <[email protected]> wrote:  Hi,

I'm reposting this from 2006-11-30 because
no one replied then. I've confirmed the issue
still exists with V7.05 beta0.

The compiler-generated interrupt handler wrapper
code preserves R8 and R9 as well as R10~15.
I don't think it should. 

>From "Assembly Interface and Calling
Conventions" in the online help:
----------------------------------------
Preserved Registers R4~9
These registers are called preserved registers,
since their contents are unchanged by a function
call. Local variables are assigned to these registers
by the compiler.

Volatile Registers R10~15
Can be used in a function without being saved or
restored. These registers are called volatile registers,
since their contents may be changed by a function
call.

Interrupt Handlers
If you write a handler in assembly and if it calls
normal C functions, then the assembly handler
must save and restore the volatile registers,
since normal C functions do not preserve them.
----------------------------------------
I wrote my own wrapper in assembler, which
does not preserve R8 and R9, and everything
seemed to work OK.

Am I missing something here?

Kris
--
Kris Heidenstrom Embedded systems designer / programmer
[email protected] Abbey Systems Ltd - Telemetry Specialists
Wellington NEW ZEALAND Voice +64-4-385-6611 Fax +64-4-385-6848


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Mspgcc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users



Lichen Wang

Darwin was wrong. Monkeys might have evolved. Human did not.


 
---------------------------------
Access over 1 million songs - Yahoo! Music Unlimited.

Reply via email to