Re: A92: testing bits of byte


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

Re: A92: testing bits of byte



At 03:34 PM 10/29/97 -0600, you wrote:
>i need to test the bits of a byte and jump to some place if its one or 
>some other place if its zero.
>i tried using btst.b but that just caused crashes. i was thinking about 
>this instead:
>
>and #%0000001,d0  ; i think this modifies d0?
>cmp.b #%0000001,d0 ; (if not this won't work)
>bne place2   ; means its zero
>bra place1   ; means its one

Though you can and should use the btst method, if you did use "and" you
would not need to follow it with "cmp"; "and" by itself would set the zero
flag according to whether or not the result was zero. (So you could remove
the "cmp" and replace the "bne" with a "beq" to get the same result.)

>will that work?  am i using btst wrong?
>i tried:
>btst.b #1,d0
>bne
>bra
>..
> 
>does btst change d0?

First of all, when using "btst" to test a register, you do not need to
specify ".b", ".w", or ".l". If you do, it will be ignored; "btst" on a
register is always ".l", since data registers have 32 bits.

If you're testing for %00000001, that would be bit #0, not bit #1:

  btst #0,d0
  bne place2 ; if bit is set
  bra place1 ; if bit is clear

And no, btst does _not_ change d0.

---
David Ellsworth
davidell@earthling.net
IRC: eXocomp
ICQ: 2300673


References: