4 byte function?
hey all, can someone tell me why this doesn't compile ?
SX/B VERSION 2.00.30
Unable to assemble due to errors in source code:
... <__ PARAM9> is not defined
... <__ PARAM13> is not defined
Thanks again!
Post Edited (skynugget) : 1/3/2010 12:39:37 AM GMT
SX/B VERSION 2.00.30
Unable to assemble due to errors in source code:
... <__ PARAM9> is not defined
... <__ PARAM13> is not defined
TEST4 FUNC 4 'setup function to return 4 bytes ' ========================================================================= PROGRAM Start ' ========================================================================= start: string = test4 goto start ' ------------------------------------------------------------------------- ' Subroutine / Function / Task Code ' ------------------------------------------------------------------------- func TEST4 b1 var byte b2 var byte b3 var byte b4 var byte b1 = 11 'plug in random values b2 = 99 b3 = 91 b4 = 10 return b1,b2,b3,b4 endfunc
Thanks again!
Post Edited (skynugget) : 1/3/2010 12:39:37 AM GMT
Comments
i was working on something else, that i scrapped(and didn't save, doh), but it left me thinking.
Though this code is incomplete, i would think it should compile given that i would have remembered to paste the following in the example:
i tried to come up something simple basically to ask if its a bug, or if im just dumb and don't get it the syntax
i thought you could return a max of 5 bytes from a function, and the get stored in __PARAM1 thru __PARAM5
i dint know param9 and param13 existed.. i kinda thought it was a bug... but ive been known to be pritty dense sometimes.
Post Edited (skynugget) : 1/3/2010 5:10:19 AM GMT
I have personally written hundreds of SX/B programs and helped weed out a lot of "gotchas" (I'm part of the development team); in all that time I have never seen the compiler complain about [noparse][[/noparse]the non-existent] __param9 or __param13. Again, had you attached your code (the whole thing, not just fragments), one of use could compile it on our end and give you better guidance.
Note that SX/B can only return two bytes using the form
someVariable = SomeFunction
...where 'someVariable' is a word that will receive __wparam12 (__param1 and __param2).
In order to get the the others you need to capture them manually, right after the call; in your case:
myVar(0) = TEST_FUNC
myVar(1) = __param2
myVar(2) = __param3
myVar(3) = __param4
Note that you shouldn't use symbols like string and test; these are reserved words in other flavors of BASIC and might create troubles.
Post Edited (JonnyMac) : 1/3/2010 7:17:50 AM GMT
To call the above function:
Another note: Local variables generate a butt-load of code; I don't recommend them unless they're absolutely necessary (I've never found that to be the case).
So I was using it wrong?
a sub can handle 5 bytes, but RETURN can only return 2 bytes not 5, and you have to work around that?
thanks for the tip on the local vars, i didn't realize they create such a mess.. cool idea though
note:
If i make the local variables global, it compiles the file, and the sasm source uses param 1 through 4
so the local variables where using up the Param space? i thought they where crammed in the stack space?
thanks again for helping, and putting up with my dingy-ness
Using local variables in SX/B is a bad idea; it complicates the output and generates a huge amount of extra code. While a function can in fact return four bytes you cannot move them into an array as you're attempting to do. I showed you how to move data to an array using the __RAM() pointer; I've updated your program to let you see for yourself.
Post Edited (JonnyMac) : 1/5/2010 5:37:17 AM GMT