avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] Can functions modify register 'r0' or not?


From: hutchinsonandy
Subject: Re: [avr-gcc-list] Can functions modify register 'r0' or not?
Date: Tue, 18 Aug 2009 20:22:56 -0400

r0 is scratch register. Only ISR have to save it - since it may interrupt usage as scratch.
Normal functions or inline assembler do not r0 contents. The contents of r0 are not assumed to remain outside a single RTL statement (-which ultimately translates to 1 or more assembly instructions). So the lifetime of r0 is quite limited.

If r0 is used in assembler, the code must be in one block. Otherwise intervening C RTL may well overwrite it.

Interrupts are pushed on stack by prolog and restored afterwards. r0 is used as temporary for this process. That is to avoid using some other register that would then need to be saved prior to use.

Andy


----------------------------------------------
Sent from my Dingleberry wired device.


-----Original Message-----
From: Stu Bell <address@hidden>
To: address@hidden; avr-gcc-list <address@hidden>
Sent: Tue, Aug 18, 2009 10:09 am
Subject: RE: [avr-gcc-list] Can functions modify register 'r0' or not?

AVR-LibC FAQ #13:
http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_reg_usage

R0 is a temp register, available for use in any function. The compiler
gurus will know if it needs to be pushed at the beginning of the
function and restored at the end.

My guess is that you are doing something funky with an Interrupt Service
Routine, but that's just a guess. Perhaps you can post the code you
think is bad.

Best regards,

Stu Bell
DataPlay (DPHI, Inc.)



> -----Original Message-----
> On Behalf Of address@hidden
>
> Hi all,
>
> In my code, I found that the global interrupts is disabled
> after one function is called. By reading the assembly code I
> found that this function uses register 'r0' to save the
> global interrupts in the prologue and restore it in the end.
> One of the functions been called in this function modified
> the register 'r0' and caused this problem.
>
> I wonder whether or 'r0' can be clobbered in functions. If
> so, why register 'r0' is used to save the global interrupts
> in that function.
>
> THX


_______________________________________________
AVR-GCC-list mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list

reply via email to

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