@wassermann
unser Guru PicNick hat hier etwas kryptisch geantwortet...

zum Stack:
Ich habe gute Erfahrungen mit dem Bascom Befehl $DBG und DBG gemacht. Lies mal dazu im Handbuch nach (und auch mal STCHECK)...

Ansonsten kannst Du den Bedarf an Stack selber abschätzen.
Dazu steht im Handbuch:

HW STACK
Most statements need HW stack too.
An interrupt needs 32 bytes!!!!!!
When you use GOSUB or CALL, you are using 2 bytes of HW stack space.
When you nest 2 GOSUB’s you are using 4 bytes (2*2).
SOFT STACK
When you use a LOCAL variable inside a SUB or function. Each local variable will use 2 bytes.
Each variable that is passed to a sub program uses 2 bytes too. So when you have used 10 locals in a SUB and the SUB passes 3 parameters, you need 13 * 2 = 26 bytes.
This space is freed when the routine ends.
But when you call another sub inside the sub, you need more space.
FRAME SPACE
Each local is stored in a space that is named the frame space.
When you have 2 local integers and a string with a length of 10, you
need a frame size of (2*2) + 11 = 15 bytes.

The internal conversion routines used when you use INPUT
num,STR(),VAL() etc, also use the frame. They need a maximum of 16
bytes. So for this example 15+16 = 31 would be a good value.

When ever you use a num<>string conversion routine like:
Print b (where b is a variable)
Bytes will use 4 bytes max (123+0)
Integer will use 7 bytes max (-12345+0)c
Longs will use 16 bytes max
And the single will use 24 bytes max

When you add strings and use the original the value must be remembered by the compiler.
Consider this :
s$ = "abcd" + s$
Here you give s$ a new value. But you append the original value so the original value must
be remembered until the operation has completed. This copy is stored in the frame too.
So when string s$ was dimmed with a length of 20, you need a frame space of 20+1(null
byte)
When you pass a variable by VALUE (BYVAL) then you actually pass a copy of the variable.
When you pass a byte, 1 byte of frame space is used, a long will take 4 bytes.
When you use a LOCAL LONG, you also need 4 bytes of frame space to store the local long.
Meine Tipps für kurzen Bascom-Code mit geringem Stackbedarf:
  • Beachte die 32Byte SW-Stack in ISR.
    Vermeide LOCAL Variable
    Vermeide SUB mit Parameterübergabe
    Vermeide Bit-Variable
    Vermeide a>b, verwende a>=c oder b<a (RISC-Prozessor kennt kein größer als)
    Vermeide Single/Long etc. und dazugehörige Matheoperationen (am besten nur Byte und Word)