Input and return values from Assembly
agimuhing
Posts: 39
How do you input values into an assembly program and have the assembly program return a value?
If you know C, I'm trying to make assembly programs receive and return values like inline functions
my question might be worded a little funny so fell free to ask for clarifications
If you know C, I'm trying to make assembly programs receive and return values like inline functions
my question might be worded a little funny so fell free to ask for clarifications
Comments
Edit: Whoops, found a small typo in the demo (though it didn't affect the way it ran). This line
should be:
The # sign is required here.
That's not possible with the propeller. You have to understand how the propeller works. After booting there will be one COG running the SPIN interpreter, which is executing the main SPIN program. The COG only has 512 longs of memory and the SPIN interpreter needs all that memory. The SPIN program simply stays in HUB-RAM. The interpreter fetches the instructions and executes the subroutines which implement the instruction.
PASM can only be used in a free COG. But then there is no more room for a SPIN interpreter.
So, you either have a SPIN COG or a PASM COG.
When starting a PASM COG you can pass exactly one parameter. As this is not enough for most cases this parameter is used to pass a start address of a memory area which is then used to EXCHANGE parameters. Both, the code that want's to pass parameters and the PASM exactly "know" which parameter has to be put where and where to find the results and of course how big this memory area is.
It's a matter of the PASM code to read data from there or write data back to these locations. And it's a matter of the code that wants to communicate with the PASM COG to put the values there when needed or take back the result.
A concept used very often is to have one long with which the SPIN code can tell the PASM COG what to do (give an instruction). Finding a value different than 0 tells the COG that it has to execute a command and the PASM COG sets this memory location back to 0 if it's done with its job.
actually I want to write a PASM program that can input and output data similar to an inline function, not use assembly inside C
@Agimuhing: MagIO's post is an excellent description of what my little demo is doing. Between my code and his description it should all come together for you.
Moreover you can have inline assembly. SpinLMM is a solution, and another is from Beau. Both are on the obex.
Check http://forums.parallax.com/showthread.php?125599-Pepper-SPIN-with-Assembly
Massimo