Shop OBEX P1 Docs P2 Docs Learn Events
Pbasic prog question. — Parallax Forums

Pbasic prog question.

stamp_demonstamp_demon Posts: 69
edited 2005-05-02 13:06 in BASIC Stamp
I was wondering if it was possible to call a subroutine within a subrouitine? As an example .. If I had a sub routine named IR: and bassed on different conditions I might want to call RIGHT:, or LEFT: ..... thnanks again _Duane

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-05-02 07:57
    Duane -

    Since there is no PBASIC "CALL" instruction, I'l presume you're speaking about GOSUB here. The answer is yes, you can have nested GOSUBS. Here are the restrictions on GOSUBS which can be found in the PBASIC Help File (which see):

    Nested Total Number of
    GOSUBS GOSUBS
    BS-1 4 16

    BS-2 4 256

    Just make sure all of your GOSUBS and RETURNS are properly paired.

    Regards,

    Bruce Bates
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-05-02 13:06
    In other words:

    On the BS2, you can have up to 256 total GOSUB destinations.

    And, you can nest them 4-deep. Thus your 'main' loop can call GOSUB Sub_A, which calls Sub_B, which calls Sub_C, which calls Sub_D. If Sub_D then calls anything, you may have messed up your return stack.

    Note, with only 2K of code space, and 26 bytes of variable space, this does not tend to be much of a limitation.
Sign In or Register to comment.