Beau,
Are you sure that's correct? Chip posted a very different short assembly routine that mostly made sure the clock was set according to what's specified in the SPIN program, but had a very different COGINIT operand that pointed to the SPIN interpreter in ROM so it gets loaded into the COG to begin interpreting the SPIN program in RAM from the beginning. Would you please explain how your example works because the assembly piece doesn't make sense from what I've gleaned from the manual and forum threads.
Mike
Yeah, unfortunately, it's more complicated than Beau's example. You must set up some word pointers, have some stack allocated and initialized, and then launch the interpreter pointing to the word pointers. I really like Beau's approach, though. That could be a goal for the next chip.
After discussing with Chip on the phone this evening what was really happening with the code that I posted, it seems that there is no easy way
to do this.
From a learning perspective, here is what my code IS doing that makes it "appear" to function properly....
[b]cognew[/b](CallSpinFromAsm,LEDTest1)
' OR
[b]cognew[/b](CallSpinFromAsm,LEDTest2)
This line never actually runs the Assembly code pointed to at 'CallSpinFromAsm'. Because the syntax for 'cognew' used in this way....
[i]COGNEW(AsmAddress, Parameter)[/i]
...COGNEW evaluates the 'Parameter' argument as 'LEDTest1' or 'LEDTest2' essentially looking at it as a function awaiting a value to
be returned so that it can be passed on to the Assembly program.
In doing so, 'LEDTest1' or 'LEDTest2' get launched but never return to the "COGNEW" command which originally called it.
To help prove this, the original program could have looked like this, and it still would have appeared to function properly...
If you loosen your definition of "call" slightly, you can call a Spin routine from assembly by using a dispatch table. This is the same technique used to call assembly routines from Spin, but in reverse. Here's an example:
The dispatch loop just waits for the command to become non-zero, then calls the associated subroutine with the arguments passed by the assembly routine and returns the return value in the first argument. (Return values are not used in the example.) Finally, the command is cleared to signal the assembly routine that it's done.
Notice that I did not call the pr.str routine in the example. To do so requires the hub address of a string, and this would require passing the address of a more complicated data structure in par.
Comments
Edit: Updated see below...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 7/26/2006 7:36:08 AM GMT
Are you sure that's correct? Chip posted a very different short assembly routine that mostly made sure the clock was set according to what's specified in the SPIN program, but had a very different COGINIT operand that pointed to the SPIN interpreter in ROM so it gets loaded into the COG to begin interpreting the SPIN program in RAM from the beginning. Would you please explain how your example works because the assembly piece doesn't make sense from what I've gleaned from the manual and forum threads.
Mike
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chip Gracey
Parallax, Inc.
You are right.
After discussing with Chip on the phone this evening what was really happening with the code that I posted, it seems that there is no easy way
to do this.
From a learning perspective, here is what my code IS doing that makes it "appear" to function properly....
This line never actually runs the Assembly code pointed to at 'CallSpinFromAsm'. Because the syntax for 'cognew' used in this way....
...COGNEW evaluates the 'Parameter' argument as 'LEDTest1' or 'LEDTest2' essentially looking at it as a function awaiting a value to
be returned so that it can be passed on to the Assembly program.
In doing so, 'LEDTest1' or 'LEDTest2' get launched but never return to the "COGNEW" command which originally called it.
To help prove this, the original program could have looked like this, and it still would have appeared to function properly...
Notice that there is nothing in the Assembly section other than a label? The code could be further equated to...
...Once again proving that there was no Assembly code that was actually executed.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
The dispatch loop just waits for the command to become non-zero, then calls the associated subroutine with the arguments passed by the assembly routine and returns the return value in the first argument. (Return values are not used in the example.) Finally, the command is cleared to signal the assembly routine that it's done.
Notice that I did not call the pr.str routine in the example. To do so requires the hub address of a string, and this would require passing the address of a more complicated data structure in par.
-Phil
any way to change the forum width? Some of these threads are hard to read [noparse]:)[/noparse]
Robin