Re: TI85 Programs - anything like GOSUB?


[Prev][Next][Index][Thread]

Re: TI85 Programs - anything like GOSUB?



In article <325C53BE.3A5C@voicenet.com>, Webster <webster@voicenet.com>
writes
>Is there any command (okay I know there isn't a command for this) or a
>way to fake a gosub statement in a TI-85 basic program?  [snip]


You can fake it by calling the program recursively, something like this:


PRGM Aaaaargh
-------------


s\->\v          /* s = subroutine flag ; copy it to v
0\->\s          /* Reset flag for jump to Lbl MN at keyboard call


If v==0:Goto MN              /*Jump table, using v as flag
If v==1:Goto S1
If v==2:Goto S2
If v==3:Goto S3


Lbl MN                      /*Main driver
(code ......)


2\->\s:Aaaaargh                 /*Subroutine call
(code ......)


Stop


Lbl S1                           /*Subroutine S1
(code ......)
Return


Lbl S2                          /*Subroutine S2
(code ......)
Return


        This works fine. I've never had trouble with it, but I guess if
you were sloppy about program structure, you might eventually fill up
the stack with unRETURNed subroutine calls and crash the program.
        A bonus is that the subroutines are also available to calls from
separate programs, which can be useful if you're writing a suite of
programs.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Stuart Dawson                          Dawson Engineering
49 Knockbracken Park, Belfast  BT6 0HL,  Northern Ireland
sd@dawson-eng.demon.co.uk                 +44 1232 640669
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


Turnpike evaluation. For information, see http://www.turnpike.com/


References: