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

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

Re: [avr-gcc-list] Bad code generated when using volatile keyword/-O0 op


From: Joerg Wunsch
Subject: Re: [avr-gcc-list] Bad code generated when using volatile keyword/-O0 opt?
Date: Mon, 13 Feb 2006 10:13:00 +0100 (MET)

Rick Mann <address@hidden> wrote:

> I've boiled this down to a pretty simple case, I think. In the =20
> following code, if compiled with -Os, if "d" is made volatile, then
> =20 it never seems to get past execution in the first delay loop.

What compiler?

With GCC 3.4.5, the "volatile" keyword and -Os, I get the following
assembly code:

        ldi r24,lo8(48)
        out 52-0x20,r24
        out 53-0x20,__zero_reg__
        ldi r19,lo8(32)
        ldi r25,lo8(-1)
        ldi r18,lo8(16)
..L2:
        out 53-0x20,r19
        std Y+1,r25
..L4:
        ldd r24,Y+1
        subi r24,lo8(-(-1))
        std Y+1,r24
        ldd r24,Y+1
        cpi r24,lo8(-1)
        brne .L4
        out 53-0x20,r18
        std Y+1,r25
..L6:
        ldd r24,Y+1
        subi r24,lo8(-(-1))
        std Y+1,r24
        ldd r24,Y+1
        cpi r24,lo8(-1)
        brne .L6
        rjmp .L2

Both delay loops look exactly the same, and I couldn't see why they
would not terminate.

Of course, for a real delay loop, I'd rather recommend you to use the
functions from <util/delay.h>.

-- 
J"org Wunsch                                           Unix support engineer
address@hidden        http://www.interface-systems.de/~j/




reply via email to

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