Shop OBEX P1 Docs P2 Docs Learn Events
PASM variables using RES — Parallax Forums

PASM variables using RES

JonnyMacJonnyMac Posts: 9,194
edited 2009-05-13 22:01 in Propeller 1
If I define a PASM variable with RES is it safe to assume that on launching the cog that variable will be zero, or could it be some random number based on stray bits in the cog ram?

Comments

  • RaymanRayman Posts: 14,827
    edited 2009-05-13 19:14
    Good question. I would guess that it wouldn't be random, but the actual value of HUB ram that follows the cog code...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My Prop Info&Apps: ·http://www.rayslogic.com/propeller/propeller.htm
  • ericballericball Posts: 774
    edited 2009-05-13 19:17
    Rayman said...
    Good question. I would guess that it wouldn't be random, but the actual value of HUB ram that follows the cog code...

    Your guess would be correct.· RES variables must be considered uninitialized.· If you want it to be zero on load you must declare it as LONG 0.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Composite NTSC sprite driver: http://forums.parallax.com/showthread.php?p=800114
    NTSC color bars (template): http://forums.parallax.com/showthread.php?p=803904
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-05-13 20:05
    Assuming you follow the rules and put your RES variables last, they will be initialized to whatever is in hub RAM after the last BYTE, WORD, or LONG in your DAT section. In other words, RES variables take up no space of their own in hub RAM but overlap with whatever follows the defined stuff. When the cog loads, that overlapping data gets loaded with it, up to the 496-long limit.

    -Phil
  • JonnyMacJonnyMac Posts: 9,194
    edited 2009-05-13 20:05
    Thanks for the feedback; I used mov phase, #0 in the setup section of the code -- everything is fine.
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-05-13 21:57
    If you have to move a value to the a variable which is defined by RES there is no difference in memory usage. Then you could also use long to define it, because the mov itself also needs 32 bits. So, I prefer the definition via LONG because you can initialize it with any value. If you initialize a RES with a mov, then you can only assign values in a range from $000 to $1FF.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-05-13 22:01
    MagIO2 said...
    If you have to move a value to the a variable which is defined by RES there is no difference in memory usage.
    That depends on how many times you have to do it. If but once at the beginning, you're right. But if it's a loop counter, for example, that has to be reinitialized each time at the beginning of the loop, a RES will save hub space.

    -Phil
Sign In or Register to comment.