Explain in detail/clarify- CON state ments (solved)
msiriwardena
Posts: 301
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
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
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
(comment removed due to inaccuracy -- see @ersmith's post below)
Note, too, that you can change the enumeration value mid-stream. Consider this:
This is the same as:
The |< operator is shorthand for "1 <<" which is used to create masks. The code above could have been written as
...which would create a mask with bits 21, 22, and 23 set to 1 (all others cleared to zero).
I remembered incorrectly, sorry for any confusion, @msiriwardena.
Enjoy!
Mike
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.
My style is to code as obvious as possible. While the index mechanism works and is legal, I would probably code it like this:
Agreed.
If one is going to skip the enumeration, I think it best to put definitions on their own lines. That's my preference, anyway.
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.