Accessing VAR variables from assembly
dnaddor
Posts: 26
I need to be able to share variables between SPIN and assembly. I have code that works but it isn't pretty:
VAR
long ReadFromHere
long WriteToHere
PUB
COGNEW(@AssemblyCog, @ReadFromHere)
DAT
org
AssemblyCog
mov Ptr, PAR
rdlong Look, Ptr
add Ptr, #4
wrlong Look, Ptr
Ptr long 0
Look long 0
What I really want is something like this:
AssemblyCog
mov Ptr, @ReadFromHere
rdlong Look, Ptr
mov Ptr, @WriteToHere
wrlong Look, Ptr
Isn't there a way to do this so my code will be more readable?
Thanks!
VAR
long ReadFromHere
long WriteToHere
PUB
COGNEW(@AssemblyCog, @ReadFromHere)
DAT
org
AssemblyCog
mov Ptr, PAR
rdlong Look, Ptr
add Ptr, #4
wrlong Look, Ptr
Ptr long 0
Look long 0
What I really want is something like this:
AssemblyCog
mov Ptr, @ReadFromHere
rdlong Look, Ptr
mov Ptr, @WriteToHere
wrlong Look, Ptr
Isn't there a way to do this so my code will be more readable?
Thanks!
Comments
If all you are looking for is code readability you can do something like this:
Of course the #1 means for increasing the readability of code is the liberal use of comments.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Post Edited (Paul Baker (Parallax)) : 5/2/2007 5:05:48 PM GMT
Yes, I meant #@ReadFromHere instead of @ReadFromHere. And yes, I see how the value #@ReadFromHere would exceed the 9-bit limit.
I oversimplified my example. In the real application, VAR is a large collection of different sized values:
VAR
long Encoder
long Instant
long SomeTable[noparse][[/noparse]20]
long Magic
long BiggerTable[noparse][[/noparse]80]
I was hoping for a way to access these elements BY NAME from the assembly code, rather than constantly offsetting from PAR and hoping that I was offsetting properly.
Now if you are willing to sacrifice a long for each variable in your cog you can do:
But that depends on how much space you have in your cog.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Step 3 shows a practical example.
Graham