Shop OBEX P1 Docs P2 Docs Learn Events
Gosubs across Code segments in SX — Parallax Forums

Gosubs across Code segments in SX

ArchiverArchiver Posts: 46,084
edited 2000-10-07 05:32 in General Discussion
Do GOSUB's remain persistant when you run another program on the SX? I have a gosub/return pair in code space 0. I call code space 1 and then run·code space 0. Upon hitting the return my program starts over. Is the gosub/return stack cleared when the "RUN" command is executed?·If so are there any workarounds?···

MH

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2000-10-07 04:32
    As you have discovered, the pointer required to return from a Gosub
    is lost when you run another program. About the only workaround is
    to assign each return location a number and store that number in a
    variable that will be preserved when other program(s) run. Use a
    Branch instruction at the beginning of the main program to sort out
    the returns. Cumbersome, but workable.


    --- In basicstamps@egroups.com, "Michael Hendricks" <mjh80@b...>
    wrote:
    > Do GOSUB's remain persistant when you run another program on the
    SX? I have a gosub/return pair in code space 0. I call code space 1
    and then run code space 0. Upon hitting the return my program starts
    over. Is the gosub/return stack cleared when the "RUN" command is
    executed? If so are there any workarounds?
    >
    > MH
  • ArchiverArchiver Posts: 46,084
    edited 2000-10-07 05:32
    I am presently doing that... but with over 80+ branches it is VERY cumberson
    and borderline unmanagable.. thanks for clearing that up...

    MH

    Original Message
    From: <stamps@s...>
    To: <basicstamps@egroups.com>
    Sent: Friday, October 06, 2000 11:32 PM
    Subject: [noparse][[/noparse]basicstamps] Re: Gosubs across Code segments in SX


    > As you have discovered, the pointer required to return from a Gosub
    > is lost when you run another program. About the only workaround is
    > to assign each return location a number and store that number in a
    > variable that will be preserved when other program(s) run. Use a
    > Branch instruction at the beginning of the main program to sort out
    > the returns. Cumbersome, but workable.
    >
    >
    > --- In basicstamps@egroups.com, "Michael Hendricks" <mjh80@b...>
    > wrote:
    > > Do GOSUB's remain persistant when you run another program on the
    > SX? I have a gosub/return pair in code space 0. I call code space 1
    > and then run code space 0. Upon hitting the return my program starts
    > over. Is the gosub/return stack cleared when the "RUN" command is
    > executed? If so are there any workarounds?
    > >
    > > MH
    >
    >
    >
    >
    >
Sign In or Register to comment.