[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] GCC 3.0.2 unsigned int bug?
From: |
Carsten Beth |
Subject: |
Re: [avr-gcc-list] GCC 3.0.2 unsigned int bug? |
Date: |
Mon, 17 Dec 2001 22:58:26 +0100 |
Hi Chris!
Maybe you are compiling with optimization switch on. Then the compiler shortens
the loop, actualy the following program do (except from the timing) the same
thing:
void delay(void)
{
unsigned int d;
d = 0x1000;
d = 0;
}
and also
void delay(void)
{
unsigned int d;
d = 0;
}
do the same.
You can try something like this:
#define nop() __asm__ __volatile__ ("nop")
void delay(void)
{
unsigned int d;
for( d = 0; d < 0x1000; d++ )
nop();
}
Carsten
Chris Elmquist wrote:
>
> I'm having trouble understanding this:
>
> void delay(void)
> {
> unsigned int d;
>
> d = 0x1000;
> while (d) d--;
> }
>
> generates this code (using avr-objdump --disassemble):
>
> 0000004a <delay>:
> 4a: 80 e0 ldi r24, 0x00 ; 0
> 4c: 90 e1 ldi r25, 0x10 ; 16
> 4e: 80 50 subi r24, 0x00 ; 0
> 50: 94 40 sbci r25, 0x04 ; 4
> 52: e9 f7 brne .-6 ; 0x4e
> 54: 08 95 ret
>
> I can clearly see that the MSB goes in r25 and the LSB in r24
> but then why does it subtract 0x04 from the MSB each iteration?
>
> Suspecting maybe a disassembler problem, the '94 40' opcode
> indeed would subtract 0x40 from the MSB wouldn't it?
>
> Am I missing something obvious here or is this a bug?
- Re: [avr-gcc-list] GCC 3.0.2 unsigned int bug?, (continued)
[avr-gcc-list] 4-bit LCD source, Mike Jones, 2001/12/17
Re: [avr-gcc-list] GCC 3.0.2 unsigned int bug?, Dmitry, 2001/12/18
Re: [avr-gcc-list] GCC 3.0.2 unsigned int bug?,
Carsten Beth <=
Re: [avr-gcc-list] GCC 3.0.2 unsigned int bug?, john . johnson, 2001/12/17
Re: [avr-gcc-list] GCC 3.0.2 unsigned int bug?, Francisco T. A. Silva, 2001/12/17