Quote Originally Posted by bumlife View Post
I wanted to know if it is possible to write function in picbasic. By functions i am referring to the functions that you write in higher level languages like C, where you can pass a value to this function, it performs some operations and then returns a value. i have gone through the pic basic pro manual and i havent found anything that will do this. The closest thing is the gosub routine but gosub doesnt return a value, but other than that i havent found anything else. I want to use functions so that i can make the program more efficient and to save space of the program memory space, and also make debugging easier. The PIC i am using is an 18F2550. So if anyone has any suggestions please let me know.
"CALL" will get you to an assembly language subroutine, but won't return a value. However, you can access any values defined in PBP (i.e. X) from assembly by prefixing that variable with an underscore (i.e. _x). Therefore, you're able to set X (in PBP) to something, call a sub, work on _X (in assembly), then after returning, you still have X (in PBP). Just don't use X anywhere else. Just pretend you pushed it onto the stack and popped it when you got back.
That's my simplified answer. There's at least 2 (probably a whole lot more) others here on the list that are FAR, FAR more versed in PBP/Assembly interaction than I.
We'll see what they have to say.