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

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

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


From: Marko Panger
Subject: [avr-gcc-list] Bug in with optimization -01,-02,-03
Date: Tue, 23 Jul 2002 12:25:54 +0200

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
 
 
 

Attachment: main_app.c
Description: Binary data

Attachment: led.c
Description: Binary data

Attachment: adc.c
Description: Binary data

Attachment: types.h
Description: Binary data

Attachment: led.h
Description: Binary data

Attachment: adc.h
Description: Binary data

Attachment: makefile
Description: Binary data


reply via email to

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