dnaddor
01-09-2009, 04:50 AM
Hi y'all.
I've never liked how I shared data between SPIN and ASM. I often have lots of different sized structures, and it is too easy to make a mistake in the offsets (like forgetting to multiply by 4). I prefer to access all variables by name.
Today, I figured out an easy way to do this. The "trick" is to have a DAT section with this line:
Memory long @Memory
and then start a cog with this:
COGSTART(@CogThread, @Memory - Memory)
Now in ASM, you can access data easily by using PAR and adding the offset to the variable.
I included a simple test program. All it does is print 100+200=300.
I've never liked how I shared data between SPIN and ASM. I often have lots of different sized structures, and it is too easy to make a mistake in the offsets (like forgetting to multiply by 4). I prefer to access all variables by name.
Today, I figured out an easy way to do this. The "trick" is to have a DAT section with this line:
Memory long @Memory
and then start a cog with this:
COGSTART(@CogThread, @Memory - Memory)
Now in ASM, you can access data easily by using PAR and adding the offset to the variable.
I included a simple test program. All it does is print 100+200=300.