? about passing variables between PASM cogs
AGCB
Posts: 327
My continuing quest to learn PASM.
Can I use the same hub variable and pass it between 2 or more PASM cogs? Back and forth. Similar to this
Thanks,
Aaron
Can I use the same hub variable and pass it between 2 or more PASM cogs? Back and forth. Similar to this
VAR one, two, three PUB cognew(@cog1,@one) cognew(@cog2,@one) DAT org cog1 mov copy, par add copy, #4 rdlong item1, copy 'this to put hub var "two" into item1 org cog2 mov copy1, par add copy1, #8, rdlong item2, copy1 'this to put hub var "three" into item2 wrlong item2, par 'this now puts item2 into hub var "one"
Thanks,
Aaron
Comments
Note that if you mix longs, words, and bytes in an object, the final order (within that object) is first all of the longs, then all of the words, and then all of the bytes, each size grouped together and ordered in the order you defined them.
This: will end up in the following order: (at least according to BST)
Edit: Electrodude said it better.
This is also the case with the Propeller Tool.
Variables in DAT sections don't get switched around like they do in the VAR section.
I personally always list my variables in long, word then byte order just so I'm not surprised by anything being switched by the compiler.
Remember to always pass a long address with par. The last two bits of the address are lost when launching a PASM cog so you can only count on a long address as being passed correctly.
OK so I know how to get the 2nd or 3rd var into the cog, but how do I write back to a var other that the 1st?
You really have two PASM programs here within the one DAT section.
It is normal to separate these with their own DAT sections and then each will have its own private variables at the end (ie copy1, item1, etc).
I always use "ORG 0" just to be sure (ie add the 0 or $0 parameter to the ORG)
Your question in post #6..
Just use
wrlong anyvar,anyptr
where anyptr can be copy1 or any variable which is typically set to par + offset.
We typically use ptrxxx or xxxptr to be a variable containing a pointer to hub (in your case this is copy1 or copy2)
BTW I believe there are good pasm learning info around - maybe someone would like to chime in where they are.
You can write the same way you read.
Use "wrlong item1, copy" instead of "rdlong item1, copy" to write the value of item1 to address "copy". It's common to maintain multiple addresses (if different variables) in the cog for this purpose.
Post #3 of my index.
To instead write item2 to the second hub var, what do I change
Is this it?
yes this code will read the 3rd long and write it back to the 2nd long, the 1st long (location 0) is the value PAR have.
declaring values (4,8,12) does not waste hub space as 'add copy1, #4' is no longer in the code that initially is also stored in hub so it's a wash, but cog space is saved that is important,
and the readability is way better.
see propeller assembly for the beginner thread. multiple really good examples by kuroneko, jazzed, and others on this and other topics. Filter heavily as needed. Also, Propeller Tricks and Traps by Phil Pilgrim, The tutorial written by potatohead , and Da Silva's tutorial are all good resources to get started.
They are freely available on this forum if you know where to look and what to look for.
Sandy
You taught me more than I asked to know. What a great forum because of great members!
Tonyp12
I was thinking that I could somehow make some shortcuts similar to that. I'll study yours.
Alexander (Sandy) Hapgood
I've gone through the DeSilva one several times. Will look at the other.
Duane Degn
I'll have to search in your index some more. I see there are probably some I haven't looked at yet.
Cluso99
Thanks for those "few things to note". A lot of what I do has been learned by studying other peoples code and not all are done the same. I guess it just takes time to learn the perfect way even if a slightly different way works also (at least so far)
Thanks to the others as well. I appreciate the replies and time taken of everyone.
Aaron