Propeller Object: Assembly Function Engine Demo (A method for Hybrid Spin/Assem
Beau Schwabe
Posts: 6,568
Here is a demonstration of how to setup an Assembly Engine running in it's own cog that houses functions which can be called from any Spin program.
This DEMO is designed to be a template only. It was originally derived from the 'graphics.spin' object, so you should see some similarities. The Demo
functions in the Assembly program return Sine, Cosine, and Arcsine ...but anyone can add their own Assembly routines to satisfy their own criteria.
Sine and Cosine are returned from the Propeller's internal lookup table, while the Arcsine function uses an 11-itteration successive approximation reverse
lookup routine, also using the Propeller's internal Sine table.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 8/14/2006 3:13:37 AM GMT
This DEMO is designed to be a template only. It was originally derived from the 'graphics.spin' object, so you should see some similarities. The Demo
functions in the Assembly program return Sine, Cosine, and Arcsine ...but anyone can add their own Assembly routines to satisfy their own criteria.
Sine and Cosine are returned from the Propeller's internal lookup table, while the Arcsine function uses an 11-itteration successive approximation reverse
lookup routine, also using the Propeller's internal Sine table.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 8/14/2006 3:13:37 AM GMT
Comments
thanks
Graham
Can I first ask a stupid question, in a typical function:
How does Arg1_ get a value assigned when the result is written to Ang? And am I right in saying that if you want multiple arguments you make sure they are contigious and just pass the first?
And a less stupid question, how do you think I should implement functions with multiple returned variables?
Thanks
Graham
One question, it looks like the SPIN code that is calling the assembly worker routine will return as soon
as the assembly cog receives the command, but it seems like it is before the actual final result is calculated.
Maybe this was intentional or maybe I'm reading it wrong.
-Chad
Graham
The result is always written to Arg1_ at the end of each function by the following code.
The add instruction changes the pointer t1 to the next long variable, which is Arg1_.
That's right. You must only use the add instruction like above to point to the next variable.
The best way would be you calculate your result in contiguous variables in Cog memory. So you can return the result using a loop like this.
You are right. In my opinion it is a mistake, but it is working while the execution time of Spin is slow enough until the result is written back.
All the spin functions call setcommand and that includes the line:
So it will not return until command is cleared and that is done by the assembly AFTER it has completed its task
Graham
I guess my next question is why is Arg1 the next long after Command? It must be but its not obvious to me why.
Graham
You are right in saying that the command must be cleared, but this should be at the right time. In the example code it is cleared BEFORE the function has calculated the result. It would be better to do this AFTER the result is written back.
I have nothings found about this in the manual, but I know that all parameters and local method variables are stored on the stack in the order they are specified in the method.
Post Edited (Kaio) : 3/27/2007 1:12:00 PM GMT
It raises an important point, it make sense to clear the command at the end but in some cases it would make more sense to allow the spin program to continue while the assembly program did its work, there would just need to be a flag to indicate that the assembly routine had finished, that would allow greater parallel processing potential in some instances and would make the one cog act like lots of little cogs. If I remember correctly someone actually did something like this, combining some of the ps/2 drivers into one object.
Cheers
Graham
I have written a multithread kernel. So you can use some little assembly routines simultaneously in the same Cog.
http://forums.parallax.com/showthread.php?p=623841
As you and other have indicated, there are potentially two right or correct ways to do this.· One is to wait while until the assembly command executes, and the other is to allow the assembly command to execute allowing the parallel processing potential to be maximized.· In the DEMO assembly program the 'par' variable is cleared only to signify that the command has been received, not that it has been completed or not.· The PRE or POST significance should be addressed by the programmer based on·his or her·particular needs.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Re my origional question before we got side tracked:
I've just modified the code so I can return multiple values from a function, I do this by passing a pointer to both arguments and return values which are declared contigiously in hub ram. I've got my code working for multiple return values but when I try multiple arguments it doesn't seem to work. I've not looked at the code enough to say if it is something I am doing or something in the code (the example only uses single arguments) but could you explain the meaning of the constant d0 which is $200, It looks to me as it increases the destination field of a command by one but why not four?
Graham
the destination address points to the memory in Cog. This is organized as long, you can it only access as 32 bit value. Therefore you must increment the pointer only by one.
In opposition to the main memory which is organized as byte. Therefore you must increment the pointer by four, if you want to access it as long.
I'm still having trouble with the code that reads in the arguments, to test it I have removed the loop and written it out but still no joy, the first variable loads OK but not the second.
If I just make arg0 and arg1 equal something with a mov command it works but not otherwise.
par contains the pointer to the first of the input variables which are defined in the spin of the test program like so:
It reads a into arg0 but not theta into arg1
I'm completely confused by this.
Graham
Graham