Shop OBEX P1 Docs P2 Docs Learn Events
BS1 GOSUB Limit — Parallax Forums

BS1 GOSUB Limit

SapphireSapphire Posts: 496
edited 2015-05-20 13:30 in BASIC Stamp
The Basic Stamp Syntax and Reference Manual says you can have up to 16 GOSUBs in a BS1 program. But when I tried, the program won't tokenize or load. Even though there are only 16 GOSUBs, a pop-up warning says "Limit of 16 GOSUBs was exceeded." So is the manual wrong, or is there a bug in the editor? It appears the maximum is 15. Does anyone know why?
' {$STAMP BS1}
' {$PBASIC 1.0}

GOSUB A '1
GOSUB A '2
GOSUB A '3
GOSUB A '4
GOSUB A '5
GOSUB A '6
GOSUB A '7
GOSUB A '8
GOSUB A '9
GOSUB A '10
GOSUB A '11
GOSUB A '12
GOSUB A '13
GOSUB A '14
GOSUB A '15
GOSUB A '16

END

A:
RETURN

Comments

  • JonnyMacJonnyMac Posts: 9,157
    edited 2015-05-19 19:29
    I write a lot of BS1 programs for EFX-TEK customers and I've never run into that limit. You might consider a state machine (use BRANCH) to call routines instead of using GOSUB.
  • SapphireSapphire Posts: 496
    edited 2015-05-19 19:38
    Jon,

    Oh, I've got those in there too. That's a neat trick. But this program needed exactly 16 GOSUBs (for some I2C routines) and I hit this error. I in-lined one to cut it back to 15, but wonder why that's the limit. The BS1 tokenizes GOSUB with a 4-bit GOSUB number, so it would seem that 16 should work. I wonder if the problem is with the editor, although I tried a very old STAMP.EXE (DOS) program and it too reports the same error.
  • JonnyMacJonnyMac Posts: 9,157
    edited 2015-05-20 06:34
    You're doing I2C on a BS1? Wow, my hat is off to you!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2015-05-20 09:22
    I agree with Jon that a BRANCH would be a more efficient solution, however we are looking into the issue about the GOSUB. From the limited information I have it may very well be that the limit was meant to be 16. This is based on the fact that the BS2 uses a byte value and has a limit of 255 (not 256), however I will have our Application Engineer follow-up with a confirmation on this.
  • Jeff MartinJeff Martin Posts: 760
    edited 2015-05-20 09:37
    Hi,

    It appears we intended it to be a limit of 16 but the final limit became 15 in the final implementation. Unfortunately, both the manual and the tokenizer's error message states 16 as the limit, but it definitely limits it to 15 in practice.

    I don't have reason to think that there's a bug, but rather a mistake in the error message itself and the documentation also. I will check on this to see if I can determine all that for sure.
  • Jeff MartinJeff Martin Posts: 760
    edited 2015-05-20 12:42
    UPDATE: It's not easy to diagnose this in the BASIC Stamp 1 tokenizer, however I can confirm now that the technique employed in the BASIC Stamp 2 tokenizer follows the same kind of steps where it counts from 0 to a power of 2 minus 1. Since the tokenized code stores a table of gosub routines at the start of code, the count (which is 4 bits in the BS1) serves as both a count of total GOSUBs in the program and also an index into this table, where one of the possible values means "zero gosubs."

    So, it's true that on the BS1 programs are limited to a maximum of 15 GOSUBs total, but the error message in the tokenizer, and consequently the documentation, incorrectly states that it's limited to 16.

    We're sorry about the mistake and the inconvenience it has caused you.
  • PublisonPublison Posts: 12,366
    edited 2015-05-20 13:06
    UPDATE: It's not easy to diagnose this in the BASIC Stamp 1 tokenizer, however I can confirm now that the technique employed in the BASIC Stamp 2 tokenizer follows the same kind of steps where it counts from 0 to a power of 2 minus 1. Since the tokenized code stores a table of gosub routines at the start of code, the count (which is 4 bits in the BS1) serves as both a count of total GOSUBs in the program and also an index into this table, where one of the possible values means "zero gosubs."

    So, it's true that on the BS1 programs are limited to a maximum of 15 GOSUBs total, but the error message in the tokenizer, and consequently the documentation, incorrectly states that it's limited to 16.

    We're sorry about the mistake and the inconvenience it has caused you.

    It's amazing in all these years none has tested these limits before!

    Great rapid response from Parallax, thanks Jeff!
  • SapphireSapphire Posts: 496
    edited 2015-05-20 13:25
    JonnyMac wrote: »
    You're doing I2C on a BS1? Wow, my hat is off to you!

    Jon,

    The program is attached in case you're interested. I had to make some compromises with the Ack/Nak, but otherwise it meets spec. I can read the voltages and temperature and send them back to my monitoring station. Note that I use tabs instead of spaces, so formatting might be off if you don't use them.
    The tab stops are set for: 5,9,13,17,21,25,29,33,57,61,65

    Jeff,

    Thanks for the clarification. I too noticed the 255 limit on a BS2 (never tried to exceed it) and figured it was really 15 on the BS1, but since the documentation said 16 I was going with that. In any case, I have a work-around. I'm really pushing the limit on this one, but for this application it's just right.
  • Jeff MartinJeff Martin Posts: 760
    edited 2015-05-20 13:30
    You're welcome, Sapphire.

    It's awesome that you were able to do an I2C implementation on the BS1!
Sign In or Register to comment.