[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] How to tell avr-gcc not to use some registers in the
Re: [avr-gcc-list] How to tell avr-gcc not to use some registers in the whole program?
Sat, 21 Feb 2009 19:40:32 +0100
Mozilla Thunderbird 1.0.7 (Windows/20050923)
Lin Nan schrieb:
In my project, I need to bind four registers to two 16 bit pointers because
the two pointers are used frequently. But I don't know exactly how to do it.
Does anyone know something about it?
You can do this by introducing two global register variables like
register foo_t * pfoo asm ("r2");
But note: If doing so /all/ of the sources that contribute to your
project must include this line and be aware of the new convention for
R2/R3, even if a module does not use the register: It must not alloc
them for register allocation. This includes libraries, so you must be
sure that no library you link against uses R2 or R3 (in the example
Also note the command line option -ffixed-2 -ffixed-3 that turn R2/R3
into fixed registers (in contrast to R2/R3 beeing call-saved-regs, which
is the default for them).
Also note that you most probably won't experience the desired reduction
of program memory and/or execution time. This is because the compiler
must move R2 to X, Y, or Z to access a location.
Making Y or Z global regs will crash the compiler sooner or later. I
would not recommend to make X global, either.
Best way to save program space is to gather stuff in a struct an pass a
pointer to the object to functions dealing with the object:
void foo (foo_t *pfoo);
This applies even if just one entity of foo_t exists. For small
functions this can reduce code size, but for more complex functions that
are no leaf the code may get worse. So there is nor general recommendation.