converting coginit code to a call
kwagner
Posts: 48
I want to take some PASM code that's currently run via coginit and make it a function I call. What I don't understand is how to get data into ptra with a call. If I have for example:
cog := coginit(COGEXEC_NEW, @main, @abc)
How do I get the info from abc into call(@main)?
Comments
The call() instruction only supports an address parameter so that's probably not going to work for you. Will an inline method work? You could do something like this:
After reading the docs a bit more, it seems like you just have to add a second line: pass your address for ptra in an available register. I did this simple test:
In your case, the first line of your pasm code would be:
One of my libraries uses pre-loaded (via regload) PASM extensively and uses calls to execute assembly routines. There are 8 registers allocated that have symbols defined in both Spin2 and PASM so they can be shared. I use these registers to pass parameters.
Example snippet from my library:
Then in the PASM you can access the registers symbolically using PRx (PR0, PR1, etc.).
Per the Spin2 documentation:
Pre-edit, looks like I was beat to the punch but figure I'd still submit it to say I vote in favor of what JonnyMac stated. It has been working out for me.
Either of those should work. I'll give them a try, thanks!
Edit: Replied same time as DarkInsanePyro. That's great info as well.