Shop OBEX P1 Docs P2 Docs Learn Events
SX/B v1.42.01 - GOSUB nesting — Parallax Forums

SX/B v1.42.01 - GOSUB nesting

Mike CookMike Cook Posts: 829
edited 2005-11-16 09:10 in General Discussion
First off not complaining, just learning to convert various BS2xx programs to SX/B!

In the "PBASIC Syntax Guide" for GOSUB it states:

"GOSUB Limitations
 
Only a limited number of GOSUBs are allowed per program (as shown in above), and they may be nested only four levels deep. In other words, the subroutine that's the destination of a GOSUB can contain a GOSUB to another subroutine, and so on, to a maximum depth (total number of GOSUBs before the first RETURN) of four. Any deeper, and the program will "forget" its way back to the starting point (the instruction following the very first GOSUB).
 
When GOSUBs are nested, each RETURN takes the program back to the instruction after the most-recent GOSUB. As is mentioned above, if the BASIC Stamp encounters a RETURN without a previous GOSUB, the entire program starts over from the beginning. Take care to avoid these phenomena."


·I have read the GOSUB documentation in the SX/B help file and did not see this type of limitation, was wondering if this applies to SX/B or if there was a nesting limitation?


Thanks,

Mike

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"OEM NMEA GPS Module" Now available on ebay for only $19.99

Product web site: http://www.allsurplus.net/Axiom/

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-16 03:52
    There is a limit, but it has to do with the SX stack -- I ran into this when writing the Serial Injet Printer module code. I believe the limit is eight nested GOSUBs.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Mike CookMike Cook Posts: 829
    edited 2005-11-16 03:55
    Thanks Jon,

    Went back and RE-READ the SX/B Gosub documentation, sure enough in the Quick Facts section, there it is, "Maximum Nested GOSUBs = 8"

    DOH!!!!!!!!!!!!!!!!!!

    Mike



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "OEM NMEA GPS Module" Now available on ebay for only $19.99

    Product web site: http://www.allsurplus.net/Axiom/

    Post Edited (Mike Cook) : 11/16/2005 4:21:36 AM GMT
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2005-11-16 09:10
    Mike, Jon,

    Although I assume everybody has STACKX or OPTIONX mode on when using SX2Xes (both are synonymes). Nevertheless you should keep an eye on it. Without setting it, subroutine nesting will be limited to just two. Imagine what happens when you remove this setting by mistake in a program later - it may cost you some sleepless nights.

    As long as you are using SX/B, don't worry, the compiler will automatically generate a DEVICE STACKX directive fir you.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Greetings from Germany,

    G
Sign In or Register to comment.