[Top][All Lists]

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

Re: [avr-gcc-list] efficiency of assigning bits

From: E. Weddington
Subject: Re: [avr-gcc-list] efficiency of assigning bits
Date: Mon, 14 Mar 2005 12:28:01 -0700
User-agent: Mozilla Thunderbird 0.7.3 (Windows/20040803)

David Willmore wrote:

Hello, all.  I'm a bit confused by many of the comments in this
thread.  Where is there a guarentee that the two bits will be
set at the same time in any of the shown examples?

If I understand correctly, any of:

PORTD &= ~_BV(PD1);
PORTD &= ~_BV(PD4);


PORTD &= ~(_BV(PD1) | _BV(PD4));

or other variants are completely the same in what kind of code
they may generate when it gets down to machine language, no?

There is no implied simultinaity in any of these statements--
all C offers you is that the user code won't be able to tell
the difference--unless PORTD is defined as a volatile.  Which
may be the default and would explain my confusion.

Is that the critical bit that I'm missing?
Yes. PORTD and all of the AVR registers are defined as volatile. That is why you would want to combine the statements if you want simultaneous changing of the state of those two pins. If you don't care, then you're free to have them as two statements, but it would also be inefficient in terms of code space. Your choice.

reply via email to

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