[Top][All Lists]

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

Re: [avr-gcc-list] Not naked but "topless" functions?

From: Larry Barello
Subject: Re: [avr-gcc-list] Not naked but "topless" functions?
Date: Thu, 17 Oct 2002 08:45:22 -0700

Avr-gcc has only 8 temporary registers available.  It steals a few others as
conditions permit (e.g. if there is no frame, it can use Y, it can also use
just about everything else if conditions permit)  It also does a *very* good
job of recycling registers throughout the function.  That is why you can
declare many more local variables than actually get allocated.  However,
just try to declare a structure with more than 8 bytes and see what happens,
or have an endless loop (while(1) { ... }) and use automatics to hold state
variables (variables that never go out of scope) and recycling is no longer
possible and when you hit the 8 byte limit stuff *will* go onto the stack.

I may have the details off a bit, but the general idea holds: Naked is
broken except in restricted circumstances, Kang's version of "naked"
(actually "noreturn") should be in GCC as it covers "naked" and allows frame


----- Original Message -----
From: "Kang Tin LAI" <address@hidden>
> >
> > Only 8? Once I tested how many register variables I can have, and when I
> > 30 of them, compiler put only 5 of them on the stack!? When I used 20,
> > was on the stack. Is there an fixed number of available registers? Some
> > reserved like r0,r1. All other registers are free or not?
> >
> It is depended on what type of local vars, for example:
> char a, b, c, d;
> If in your function, no "address" operation, such as &a; then all vars
should be
> hold by register, another case, in your function, a function call for
> takes a address of a vars as argument:
> swap(&a, &b);
> then a and b will be allocated in the stack.
> I believe that number of register allocated for local vars is not a

avr-gcc-list at http://avr1.org

reply via email to

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