[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] assembly-c mix and interrupts

From: darkschine
Subject: Re: [avr-gcc-list] assembly-c mix and interrupts
Date: Sat, 28 Nov 2009 21:56:05 -0800 (PST)

David Brown-4 wrote:
> So any function generated by the compiler, or compatible functions 
> written in assembly by hand, can freely use the call-used registers 
> (SREG, r18-r27, r30-r31) without preserving or restoring them.  But if 
> it wants to use the call-saved registers (r2-r17, r28-r29), it must save 
> them on entry and restore them on exit.
> An interrupt routine must also preserve any call-used registers it 
> needs, including SREG and r0.  It must also preserve the current r1 and 
> set it to 0 before certain compiler-generated code is executed.  If the 
> interrupt routine is going to call other functions, it must preserve 
> /all/ the call-used registers, since the other functions may trash them. 
>   On the other hand, it does not need to preserve any of the call-saved 
> registers, as the called function will preserve these as needed.

Thanks David. This was precisely the issue!
My interrupt routine was calling other functions but not preserving the
call-used registers.
my code was actually already written in C and looked something like:


The compiler does not make sure that all necessary registers are saved and
restored properly and apparently I am the first to notice this. I guess the
ISR preserves the call-used registers it uses, but does not preserve the
call-used registers that may be in use prior to the interrupt before
transfering control to the ignorant interruptHandler() function.

I wish I could say this was the end of my troubles.

  char *test ="test";

The output on the LCD is "\0\0x"

but put in another function in the same file, the output is "tex" as
expected! I'm starting to wish I wrote the whole thing in assembly! ;)

Can anyone suggest a possible cause for this problem?
View this message in context: 
Sent from the AVR - gcc mailing list archive at Nabble.com.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]