strange behavior: declaring a LONG in a DAT block with no initial value
ags
Posts: 386
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:
it compiles but does not run. If I do this:
Is this correct?
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 'dittoit 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
Sometimes it's important to have byte or word values on a long aligned address then you can do this: The byte with value 4 will be long aligned, also if you have only 3 bytes defined before.
Andy
In the case above, I suppose that would cause labels <uninitLong> and <yourLong> to refer to the same location. Ugh.
Thanks for the reply.