Memory locations in Spin
tom90
Posts: 55
Hey All,
I have a cog running ASM that writes a word/long to a specific memory location
For example:
I would like to have another cog running spin that will read this word/long from that specific location so it can be output.
How do I read from a specific memory location in spin?
The manual addressed something similar but it didn't really explain this situation.
Thanks,
Tom
I have a cog running ASM that writes a word/long to a specific memory location
For example:
wrword AdcValue, $1FF
I would like to have another cog running spin that will read this word/long from that specific location so it can be output.
How do I read from a specific memory location in spin?
The manual addressed something similar but it didn't really explain this situation.
Thanks,
Tom
Comments
But you should not write to $1ff in the first place...
I have tried this, and it comes up with an error message that says "Expected a Variable"
OBJ
··· debug : "pc_debug"
VAR
· long· answer
·
PUB Main
· debug.start(2_400)····
· cognew(@divtest, 0)
·
·· answer := 0
repeat
· answer := word[noparse][[/noparse]@$1FF]
· debug.str(string("Answer "))··········
· debug.dec(answer)
· debug.str(string("· "))
DAT
············· ORG······ 0
divtest······
·············
:loop········ mov······ Total, A1
············· add······ Total, A2
············· add······ Total, A3
············· add······ Total, A4
············· add······ Total, A5
············· add······ Total, A6
············· add······ Total, A7
········································
············· wrword··· Total, $1FF
············· jmp······ #:loop
A1····· long··········· 1
A2····· long··········· 2
A3····· long··········· 3
A4····· long··········· 4
A5····· long··········· 5
A6····· long··········· 6
A7····· long··········· 7
Total·················· res 1·
What am I doing wrong?
Thanks
Tom
Now I am getting a very high incorrect value.
I am assuming that my variables arent defined correctly.· I just tried several configurations but didnt have any luck
Any ideas?
Thanks,
Tom
The code you were using was writing to the address contained in register $1ff. In any event, why are writing to that location when you have no idea what you might be clobbering in the process?
-Phil
First of all, thanks.
The answer to your second question is because i am a terrible programmer.· I was doing this because I needed to pass multiple things between cogs, and didnt know how else to do that.· Where should I be writing these varaibles so that i dont disturd anything important.·
Thank
Tom
This is assuming that nothing has taken that memory for its own use; video buffer, etc.
When i try to write to anything higher than $1FF it comes back with an error message that says "Source register/constant cannot exceed $1FF".· How do i write to a location higher than $1FF?
thanks
Tom
Post Edited (tom90) : 2/13/2008 9:11:59 PM GMT
> cannot exceed $1FF"
As deSilva already said, it's no good idea to write to $1FF. It's also not good to write to $whateverValue.
You need to define a var in SPIN and pass that address to your assembler routine. Here, you can access the parameter (the address in this case) via PAR.
If you insist on using some constant address that you have chosen, you insist on having unpredictable results.
Nick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!
The DIY Digital-Readout for mills, lathes etc.:
YADRO
This way you don't have to worry about whether the memory is being used by something else.
The code i posted was just a small test program that i wrote to make sure that passing the variables was working.· In the larger program that i have written (and this test will be a part of) uses the "PAR" to sync all of the cogs together.· Is there a way to use more than one "PAR" on each cog?· I was trying to write to these other memory location because i didn't know how to pass aroung variable once i already had that "par" assigned to something else.
Thanks
You can set addresses (or other values) to DAT variables to be copied in the COG - of cause BEFORE you have it copied by COGNEW
I am aware that there are reasons to NOT do it that way, but it also has its merrits
@Steven:
is also NOT a good idea as someVariable is a WORD. The problem is that PAR is not a LONG, but a quite specific 14-bits value, allowing addresses of LONGs only!!! It works by chance in your example , as someVariable is the FIRST WORD and is thus aligned to LONG...
Post Edited (deSilva) : 2/14/2008 1:20:02 AM GMT