[Top][All Lists]

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

Re: [avr-gcc-list] Strange inline asm bug or silly user?

From: Niklas Holsti
Subject: Re: [avr-gcc-list] Strange inline asm bug or silly user?
Date: Tue, 20 Jul 2010 10:27:31 +0300
User-agent: Mozilla-Thunderbird (X11/20100328)

David Carr wrote:
I'm just learning to use inline assembly with avr-gcc, and I've encountered what seems to me to be a very strange bug (but may be user silliness).

In the test case below, I repeatedly change the first entry of the data array between 0xFF and 0x00. A short piece of assembly then moves data[0] into r0 and pushes it out to PORTB. This causes an LED to flash. This works.

However, when I change:

"ldd r0, %a1+0 \n\t"
"out %0, r0 \n\r"


ldd r1, %a1+0 \n\t"
"out %0, r1 \n\r"

IE: replace r0 with r1, the LED just stays lit continuously.

I believe that avr-gcc uses r1 in a special way: this register is always assumed and expected to contain zero. When your code uses r1 as a temporary, it violates that assumption by putting some non-zero value in r1. This can make some other parts of the gcc-generated code fail in wild ways. You can check that this is the problem by extending your inline assembly in send_packet to (re)set r1 to zero before returning, for example by the "clr r1" instruction. But of course the better solution is not to use r1 in ways that confuse gcc, and to use some other available register instead.


Niklas Holsti
Tidorum Ltd

reply via email to

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