[Top][All Lists]

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

[avr-gcc-list] Is this a Bug??????

From: Lorne Gutz
Subject: [avr-gcc-list] Is this a Bug??????
Date: Wed, 31 Jul 2002 08:21:17 -0400

This C code produced the assembler below.  The 2
write bits to PORTB are just added to help me
identify the code in assmebler.
C   code
cbi( PORTB, 0 );    // sos send
        while( timer_flag == 0 );  //wait for timer
cbi( PORTB, 1 );    // seakey send

In the assembley code, the variable 'timer_flag'
gets put into register r24 and then gets tested
repetedly.  The value of timer_flag never gets
reloaded into r24 the program hangs.

assemble code
/* #NOAPP */
        lds r24,timer_flag
/* #APP */
        cbi 24,0
/* #NOAPP */
        tst r24
        breq .L37
/* #APP */
        cbi 24,1
/* #NOAPP */
        ldi r24,lo8(0)
        rjmp .L28

The value of timer_flag is being incremented in an
interrupt ISR which works fine.

    extern uint8_t timer_flag;

and the assembler code of this function shows that
timer_flag is being incremented.

assemble code of ISR
        lds r24,timer_flag
        subi r24,lo8(-(1))
        sts timer_flag,r24

Well then I figured out a work around.  I declared
timer_flag as volatile, and BOB's your uncle, it
works.   Take a look at the assmebler code now.
it reloads r24 before it tests for zero.
/* #APP */
        cbi 24,1
/* #NOAPP */
        lds r24,timer_flag
        tst r24
        breq .L37
        sts timer_flag,__zero_reg__
        rjmp .L28

Well another long days work on the AVR


avr-gcc-list at http://avr1.org

reply via email to

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