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

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

Re: [avr-gcc-list] Using a register throughout a program


From: Kang Tin LAI
Subject: Re: [avr-gcc-list] Using a register throughout a program
Date: Mon, 24 Sep 2001 22:22:23 +0800

Hi,

Yesterday I studied in detail of the avr.h file in avr source directory,
I found a description regarding the register allocation:

   The table initialized from this macro, and the table initialized by
   the following one, may be overridden at run time either
   automatically, by the actions of the macro
   `CONDITIONAL_REGISTER_USAGE', or by the user with the command
   options `-ffixed-REG', `-fcall-used-REG' and `-fcall-saved-REG'.  */

That means gcc has already considered such case, need not to modify the
gcc,
good!

So if you want a register dedicated from your own purposed, for your
case,
the r10, you may use

   -ffixed-r10 and -fcall-used-r10 in the command line.

Example:
fxn0(){
        init r10,
        asm (ld  r10,#1234); or something like this, I don't the exact.
        setup serial port,
        initiate serial transmission
}

serial_isr(){
        access r10
        do serial transmission
}

The -ffixed-r10 tells the compiler the fixed purpose of r10 and may not
be allocated, -fcall-used-r10 tells the code generator no need to
preserve
r10 in serial_isr(). But I don't know the outcome if r24,r25? Didn't
test,
but shouldn't try, :)

Hope help.

Cheers!
Kang.

Peter N Lewis wrote:
> 
> >Everything's working alright, but looking at the generated assembler
> >source, I noticed that my variable 'outcount' is stored in the AVR's SRAM
> >and loaded each time the signal handler gets called. I would have preferred
> >to store it in a register, because it's used fairly often.
> 
> This should be a FAQ.
> 
> the short answer seems to be "there is no easy way"..  A more
> complicated answer appeared recently:
> 
> At 11:57 +0800 6/9/01, Lai Kang Tin wrote:
> >I think you may try to change config/avr/avr.h in gcc source directory,
> >there are some defines for the usage of register allocation, change
> >what register(s) you wanted to FIXed purpose, but it seemded that you
> >must not change some of them such as R24 R25, X,Y,Z,...
> >Then recompile the GCC.
> 
> But in this case, I question the wisdom.  What speed is your
> processor running at and what speed is your serial running at?
> 
> Assuming 4MHz processor and 115,200 baud (pretty close to the worst
> case I can imagine), your interrupt will get executed at roughly
> 11kHz, or once ever 350 cycles.  Is the extra couple cycles to load
> and store the variable (and extra couple cycles of interrupt latency)
> really worth worrying about?
> 
> Enjoy,
>     Peter.
> 
> --
> Sungroper Solar Car Association <http://www.sungroper.asn.au/>
> 
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://avr.jpk.co.nz/mailman/listinfo/avr-gcc-list



reply via email to

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