reading variables from assembly HELP!
yellowcouch
Posts: 3
I am trying to read a variable from assembly usiing full duplex serial plus
Comments
i.e. Are you trying to read a variable that is inside of FullDuplexSerial from Spin or take a variable from Spin and use it from within FullDuplexSerial.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Signature space for rent, only $1.
Send cash and signature to CannibalRobotics.
I think the last non working version used
Mov mem, par
and then
Wrlong count, mem after the 'add count, #1' line
CON
_clkmode = xtal1 +pll16x
_xinfreq = 5_000_000
var
long stack [noparse][[/noparse]30]
obj
Debug: "fullduplexserialplus"
PUB Main
debug.start (31,30,0,115200)
{launch cog to blink pin 16 endlessly}
cognew(@follow,0) 'Launch new cog
repeat
Debug.str(string("count"))
Debug.Dec (Count)
waitcnt(clkfreq+cnt)
DAT
{follow P16}
ORG 0 'Begin at Cog RAM addr 0
follow mov dira, Opin 'Set pin to output
:loop mov P2, ina 'Sets pin to input
shl P2, #14
mov outa,Opin 'set minimun delay here
mov outa, P2
add Count,#1
jmp #: loop 'loop endlessly
OPin long |< 16 'pin number
IPIN long 2 ' clock cycles to delay
Time res 1 'system counter workspace
P2 long
Count long
"
CON
_clkmode = xtal1 +pll16x
_xinfreq = 5_000_000
var
long stack [noparse][[/noparse]30]
obj
Debug: "fullduplexserialplus"
PUB Main
debug.start (31,30,0,115200)
{launch cog to blink pin 16 endlessly}
cognew(@follow,0) 'Launch new cog
repeat
Debug.str(string("count"))
Debug.Dec (Count)
waitcnt(clkfreq+cnt)
DAT
{follow P16}
ORG 0 'Begin at Cog RAM addr 0
follow mov dira, Opin 'Set pin to output
:loop mov P2, ina 'Sets pin to input
shl P2, #14
mov outa,Opin 'set minimun delay here
mov outa, P2
add Count,#1
jmp #: loop 'loop endlessly
OPin long |< 16 'pin number
IPIN long 2 ' clock cycles to delay
Time res 1 'system counter workspace
P2 long
Count long
"
There are some assembly language tutorials in the permanent messages threads at the top of the thread list in this forum. I suggest looking at the Assembly Code Examples for the Beginner and deSilva's Machine Language Tutorial.
Two things:
1) "P2 long" and "Count long" have to come before the RES directive and they need values ("P2 long 0" and "Count long 0"). The way you've written them, they don't occupy any space.
2) The whole DAT block gets copied to a cog by the COGNEW to execute it. When executing, the labels stand for locations in the cog's memory, not the shared hub memory. When you reference Count in the Debug.dec statement, you're referring to a location in or (in this case) just following the DAT block. What you have to do is declare a long variable in the VAR section which you use in the Debug.dec statement, then pass the address of this variable to your assembly routine like "cognew(@follow,@variable)". Then you'll be able to refer to this in a WRLONG instruction like "WRLONG Count,PAR". I believe there are some examples of this in the tutorials I mentioned.