Using the Run command inside a Subroutine
Bob - Fremont
Posts: 11
Hello everyone,
I have what is a simple question to the one who can answer it.
Is it possible to issue a RUN command when inside a subroutine.· And then from the new·program slot, issue a Return command.· Will the Return command bring me back to the original program slot, or do I need to RUN to that slot and then issue the Return.
Thanks in advance for your help.
Bob H.
I have what is a simple question to the one who can answer it.
Is it possible to issue a RUN command when inside a subroutine.· And then from the new·program slot, issue a Return command.· Will the Return command bring me back to the original program slot, or do I need to RUN to that slot and then issue the Return.
Thanks in advance for your help.
Bob H.
Comments
You will need to use the RUN commmnad twice. Once to get over and once to get back.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
Similarly, RUN trashes FOR-NEXT counters. So a program has to use a DO-LOOP instead and manage its own loop counter.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
You lost me when you mentioned using a DO_LOOP instead of a FOR-NEXT. What's the difference with regards to my original question?
Thanks
The comment about DO-LOOP was tangential.
I should amplify the answer by saying that cross-bank RUN and return is strictly a do-it-yourself affair, and your program has to manage its own stack. And if your program does that, it cannot return to to a point within a subroutine or a FOR loop and expect their RETURN or NEXT to work properly.
A main loop might be structured as a DO : LOOP, and that is fine for a RUN. All the normal Stamp RAM and Scratchpad variables can be intact across slots.
Here are a couple of articles about this topic...
www.emesystems.com/BS2SX.htm#Crossbank
www.parallax.com/dl/docs/cols/nv/vol3/col/nv87.pdf
should be used in the main program, and not from a subroutine nor from within a FOR-NEXT loop. However, that does not matter if you have no intention of returning.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
As Tracy said, your stack is 'fresh' when you issue a RUN statement (i.e. isn't preserved across run slot jumps)- A possible work around is to manually keep track of where you need to go in a data statement, and check this location/flag each time you enter a run slot-
The articles Tracy referenced should help you along.
Ryan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Ryan Clarke
Parallax Tech Support
RClarke@Parallax.com