[Top][All Lists]

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

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

From: Ben Mann
Subject: RE: [avr-gcc-list] efficiency of assigning bits
Date: Mon, 14 Mar 2005 19:20:28 +0800

Hi Jamie

There has been neverending discussion on this.

Essentially, if you read the datasheet, you will see that cbi/sbi only works
on *some* ports, while read/modify/write works on all. The compiler will use
whatever is most efficient regardless of whether you use the sbi() macro.

Therefore using
 some_port = sbi(my_bit);
is equivalent to
 some_port = some_port | _BV(my_bit);
however the latter does not confuse anyone and is a better (and more
portable) higher-level representation of what is happening.

If you are concerned with counting clock cycles, usually inline or pure
assembly is a much better choice.


Ben Mann

-----Original Message-----
From: address@hidden
[mailto:address@hidden On Behalf Of Jamie
Sent: Monday, 14 March 2005 5:59 PM
To: Parthasaradhi Nayani
Cc: address@hidden
Subject: Re: [avr-gcc-list] efficiency of assigning bits


----- Original Message -----
From: Parthasaradhi Nayani <address@hidden>
Date: Sunday, March 13, 2005 7:12 am
Subject: Re: [avr-gcc-list] efficiency of assigning bits

> Hello,
> To turn two bits off, the method I would adopt is
>  PORTD &= 0B11101101;
> This is the fastest method.

What does that work out to in assembly?  A cbi/sbi assembly instruction is 2
clock cycles.  I still don't understand why these instructions would be
taken out of winavr, they obviously are useful for them to have been
included as opcodes in the AVR! :)

Is it possible to do inline assembly with cbi/sbi?
Something like this:


--gives an error though


> The cbi and sbi instructions are removed in the latest version of 
> winavr and can not be used. Moreover the two instructions take more 
> time and more space compared to the above example.
> Nayani
> __________________________________
> Do you Yahoo!? 
> Make Yahoo! your home page 
> http://www.yahoo.com/r/hs

AVR-GCC-list mailing list

reply via email to

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