New editor simulator gosub issues?

Grant Fleming

Senior Member
Some different pieces of code that I could simulate on V5.08 ok but can't on V5.1 - I'm getting an "only 16 gosub commands allowed" error when I have just 16 on one programme. Another programme is o.k with the syntax check but while simulating will give-"stack error-more nested gosubs than the stack allows". I have 28X option checked and as far as I know have all the other editor options set-up the same as before?
Any ideas?
Cheers,
Grant
 

hippy

Ex-Staff (retired)
I think you've got two distinct issues here.

The 28X allows just 15 GOSUB statements in the source code because one of the 16 is reserved for use by interrupts ( even if interrupts are not used ). The error message isn't as clear as it could be. I'm not sure why the source compiled before but not now, as I am sure earlier compilers counted GOSUB's correctly.

The second issue is not how many GOSUB's are used but how many GOSUB statements can be executed before any RETURN must be. Compilation cannot spot these run-time errors and it's entirely possible the 5.1.0 simulator does a better job in that respect than earlier versions.
 

hippy

Ex-Staff (retired)
Gosub nesting too deep example -<code><pre><font size=2 face='Courier'>Depth0: Gosub Depth1 : SerTxd(&quot;OK&quot;) : End

Depth1: Gosub Depth2 : Return
Depth2: Gosub Depth3 : Return
Depth3: Gosub Depth4 : Return
Depth4: Gosub Depth5 : Return

Depth5: SerTxd(&quot;Bingo!&quot;) : Return </font></pre></code> Once 'Depth4:' has been reached, four GOSUB's will have been executed without any RETURN, a further GOSUB cannot be executed to go to 'Depth5:'.

If the code is run in a real PICAXE the &quot;Bingo!&quot; will be output but not the &quot;OK&quot;. The simulator catches where the error occurs which leads to that outcome.

The new X1 and X2 parts will allow a depth of 8 subroutines before things get screwed up.
 

kym

Member
I too am getting strange results with the simulator. No error messages but halts on

next b1

18X and 28X the same
this is just after gosubs routines:

And the X parts allow 256 gosubs:

Kym
 

hippy

Ex-Staff (retired)
Rev-Ed may have bugs in the simulator, and it would be surprising if there are not.

If you can narrow the circumstances down to or near to minimal code which causes incorrect behaviour and post that in the Software Feedback forum it would help Rev-Ed identify where there may be problems and help to get the problem fixed.
 

Grant Fleming

Senior Member
Hippy- thanks for the replies and your example. I wasn't aware of the 15 (not 16) max gosubs- understand one is taken by interrupt (even if not using interrupt). Also now understand max 4 nested gosubs- this has all just come to light now with the new simulator. This means I will have to rewrite (alter) some programmes now but the upside is that I have learnt something!

Kym- I am also now having trouble in the new simulation with getting stuck in for/next loops but maybe this is tied in with too many gosubs somewhere (no error shows-just gets stuck). I will continue to go through my programmes to work out why. As hippy suggests, I will write short pieces to simulate.
Cheers,
Grant
 
Top