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

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

Re: [avr-gcc-list] avr-gcc bug: global register variable is broken


From: Dmitry K.
Subject: Re: [avr-gcc-list] avr-gcc bug: global register variable is broken
Date: Thu, 2 Dec 2004 10:45:20 +1000
User-agent: KMail/1.5

At 2 Dec 2004 Klaus Rudolph wrote:
...
> Any idea for a workaround? I need some register vars for interrupt handler
>

Small addition: remember about that is impossible to declare register vars as  
volatile. (This is not avr-specific.) You need to write special code for  
interraction with interrupt handler through such vars.

For example:

   register unsigned char reg asm ("r2");

   void foo1 (void);

   void foo (void)
   {
       do {
           if (reg & 1) {
               foo1();
               reg &= ~1;
           }
       } while (1);
   }

   void foo2 (void)
   {
       do {
           if ( ({
                   unsigned char __c;
                   asm volatile ("" ::: "r2");
                   __c= reg;
               }) & 1 )
           {
               foo1();
               reg &= ~1;
           }
       } while (1);
   }

foo:   incorrect code with `-O3'
foo2:  always OK

Regards.



reply via email to

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