[A89] Re: Setting bit fields


[Prev][Index][Thread]

[A89] Re: Setting bit fields




At 21:50 2002-02-28, you wrote:

> > I want to change some things in the I/O ports. $600015. But i dont want to
> > change all bits. What is the most used way to do this?
> > ...
> > AND all bits to be reset with 0 and OR the bits to be set with 1? Or
> > should I just move a byte over there?
>
>Yup, you should only need two total instructions -- one AND, one OR.  You
>can AND multiple bits in one instruction by ANDing the entire byte with a
>mask (want to reset all but bit 6?  AND the byte with 0xBF); same thing with
>OR.

If it is just a few bits you could just as well use the instructions bset 
and bclr.
increases readability too.
if you do a lea to an adress reg first and then one and and one or, you 
take 14 bytes. (16 without the lea)
that is equal to up to four bset/bclr.
don't know about speed difference though, since I don't have my book here.
actually I'm not even 100% sure all adress modes mentioned above is legal 
:) but I think they are.


//Olle





References: