Shop OBEX P1 Docs P2 Docs Learn Events
Noob spin questions — Parallax Forums

Noob spin questions

cthomascthomas Posts: 17
edited 2012-12-06 16:57 in Propeller 1
Hi All;

Two questions...

First, given OUTA[8] := (idx) where idx is a local variable, does OUTA[8] get assigned the value of the lowest bit of idx?

Second, and related;

if idx varies from 0 to 7 and is currently 6, does OUTA[8..10] := %idx assign values like so..
OUTA[8] gets 1
OUTA[9} gets 1
OUTA[10] gets 0

Or perhaps in the above case, does it work without using the %?

Sorry for the simple questions and thanks in advance for any answers. I'm not in a position to test this for a couple days and it's bugging me!

Craig

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2012-12-05 23:44
    Yes and yes. In the latter case the % isn't required (compile error). You only need it when you want to use a literal (binary) value (e.g. %101). Note that the order of the bit range is important ([9..10] vs [10..8]).
  • cthomascthomas Posts: 17
    edited 2012-12-06 09:12
    Thanks very much!

    Appreciated.

    Craig
  • danielstrittdanielstritt Posts: 43
    edited 2012-12-06 13:13
    You can use other bits from the local variable. To assign OUTA[x] to the 2nd bit, it would be "OUTA[x] := (variable & %10).
  • MagIO2MagIO2 Posts: 2,243
    edited 2012-12-06 13:48
    @danielstritt:
    Are you sure? I'd doubt that! I think you'd have to shift the second bit in this case. Or you have to use the boolean and instead!
  • Mike GreenMike Green Posts: 23,101
    edited 2012-12-06 15:01
    You do have to shift the value. OUTA[ x ] is a one-bit value for bit #x that gets set to the the least significant bit of the expression assigned to it (like OUTA[ 3 ] := 1). You can refer to a 2 (or more) bit portion of the OUTA register by writing OUTA[ x..y ] where x is the most significant bit number and y is the least significant bit number. If x < y, then the bits in OUTA are reversed in order.
  • danielstrittdanielstritt Posts: 43
    edited 2012-12-06 16:57
    Ahh, I see. Live and learn, I guess!
Sign In or Register to comment.