View Full Version : spin and assembly mix
mctrivia
01-12-2009, 03: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.
VAR
long ulDate,ulTime
PUB start
cognew(@TimeKeeper,0)
DAT
org 0
'initialize
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:
wrlong <destination_address_in_HUB>,<source_address_in_COG>
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:
DAT
ulDate long 0
...
DAT
org 0
...
wrlong ulDate_c, startDate
...
ulDate_ long @ulDate
startDate long 0
Something like that
mctrivia
01-12-2009, 03: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.
mpark
01-12-2009, 11:55 PM
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.
thebigmacd
01-13-2009, 12: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.
mctrivia
01-13-2009, 09: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.
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
sound_port = 10
Dat
ulTime long 3_500_000 ''ulTime <-- msec
Var
long stack[100]
long ulTemp
byte ubHour
byte ubMin
OBJ
oT : "talk"
PUB start
cognew(@TimeKeeper,0)
cognew(sayNow,@stack)
PUB sayNow
dira[16]~
oT.start(sound_port)
oT.set_speaker(0, 90)
oT.set_speaker(1, 110)
oT.set_speaker(2, 100)
repeat
sayTime
waitpeq(|<16,|<16,0)
sayTime
waitpeq(0,|<16,0)
pub sayTime
ubHour:=ulTime/3_600_000
ulTemp:=ulTime//3_600_000
ubMin:=ulTemp/60_000
ubHour:=ubHour//12
if ubHour==0
ubHour:=12
'ubHour:=1
'ubMin:=46
oT.say(sayNumber(ubHour))
if ubMin<10
if ubMin>0
oT.say(string("oa"))
sayNumber(ubMin)
PUB sayNumber(uiNum)
case uiNum
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~"))
10: oT.say(string("ten~"))
11: oT.say(string("el'even~"))
12: oT.say(string("twelv~"))
13: oT.say(string("th'irteen~"))
14: oT.say(string("f'orteen~"))
15: oT.say(string("f'ifteen~"))
16: oT.say(string("s'iksteen~"))
17: oT.say(string("s'eventeen~"))
18: oT.say(string("'aytteen~"))
19: oT.say(string("n'aenteen~"))
20: oT.say(string("tw'entee"))
30: oT.say(string("th'irtee"))
40: oT.say(string("f'ortee"))
50: oT.say(string("f'iftee"))
other:
sayNumber((uiNum/10)*10)
sayNumber(uiNum/10)
DAT
org 0
'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
jmp #TimeKeeper
'Locale Time Value
ulMSec long 0
'constants
ulDayLength long 86_400_000
ticTime long 80_000
fit 496
mpark
01-13-2009, 12:32 PM
Try these changes:
PUB start
ptrToUlTime := @ulTime '*** NEW ***
cognew(@TimeKeeper,0)
cognew(sayNow,@stack)
:updateTime wrlong ulMSec, ptrToUlTime 'Update the time *** CHANGED ***
waitcnt cnt, ticTime 'Delay for 1ms
jmp #TimeKeeper
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.
mctrivia
01-13-2009, 01: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.
mctrivia
01-13-2009, 01: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. :(
mctrivia
01-13-2009, 02:10 PM
well pointers fixed the problem after some tweeking.