assembler and spin combination
psavolai
Posts: 21
Hi,
having programmed for living for quite a long time Spin looks relatively straightforward to me.
What I am missing is some sort of documentation·of the relationship between Spin and Assembler.
Looking at Chips tv-objects they seem to contain Spin "controller" and some assembler "worker" routines.
1. What are the size limits for such assembler sub routines ?
2. What type of variable exchange happens between those two ?
3. Cog usage ?
4. stack issues ?
5.·any·documentation·on the subject ?
regards,
petri.
having programmed for living for quite a long time Spin looks relatively straightforward to me.
What I am missing is some sort of documentation·of the relationship between Spin and Assembler.
Looking at Chips tv-objects they seem to contain Spin "controller" and some assembler "worker" routines.
1. What are the size limits for such assembler sub routines ?
2. What type of variable exchange happens between those two ?
3. Cog usage ?
4. stack issues ?
5.·any·documentation·on the subject ?
regards,
petri.
Comments
Chip Gracey
Parallax, Inc.
Just to make sure:
1. If I have 3 assembler subprograms under my main spin block
is it the total of those 3 soubroutines that is supposed to be under 496 or is
it just the one which is currently executing ?
2. If my "main" spin block is running in Cog0
is the assembler subroutine swapped in cog0 memory and later on swapped out
when it returns. Basically I'd like to know where the spin
context is kept while my assembler routine is·busy hogging all the 496 longs.
petri.
·
Chip Gracey
Parallax, Inc.
I try to get myself oriented a bit more.
Does it mean if I choose to write·even a small section of my algo in assembler, this routine will always require separate cog or at least one can't go back from asm to SPIN code after
COGINIT(COGID, @asmcode, parvalue) is called?
Or on can write a hybrid algo in SPIN & assembler and·the same cog would·execute either SPIN or assembler code, back and forth, ·depending what is calling what?
Thanks
Jan·
If you see pages 339-352 in the manual, they should clear up a bunch (I just read 'em last night, and many things "clicked").
My understanding, you can:
- Only run Spin code in one cog at a time
- Only run Assy code in one cog at a time (it's own cog)
- You can run Assy code in the same cog as spin, but you have to "restart" the cog into the assembly code
- Spin and Assm code must be run separately, aka no mixing code, period
The next logical question would be, if I were to run assm code in the same cog by restarting into the assm code, how long would that take? I think, someone please confirm, that it takes about 400 clocks. So at 80Mhz, you would need 400/80_000_000 = 5us = 0.000_005sec.
I just grasped this yesterday, hence why I write, often you learn by teaching, I hope I haven't written the wrong thing...
-Parsko
5 us is fast enough
Jan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
...
I think I was mistaken, but I DO remember Chip saying that it was around 400 (actually, the number in my head is 384) clocks to start a new COG. If you view the following post, it says that it takes 103us to start a COG. This does seem to make more sense than 5us. I tried searching, but couldn't find anything else helpfull...
http://forums.parallax.com/forums/default.aspx?f=25&m=132607&g=132773#m132773
-Parsko
Most assembly programs are designed to be started, then run continuously. They may wait for an I/O pin setting or a particular location in HUB RAM to be changed. Frequently, an assembly routine will have a location in HUB RAM that is a command value. The assembly routine sets it to -1 when it finishes its initialization, then waits for a SPIN program to put something other than a -1 in that location. This may be a starting address and size of a buffer (packed together into one long) or the number of an action to be performed and a HUB address of more control information. The assembly routine does what it's supposed to do, then sets the location to -1 again. This process can be very short. Maximum time to access a HUB location is about 22 clock cycles. Add 3 or 4 instructions at 4 cycles each and you have maybe 40 clock cycles between when the SPIN program signals the assembly routine and when the assembly routine actually starts doing something. This takes well under a microsecond. If the assembly routine is responding to an I/O pin change, we're talking 50-60ns with the waitpeq/waitpne instructions.
Back in March, I did some launch timing tests, and these were reported on the Propeller Beta Tester's forum.
http://forums.parallax.com/forums/default.aspx?f=24&m=113608
Cheers,
Peter (pjv)
I'm not sure anyone has access to that, only Beta Testers... at least I know I can't (just tried).
-Parsko
Thanks for letting me know that. Here is a copy of that post.
Now that I know more about the Propeller, I aught to go and check these figures again....... they were pretty early on, and perhaps not optimum. But at least thats what I found then.
Cheers,
Peter (pjv)
Mike