Shop OBEX P1 Docs P2 Docs Learn Events
PASM question about declaring variables... — Parallax Forums

PASM question about declaring variables...

Chris_DChris_D Posts: 305
edited 2009-10-06 21:40 in Propeller 1
Hi guys,

I am still working on my first PASM program and am doing pretty good (had it actually working but needs much improvement).· The one thing that is causing me confusion (as I copied the method from examples) is how variables are declared within a PASM program.· THere are two ways it is done...

Variable_1····· LONG··· Preset value

or

Variable_2···· RES····· 1


I can see that the first method allows me to preset the value and method two does not.· However, I also seem to recall that there is something more "complex" going on which dictates when to use which method.· Can someone clarify this for me?

Thanks

Chris
·

Comments

  • BradCBradC Posts: 2,601
    edited 2009-10-06 15:13
    As you correctly surmised, the former allows you to pre-allocate a value. This requires that variable actually consume a long of hub ram. The RES method allocates a COG variable, but it consumes no space in the cog. It's value is effectively undefined when the cog is loaded, so it needs to be properly initialised in the PASM program.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    lt's not particularly silly, is it?
  • jazzedjazzed Posts: 11,803
    edited 2009-10-06 15:28
    Also the RES variables should only be declared at the end of your COG code DAT section.
  • photomankcphotomankc Posts: 943
    edited 2009-10-06 15:36
    Would that be because the loaded COG instructions would be laid over the variable space otherwise?
  • Chris_DChris_D Posts: 305
    edited 2009-10-06 15:44
    Brad,

    Being that the first method consumes a variable of HUB memory, does that mean that HUB memory is accessed everytime that variable is accessed?· If so, that would me the time to access it would be much longer than an undefined variable.

    Chris




    BradC said...
    As you correctly surmised, the former allows you to pre-allocate a value. This requires that variable actually consume a long of hub ram. The RES method allocates a COG variable, but it consumes no space in the cog. It's value is effectively undefined when the cog is loaded, so it needs to be properly initialised in the PASM program.

  • BradCBradC Posts: 2,601
    edited 2009-10-06 16:07
    Chris_D said...
    Brad,

    Being that the first method consumes a variable of HUB memory, does that mean that HUB memory is accessed everytime that variable is accessed? If so, that would me the time to access it would be much longer than an undefined variable.

    No. When you load the cog the contents are copied from HUB ram to the COG directly. From then on, every access to that variable from inside the cog is local, just the same as the RES variables.

    That is unless you manually access the HUB ram incarnation of it using rdlong/wrlong.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    lt's not particularly silly, is it?
  • jazzedjazzed Posts: 11,803
    edited 2009-10-06 16:47
    photomankc said...
    Would that be because the loaded COG instructions would be laid over the variable space otherwise?
    Yes. It's almost like using long without an initialization value.
  • Chris_DChris_D Posts: 305
    edited 2009-10-06 21:40
    Thanks guys.

    Chris
Sign In or Register to comment.