How to pass arguments to/from assembly language?
JonTitus
Posts: 193
in Propeller 1
Please, could someone give a short, simple explanation of and a simple piece of code for, how to pass several parameters to an assembly-language routine and how to get several values back from that routine? Examples in this Forum are either too complicated to follow or are just an explanation without an example. Show me how to send three values and how to get two back. Seems like this should be an obvious part of the Propeller manual, but it's not. I need to use assembly language for speed. Folks, many of us are new to assembly language on the Propeller, so simplicity and clarity help more than complexity and obscurity. Thanks. --Jon
Comments
1. When you start the PASM cog, send it the address of a long parameter array. This address will appear in PAR at the assembly end. The first parameter should just be a true/false flag.
2. At the beginning of the PASM program, program a loop that waits for the first parameter to become non-zero.
3. When this happens, read the parameters from hub memory, i.e. at PAR + 4, PAR + 8, and PAR + 12.
4. Do your computations, and store the result at PAR + 4.
5. Then clear the hub memory at PAR to zero.
____
6. The calling program must first store the parameters in positions 1..3 in the long array.
7. After that, it must set position 0 to a non-zero value.
8. Then it just has to wait until position 0 becomes zero again.
9. At that point, it can read the result from position 1 in the array.
-Phil
Of course, you have to launch the cog -- do that with:
I struggled with this for months trying to find useful examples. I can write the code but to get it into the C code was impossible.
Anyway I figured it out and here is the C code version. I believe C code runs faster than SPIN.
Thanks for playing.
Mike
I wrote a simple assembly-language program to turn on two off-board LEDs at pins P8 and P9. I set the DIRA and OUTA pins properly within the AL program. If I end the AL routine with:
jmp $%
the LEDS stay lit because the AL program finishes and remains in an endless loop. It doesn't return to my SPIN code. I have seen examples that use the following instructions to stop execution in the cog:
cog ID
cogstop ID
In this case, the LEDs turn on for 0.5 microseconds and then turn off. I need them to remain on when execution returns to the SPIN code. Again, thanks for any help you can offer. --Jon
I appreciate your clarification. But why do the statements above cause the I/O pins to change state, but the statement
does not? That's what baffles me.
Again, thanks. --Jon
the difference is that when you stop a COG it will reset dira and outa and let pins float again, as opposed to stay active and just jump on itself, doing nothing but keeping alive and keeping the pin states.
Mike
Another thing you can do is use the flag as a switch for what you want to do in the pasm cog -- this is why I called it command. In the examples above it's a simple true-false flag, but you could easily compare the value in command with a known set and run a routine within the pasm cog on demand. See attached demo; it illustrates the use of pasm-coded subroutines. Since it contains IO control, it must stay running.
The attached files show my attempt. I need very high-speed serial output with a clock to test other equipment. All I get out is one long (0.5-sec) pulse on the clock like. I have spend days on this code and got nowhere. I'm about to switch to an Atmel or ARM-Cortex and program what I need in C.
Thanks for any assistance you can provide --Jon
In the PropTool library there is an object SPI_Asm.spin that does that.
The code below is an excerpt from that object showing how the spin "calls" the Pasm (which was started earlier). Look at the full code from the library and the corresponding demo.
https://www.parallax.com/news/2015-02-26/download-new-book-jon-titus-experiments-propeller-quickstart.
Descriptions start in Experiment 11. Again, thanks for all your help. --Jon