Loading multiple cogs with ASM
crcordill
Posts: 29
Quick question. I've been working on learning ASM for a few weeks with the help of the Forums and some of the tutorials. They've helped me a bunch. I've been able to use some of the power of ASM and its been great. However, I've only been able to run one cog at once.
My question is how to launch multiple cogs with ASM. Lets say that I have two entries and I am launching them onto seperate cogs with totally different code. Do I need to use the ORG and FIT functions? Here's how I think it should go:
Is this the way that I should load up the different cogs?
Another quick question. I'll be using all of the cogs. When I start my code I've already started my first cog, correct? Let me explain:
where Cog# is an object to run
This one makes sense, where the next one doesn't I think. I'll run out of cogs if I try the next one, right?
Post Edited (crcordill) : 5/17/2008 4:19:44 PM GMT
My question is how to launch multiple cogs with ASM. Lets say that I have two entries and I am launching them onto seperate cogs with totally different code. Do I need to use the ORG and FIT functions? Here's how I think it should go:
PUB Main cognew(@entry1, @stack) cognew(@entry2, @stack[noparse][[/noparse]10]) DAT entry1 ORG code in here entry1_end FIT entry2 ORG code in here entry2_end FIT
Is this the way that I should load up the different cogs?
Another quick question. I'll be using all of the cogs. When I start my code I've already started my first cog, correct? Let me explain:
PUB Main cognew(Cog1, @stack) cognew(Cog2, @stack) cognew(Cog3, @stack) cognew(Cog4, @stack) cognew(Cog5, @stack) cognew(Cog6, @stack[noparse][[/noparse]6]) cognew(Cog7, @stack[noparse][[/noparse]7]) Cog0
where Cog# is an object to run
This one makes sense, where the next one doesn't I think. I'll run out of cogs if I try the next one, right?
PUB Main cognew(Cog1, @stack) cognew(Cog2, @stack) cognew(Cog3, @stack) cognew(Cog4, @stack) cognew(Cog5, @stack) cognew(Cog6, @stack[noparse][[/noparse]6]) cognew(Cog7, @stack[noparse][[/noparse]7]) cognew(Cog0, @stack[noparse][[/noparse]8])
Post Edited (crcordill) : 5/17/2008 4:19:44 PM GMT
Comments
This is even more problematic in your second and third examples, where each Cog is only given one stack entry each.
You're right that one Cog is always used ( Cog 0, the one running the Spin program launching the others ). To re-use the Cog 0, do a CogInit(0,methodName,@stack).
Here's an example of how I think you can partition the code.
I think that if I use the ORG and FIT commands, that would send the code between the ORG and FIT into two separate cogs. So the first cog is only loaded with code that it needs, and not stuff for needed for the second entry. Though I'm not sure. Here's another example and what I think will happen.
With this example, I think that each cog will load up everything in between the ORG and the FIT for each cog. I'm sure that that is clear as mud. Please ask question for clarification. Thanks
In your last code listing you have two entry points and just one ORG directive: That is a bad idea, because the address for the second entry point will not be at 0, it does need to be, because the cognew instruction will load 496 long starting at that point but the symbols will start at entry1. I'd recommend you keep every assembly block in its own DAT section with its own ORG, for clarity and to avoid messing up the symbols. (You can test what I told you, just put the cursos over a symbol and it will tell you the address, you will see that it is the ORG directive the one that fixes that address to 0).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
That's what I said, but any label will not have the correct address as I explained above.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔