Shop OBEX P1 Docs P2 Docs Learn Events
Difference between LONG and RES — Parallax Forums

Difference between LONG and RES

peterzpeterz Posts: 59
edited 2007-01-29 18:27 in Propeller 1
In an ASM program which is the difference between LONG and RES variables ?
I understand that variables stated as LONG can be initialized, but other than this, is there any difference ?

For example, between the following two sentences:

myvar LONG 0

OR

myvar RES 1

I ask because I have changed some RES variables to LONG so as to have them initialized and my program ceased to work!

·

Comments

  • scottascotta Posts: 168
    edited 2007-01-28 15:31
    Make sure you don't mix up RES and Longs:

    OK

    long
    long
    res
    res

    Not Ok

    Long
    res
    Long
    res
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-01-29 00:29
    Yes, RES variables must occur after all declared LONGs.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • John R.John R. Posts: 1,376
    edited 2007-01-29 12:22
    I think what PeterZ was asking (and I'd like to know), is what is the difference between Long and Res, and why you would use a Res variable in stead of a Long.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John R.

    8 + 8 = 10
  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-29 18:27
    Remember that an assembly program resides in the Hub memory and gets copied to a Cog with a COGINIT or COGNEW statement for execution. The Hub copy stays around and occupies memory that otherwise isn't easily usable. Some assembly programs may have a lot of variables that don't need to be pre-initialized with some constant value. The RES statement assigns a location in Cog memory to a variable, but doesn't actually occupy Hub memory. What happens is that, since the RES statements must come last in the assembly program, their space is actually filled by whatever the Propeller Tool stores next in Hub memory. This may be Spin byte codes for some method or some other DAT section information or whatever. This "junk" actually gets copied into the Cog, but it doesn't matter since a RES variable is undefined when the Cog routine starts.
Sign In or Register to comment.