View Full Version : Difference between LONG and RES
01-28-2007, 07:15 PM
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
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!
01-28-2007, 10:31 PM
Make sure you don't mix up RES and Longs:
01-29-2007, 07:29 AM
Yes, RES variables must occur after all declared LONGs.
Paul Baker (mailto:email@example.com)
Propeller Applications Engineer
Parallax, Inc. (http://www.parallax.com)
01-29-2007, 07:22 PM
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.
8 + 8 = 10
01-30-2007, 01:27 AM
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.