View Full Version : spin and assembly mix
01-12-2009, 04:26 PM
i am trying to figure out how to read a variable declaired by spin in hub ram modify it on the cog then write back to hub ram.
TimeKeeper wrlong startDate,ulDate
startDate is an assembly constant. ulDate is not recognized though in assembly so what can I use?
That will not work that way, OTOH wrlong is defined as:
The point here is that ulDate may be in stack or somewhere else. You have to give a pointer to it to the assembler program. Then it is much better to just define it in a DAT section:
ulDate long 0
wrlong ulDate_c, startDate
ulDate_ long @ulDate
startDate long 0
Something like that
01-12-2009, 04:41 PM
so variables used in spin do not have to be defined in var section they can be defined in dat
Yes and no.
The access to variables in DAT section should be done with the long, word and byte ways. The variables defined in VAR sections can be used directly. If I'm not mistaken. The Propeller manual is a very good source of information on the topic.
01-13-2009, 12:55 AM
Check out this thread: http://forums.parallax.com/showthread.php?p=775317
Btw, wrlong is actually wrlong <cog address>, <hub address> (the reverse of what Ale wrote). It's a little confusing because it violates the expected "destination, source" order. Just remember that all the hub memory ops (rdbyte, wrbyte, rdword, etc.) expect <cog address>, <hub address>.
And, sorry to correct Ale again, but you can access variables in dat sections just as you would an ordinary variable.
01-13-2009, 01:06 AM
I use DAT defined variables directly in SPIN all the time. There may be limitations (my objects are all less than 496 longs including DAT) but it's handy to have a mirror of the HUB memory locations mirrored into COG memory on startup. This way I don't have to initialize my variables in SPIN if I know what their values are going to be at compile time: I can reference·the predefined variable·in the first line of my object without initializing it at runtime, and I know it will be whatever I set it to in the DAT section.
01-13-2009, 10:29 AM
what am I doing wrong? Trying to experiment with assembly and spin together. I have 2 cogs running. 1 running an assembly program that keeps track of the time of day accurate to the ms. the second says the time out load when pin 16 is toggled. The vocalization works and says the initial time but that value is never incremented.
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
sound_port = 10
ulTime long 3_500_000 ''ulTime <-- msec
oT : "talk"
0 : oT.say(string("oa~klok"))
1 : oT.say(string("wun~"))
2 : oT.say(string("too"))
3 : oT.say(string("three"))
4 : oT.say(string("for"))
5 : oT.say(string("faev"))
6 : oT.say(string("siks"))
7 : oT.say(string("s'even~"))
8 : oT.say(string("ayt"))
9 : oT.say(string("naen~"))
'run every ms
TimeKeeper rdlong ulMSec,ulTime 'Copy sec over
add ulMSec,#1 'Add 1 to MSec
cmp ulMSec,ulDayLength 'See if day done
if_b jmp :updateTime 'If day is done jump to end of routine
'run every day
mov ulMSec,#0 'Set Time to midnight
:updateTime wrlong ulMSec,ulTime 'Update the time
waitcnt cnt, ticTime 'Delay for 1ms
'Locale Time Value
ulMSec long 0
ulDayLength long 86_400_000
ticTime long 80_000
01-13-2009, 01:32 PM
Try these changes:
ptrToUlTime := @ulTime '*** NEW ***
:updateTime wrlong ulMSec, ptrToUlTime 'Update the time *** CHANGED ***
waitcnt cnt, ticTime 'Delay for 1ms
ptrToulMSec long 0 ' *** NEW ***
If they help, I'll explain what's happening. If they don't, let us never speak of this post again.
mpark is right, what I was thinking again ?, sorry.
01-13-2009, 02:11 PM
as writen it will not compile.
changed ptrToulMSec on last line to ptrToUlTime still does not work. Canged read instruction to use this still no luck.
01-13-2009, 02:49 PM
well the pointer method works for writing the value but for some reason it just keeps setting the value to 0.
Read seems not to be working. :(
01-13-2009, 03:10 PM
well pointers fixed the problem after some tweeking.