Shop OBEX P1 Docs P2 Docs Learn Events
Stack Pointer — Parallax Forums

Stack Pointer

Carlos BastosCarlos Bastos Posts: 4
edited 2006-12-12 15:35 in BASIC Stamp
Hi,

Can I get the actual stack pointer position, after a gosub call?

I'm having problems changing slots inside subroutines.

Thankz.

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-12-12 15:05
    Carlos,
    ·
    ·· 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
  • Carlos BastosCarlos Bastos Posts: 4
    edited 2006-12-12 15:27
    Thanks Chris, but my problem is a little diferent.

    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!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-12-12 15:32
    Carlos,
    ·
    ·· 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
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-12-12 15:35
    The 'slot changing' approaches don't let you "GOSUB" to one slot and "RETURN" to another slot. It's more like a "RUN" program from another slot, which eventually then "RUN"s your program back in the first slot.

    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.
Sign In or Register to comment.