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

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

AW: [avr-gcc-list] Bug in with optimization -01,-02,-03


From: Stumpf Michael
Subject: AW: [avr-gcc-list] Bug in with optimization -01,-02,-03
Date: Tue, 23 Jul 2002 13:32:07 +0200

Hello,
 
that is exactely what volatile is for.
So no bug, just valid optimized code.
Declare the variable volatile and the compiler knows it might change
anytime without its knowledge.
 
regards
Michael Stumpf
-----Ursprüngliche Nachricht-----
Von: Marko Panger [mailto:address@hidden
Gesendet: Dienstag, 23. Juli 2002 12:26
An: address@hidden
Betreff: [avr-gcc-list] Bug in with optimization -01,-02,-03

Hello all !!
 
I am not 100% sure, but I think I found a bug. This bug happens only with -0O1, -O2, -O3 optimization options. It is working fine with -O0, -Os.
 
Please find attached the entire (small) project.
 
Short description:
I have defined a global variable "Ticks" which I increment in a interrupt handler. I am checking this variable in my main loop. Now examine the source code produced by GCC:
 
Interrupt rutine:
 
   +00000028: 921F      PUSH    R1
   +00000029: 920F      PUSH    R0
   +0000002A: B60F      IN      R0,0x3F
   +0000002B: 920F      PUSH    R0
   +0000002C: 2411      CLR     R1
   +0000002D: 938F      PUSH    R24
   +0000002E: 91800060  LDS     R24,0x0060
   +00000030: 5F8F      SUBI    R24,0xFF          ; 0xFF = 0b11111111 = 255
   +00000031: 93800060  STS     0x0060,R24
   +00000033: 918F      POP     R24
   +00000034: 900F      POP     R0
   +00000035: BE0F      OUT     0x3F,R0
   +00000036: 900F      POP     R0
   +00000037: 901F      POP     R1
   +00000038: 9518      RETI
 
Main Loop:
 
+0000004E: 91800060  LDS     R24,0x0060
   +00000050: 94F8      CLI
   +00000051: 3085      CPI     R24,0x05          ; 0x05 = 0b00000101 = 5
   +00000052: F021      BREQ    +0x04             ; Destination: 0x000057
   +00000053: 9478      SEI
   +00000054: 30C8      CPI     R28,0x08          ; 0x08 = 0b00001000 = 8
   +00000055: F7D1      BRNE    -0x06             ; Destination: 0x000050
 
In the interrupt rutine the variable, which resides on 0x0060, is incremented by one.
 
Now have a look in the main loop. First the code loads the variable in R24 and then compares it with 5, but R24 isn't refreshed any more. Is this a bug ?
 
If I define the variable as volatile all works fine.
 
What do you think ?
 
Regards,
Marko Panger
 
 
 

reply via email to

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