Shop OBEX P1 Docs P2 Docs Learn Events
Is There an ANDN Spin equivalent? — Parallax Forums

Is There an ANDN Spin equivalent?

Duane DegnDuane Degn Posts: 10,588
edited 2012-12-15 21:07 in Propeller 1
I want to make sure a single bit is set low within a mask. It's easy in PASM with "andn", but I can't think of a quick way of doing it in Spin.

I can think of several ways to do this in Spin but they are all messy and long.

I don't need to know if the bit is there, I just want to make sure it's not once the operation is done.

Do any of you have a good technique for setting a bit to zero in Spin?

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2012-12-15 20:46
    What's wrong with ... & !mask? Or use a special register (e.g. outb).
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-12-15 20:56
    Thanks for the reply. I'm not following you.

    Here's code that works as long as the bit in "enableMask" is set in "activeMask":
    activeMask -= enableMask
    

    "activeMask" is read from a PASM driver to set pin states.

    For this example lets assume enableMask equals one while activeMask can either be two or three. If activeMask equals three the above code works but if it equals two then it doesn't.

    CouldWould you show me how to use a "& !" mask? I'm still not thinking of a simple way to use them.

    Edit: A light just went on in my head. If you wait a bit, I'll give it a try.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-12-15 21:01
    activeMask &= !enableMask
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-12-15 21:05
    Mike Green wrote: »
    activeMask &= !enableMask

    Mike, Didn't you see the "wait a bit" part?:smile:

    Here's what I came up with:
    outb := !enableMask
      activeMask &= outb
    

    I see that Mike's is shorter.

    Thank you both.
  • kuronekokuroneko Posts: 3,623
    edited 2012-12-15 21:07
    @Duane: outb usage was meant to be used like outb[zero_bit] := 0. Obviously only useful for single bits.
Sign In or Register to comment.