Stack Pointer
Carlos Bastos
Posts: 4
Hi,
Can I get the actual stack pointer position, after a gosub call?
I'm having problems changing slots inside subroutines.
Thankz.
Can I get the actual stack pointer position, after a gosub call?
I'm having problems changing slots inside subroutines.
Thankz.
Comments
·
·· In PBASIC you don’t have access to the internal Stack information.· The best thing you can do is to make sure you have a one to one match with GOSUB and RETURN statements.· Make sure the main program doesn’t fall down into the subroutines and avoid exiting the subroutines via a GOTO rather than RETURN.· Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
I'm on slot 0, in a subroutine. This subroutine calls another program slot (like RUN 1).
In this new slot a function will de realized and then return to slot 0.
The problem is: when it come back to slot 0 the information of the address saved in stack pointer get lost.
And then, the program will not go to the correct location.
Thanks for the help!
·
·· I would recommend avoiding that by not putting the RUN in a subroutine like that.· But if you must, you can use a variable to return you to a specific point in the program.· The problem is you don’t want to jump to the subroutine where you will hit the RETURN.· To use the variable you can declare one as say a NIB.· In your program you can set it to a value and if your variables are declared exactly the same in each slot they will be preserved.· When you get to the new slot the first executable line would be a BRANCH instruction that can jump based on the value of the variable.· I hope this helps.· Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
If you declare the variables in the same order in both slots, you CAN use a few variables for a 'jump' table.
Multi-slot programming can be very useful, but it's also a little awkward.