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

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

[avr-gcc-list] Avr-gcc Removing Port Register Access


From: User Tomdean
Subject: [avr-gcc-list] Avr-gcc Removing Port Register Access
Date: Fri, 25 Aug 2006 22:27:37 -0700 (PDT)

I have a mid-sized application, about 400 lines of code, that behaves
strangely.  I am using avr-gcc version avr-gcc (GCC) 3.4.6, from the
FreeBSD port.  The application builds without error or warning (-Wall
-Wmissing-prototypes), behaves exactly like I expected, except for the
missing line of code.  I suspected a strange character in the line, so
I duplicated it, and, it works!

Looking at the output from avr-objdump, if the last sbi in the code
block is an access to the same register as the previous sbi, the last
sbi is dropped, even if the bits are different.  If the last sbi in
the code block is an access to a different register than the previous
sbi, the instruction is kept.

I have, in app.h,
...
#define LED_PORT PORTA
#define LED_OFF(n) LED_PORT |=  _BV(n)
#define LED_ON(n)  LED_PORT &= ~_BV(n)
#define WAIT_BIT (PINE & _BV(PINE0))
...

In app.c,
  int main() {
    ...
    while (1) {
      LED_ON(7);
      ...
      LED_ON(6);
      while (WAIT_BIT) ;
      LED_OFF(6);     /* sbi 0x1b,6 */
      LED_OFF(7);     /* sbi 0x1b,7 <== This instruction removed by avr-gcc*/
    }
    return 0;
  }

The last instance of LED_OFF is not in 'avr-objdump -d app.elf'
If I duplicate the line of code, it does appear.
     LED_OFF(7);
     LED_OFF(7);
But, only one time!  Strange!  Avr-gcc is dropping a line of code.  Why?

Anyone who knows what avr-gcc is doing willing to take a look at this?

tomdean





reply via email to

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