Shop OBEX P1 Docs P2 Docs Learn Events
strange behavior: declaring a LONG in a DAT block with no initial value — Parallax Forums

strange behavior: declaring a LONG in a DAT block with no initial value

agsags Posts: 386
edited 2013-03-23 12:15 in Propeller 1
I've been "optimizing" (aka "breaking") a driver I wrote and have stumbled on what seems to be strange behavior. I think I have it isolated, and presume there is a simple explanation (or I haven't really isolated the root cause).

I want to pass a value to a cog running a PASM driver from a SPIN init() method just before I start the cog. So, I declare a LONG in a DAT block, and assign the appropriate value to it just before starting the cog with coginit(...). I was previously using a "mailbox" method between SPIN and the cog (after starting it) to accomplish the initialization, but I realized I use more memory in the PASM code getting the value from the mailbox and assigning it to a RES location (which takes up no hub memory) than the LONG locations I'd consume in hub memory (in the DAT block - but only one for any number of OBJ instances of this driver).

I have my LONG declarations at the end of my DAT block, after the PASM code. When I do this:
var_1    long    'should not need a value, it is legal syntax in the Propeller Manual, and it does compile
var_2    long    'ditto

it compiles but does not run. If I do this:
var_1    long    0    'any value here works, I assign the actual value just before starting the cog
var_2    long    0    'ditto
it works as intended, regarless of the value I assign in the declaration. All I can think of is that without a value, the compiler does not allocate an actual location, and the symbols var_1 and var_2 end up both referring to the next location below.

Is this correct?

Comments

  • AribaAriba Posts: 2,690
    edited 2013-03-22 23:08
    A long without a value does not allocate a long in memory, it just forces the next data (next line) to a long aligned address.
    Sometimes it's important to have byte or word values on a long aligned address then you can do this:
    DAT
       byte 0,1,2
    
       long
       byte 4,5,6
    
    The byte with value 4 will be long aligned, also if you have only 3 bytes defined before.

    Andy
  • agsags Posts: 386
    edited 2013-03-23 12:15
    That explains it. Is that documented anywhere? It's made more obsure (to me) because (apparenlty) any line in a DAT block can have a label. Labeling the long (alignment only) statement makes it look (to me) like it's an unitialized location for data. e.g.:
    DAT
    myLong      long    $0F0F0F0F
    herLong     long    $F0F0F0F0
    hisLong     long    $AAAAAAAA
    uninitLong  long
    yourLong    long    $CCCCCCCC
    

    In the case above, I suppose that would cause labels <uninitLong> and <yourLong> to refer to the same location. Ugh.

    Thanks for the reply.
Sign In or Register to comment.