Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: Arrays and pointers in GCC

2009-01-12 by Don Kinzer

--- In AVR-Chat@yahoogroups.com, "David VanHorn" <microbrix@...> wrote:
> Normally in any app I write in ASM, I dedicate two
> registers for usage in the ISR, ITEMP and ITEMP2,
> and one to hold SREG, "STEMP"
That is a perfectly reasonable (partial) set of register allocation 
assumptions for a small set of applications.  The avr-gcc compiler, on 
the other hand, has a set of register allocation assumptions that work 
for all applications.  These assumptions are documented in the FAQ 
(see http://www.nongnu.org/avr-libc/user-
manual/FAQ.html#faq_reg_usage) but are summarized as:

* r1 always has the value zero
* A function can freely modify r0, r18-27, r30-31.
* A function may not modify r2-17, r28-29.  If these registers are 
used they must be saved/restored.

Moreover, an ISR must preserve all register values and cannot rely on 
r1 being zero.

There is a way to inform the compiler that you're going to use certain 
registers for your own special purposes (see http://www.nongnu.org/avr-
libc/user-manual/FAQ.html#faq_regbind) but this practice is 
discouraged.

The code that was generated for the ISR is reasonable with respect to 
these assumptions.  It is a known issue, however, that generated ISR 
code sometimes goes to the trouble of saving and zeroing r1 when it 
doesn't use r1 itself and doesn't call any external functions.

It is also true that as changes are made to the gcc compiler, there 
are sometimes regressesions in the "quality" of the code produced by 
the avr-gcc variant.  These take time to get repaired and it may make 
sense sometimes to continue to use an older version until the newer 
one is improved.  I currently use the 20071221 version and would 
recommend it unless/until there is a specific reason to use a newer 
version.

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.