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

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

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


From: Enno Luebbers
Subject: [avr-gcc-list] Using a register throughout a program
Date: Tue, 18 Sep 2001 20:45:35 +0200

Hi!

I'm currently happily hacking away at the AVR's UART. I have so far managed
to write a signal handler for the UART Data Register Empty interrupt to put
the next character into the UDR.

unsigned const char msg[] = "Patience is a virtue!\r\n";

SIGNAL( SIG_UART_DATA ) {
        static unsigned char outcount = 0;
        unsigned char dummy = msg[outcount++];
        if( dummy == 0 )
               outcount = 0;
        outp( dummy, UDR );
}

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. But trying a

register unsigned char outcount asm("r10");

or similar outside the signal handler was a little worrisome. Each time the
interrupt handler got called, it pushed r10 into exile onto the stack, then
used r10 (correctly), increased it by one (BTW, when does the gcc use INC
r10 and when SUBI r10, 0xff? Funny thing, that), but then annihilated all
the good work by popping the "old" (unadded) value into poor r10.

Is that a bug, or a feature? And if it is, how do I tell gcc that I do want
to use r10 for that purpose only? register static unsigned char outcount
asm("r10"), aside from being totally incomprehensible and hard on my
fingers, doesn't work - and doesn't make all that much sense, anyway.

Thanks in advance for your assistance to an AVR-GCC beginner!

Regards

Enno




reply via email to

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