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

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

Re: [avr-gcc-list] Problem with delay loop


From: Royce Pereira
Subject: Re: [avr-gcc-list] Problem with delay loop
Date: Fri, 28 Sep 2007 14:32:39 +0530
User-agent: Opera Mail/9.22 (Win32)

Hi,
On Fri, 28 Sep 2007 14:47:26 +0530, David Brown <address@hidden> wrote:

>
> This is probably in the FAQ somewhere - if not, it should be!
>
> The compiler is smart enough to figure out that your delay function does
> no useful work - thus the optimiser does not generate any code.  This is
> correct compilation - it's your code that is wrong.  The difference is
> that the newer version of the compiler is smarter than the older version
> (or newer makefiles have higher optimisation enabled by default).
>
> The correct way to write such a loop is:
>
> void delay(unsigned int del_cnt) {
>       volatile unsigned int n = del_cnt;
>       while (n--);
> }

So I have to write more 'C' code :) to get the same stuff done, in the 'new & 
smarter' compiler! Interesting.....

Doesn't seem right, some how.

Regards,
--Royce.

> mvh.,
>
> David
>
>
> Royce Pereira wrote:
>> Hi all,
>>
>> In the latest WinAVR (avr-gcc (GCC) 4.1.2 (WinAVR 20070525) I found this.
>>
>> Check this out:
>> //======================
>> void delay(unsigned del_cnt)
>>     {
>>        while(del_cnt--);
>>
>>        return;
>>     }
>> //=======================
>>
>> Compiles as (from the .lss file):
>>
>> //=======================
>> void delay(word cnt)
>>     {
>>   2aa:       08 95           ret
>>
>>        while(cnt--);
>>
>>        return;
>>     }
>> //=======================
>>
>> The loop is not executed !!
>>
>> Where as in an older version (WinAVR-20060421)
>>
>> It compiles correctly as:
>> //==========================================
>> void delay(word cnt)
>>     {
>>        while(cnt--);
>>   286:       01 97           sbiw    r24, 0x01       ; 1
>>   288:       2f ef           ldi     r18, 0xFF       ; 255
>>   28a:       8f 3f           cpi     r24, 0xFF       ; 255
>>   28c:       92 07           cpc     r25, r18
>>   28e:       d9 f7           brne    .-10            ; 0x286 <delay>
>>   290:       08 95           ret
>>
>>
>>        return;
>>     }
>> //=======================================
>>
>> As a result none of my delays used in my older programs work when 
>> recompiled...
>>
>> Thanks,
>>
>> --Royce
>>
>
>
>
> _______________________________________________
> AVR-GCC-list mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
>



-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/




reply via email to

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