[Top][All Lists]
[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:21:38 +0530 |
User-agent: |
Opera Mail/9.22 (Win32) |
Hi,
On Fri, 28 Sep 2007 13:42:18 +0530, Klaus Rudolph <address@hidden> wrote:
> The code has been optimized. Well done!
> If you need the variable access use 'volatile'
>
Why does it get optimised?
I understand the meaning of 'volatile', but why is it required here ?
It is clear that the variable is changing in the code itself (not outside it).
Again- it worked in the older avr-gcc. Was that a bug(the fact that it worked)?
even rewriting it as:
//--------------------
void delay(unsigned cnt)
{
while(cnt)
cnt--;
}
//--------------------
does not work. (Why not ?)
Thanks,
--Royce.
>> 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;
>> }
>> //=======================================
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> 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/