Explain in detail/clarify- CON state ments (solved)

msiriwardenamsiriwardena Posts: 197
edited 2019-04-12 - 16:54:20 in Propeller 1
I am trying to understand the following statements n the con section.

CON
#-1, OPEN[0], OUT, CLOSE
mask = |< 21 | |< 22 | |< 23

I would like someone to explain these two statements so novice can understand.

Thank you,

Siri

Comments

  • The first one creates a continuous list of value

    aka

    OPEN[0] = 0
    OUT = 1
    CLOSE = 2

    the second one combines 3 BITS via or

    something = |<21 will produce a long with all bits 0 except BIT 21 high
    so your MASK will be set to a long with all BITS 0 and BIT 21,22,23 set

    Enjoy

    Mike
    I am just another Code Monkey.
    A determined coder can write COBOL programs in any language. -- Author unknown.
    Press any key to continue, any other key to quit

    The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this post are to be interpreted as described in RFC 2119.
  • JonnyMacJonnyMac Posts: 6,196
    edited 2019-04-14 - 17:01:34
    The first line holds enumerated constants. The line begins with #, the starting value, a comma, then a list of comma-separated constant names.

    (comment removed due to inaccuracy -- see @ersmith's post below)

    Note, too, that you can change the enumeration value mid-stream. Consider this:
    con
      #0, ALPHA, BETA, GAMMA, #23, OMEGA
    
    This is the same as:
    con
      ALPHA =  0
      BETA  =  1
      GAMMA =  2
      OMEGA = 23
    

    The |< operator is shorthand for "1 <<" which is used to create masks. The code above could have been written as
      MASK = (1 << 21) | (1 << 22) | (1 << 23)
    
    ...which would create a mask with bits 21, 22, and 23 set to 1 (all others cleared to zero).
    Jon McPhalen
    Hollywood, CA
    It's Jon or JonnyMac -- please do not call me Jonny.
  • @JonnyMac is right,

    I remembered incorrectly, sorry for any confusion, @msiriwardena.

    Enjoy!

    Mike
    I am just another Code Monkey.
    A determined coder can write COBOL programs in any language. -- Author unknown.
    Press any key to continue, any other key to quit

    The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this post are to be interpreted as described in RFC 2119.
  • The enumeration possibilities in CON are very confusing, even for experts like Jon. In fact:
    CON
    #-1, OPEN[0], OUT, CLOSE
    
    is OK (the square brackets are legal) and is equivalent to:
    CON
      OPEN = -1
      OUT = -1
      CLOSE = 0
    
    (At least, this is how both fastspin and openspin handle this. bstc doesn't like the "#-1", but it does accept "#(-1)" and then produces the same output as the other compilers.)

    The "#-1" says to start declaring constants with the value "-1".

    The "[0]" after "OPEN" says to skip 0 constants ahead after declaring it; the normal action is to skip 1 ahead. So "OPEN" and "OUT" will be declared to have the same value. If it had read "OPEN[4], OUT" then "OUT" would be "OPEN + 4".

    I think it's a bad idea to use the square brackets inside CON declarations, but they are legal.
  • JonnyMacJonnyMac Posts: 6,196
    edited 2019-04-14 - 20:42:06
    I erred, too.
    My style is to code as obvious as possible. While the index mechanism works and is legal, I would probably code it like this:
    con
      #-1, OPEN, #-1, OUT, CLOSE
    

    I think it's a bad idea to use the square brackets inside CON declarations...
    Agreed.


    Jon McPhalen
    Hollywood, CA
    It's Jon or JonnyMac -- please do not call me Jonny.
  • I think you need a # before the second -1. Even more obvious would be:
    con
      OPEN = -1, OUT = -1, CLOSE = 0
    
  • Fixed -- posted too early.

    If one is going to skip the enumeration, I think it best to put definitions on their own lines. That's my preference, anyway.
    Jon McPhalen
    Hollywood, CA
    It's Jon or JonnyMac -- please do not call me Jonny.
  • ersmith wrote: »
    I think it's a bad idea to use the square brackets inside CON declarations, but they are legal.

    If it is used for VAR, for example, like "X[0], Y", may produce same address for both X and Y.
    Using same algorithm for CON may produce same value for both X and Y.
Sign In or Register to comment.