08M Simulator problem?

Odessa

Senior Member
The 'Exit' command is supposed to cause a loop to be exited and program execution continues at the first line after the loop. I have a situation in simulating the 08M where this is not occurring, and seems to be a simulator problem. I am using Version 5.2.6.

The below code doesn't do anything, but illustrates the problem (I also have the problem in my real code that IS supposed to do something, but that code is more complicated than necessary to include here exclusively for the purposes of illustration).

Load the below code and set the generic analog value to 800 then have the simulator step through quickly. No problems. Stop the simulator at a convenient point in the code, say the 'For' statement (step to it if necessary). Change the analog value, which is the value read into W5 by the ReadADC10 command, to, say, 12, or anything <751, which will trigger the Exit. The Exit does cause the loop to be exited, however, program execution jumps to the Let Dirs command (as if a reset had been issued) and the code immediately below the For/Next loop is not executed at all. Let the simulator run freewheel and you will see this behavior repeats on each iteration of the loop.

Now, the real question is whether this happens in the 08M too?

Tech Support, any ideas?

Thanks, Odessa

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Let Dirs=%00001


CFL:
For W6=W2 to 100
Gosub TFD
If W5<751 then Exit
Pause 6
Next W6

b9=50
b3=178

Goto CFL

TFD:
ReadADC10 2,W5
Return
 
Last edited:

boriz

Senior Member
Prolly thinks 'Exit' is a label. (See IF..THEN in manual). Try proper multi-line format with ENDIF.
 

MPep

Senior Member
Hi Odessa,

Having tried your program in the simulator, using PE 5.2.6, I get the same results.
Updated to PE v5.2.7, and also using 14M, and 28X as examples, it does not step to the next line.
 

Odessa

Senior Member
Boriz, Exit is not a Label, but a bona fide Picaxe Basic command and should operate as previously indicated - see Manual 2.

MPep, thanks for doing that check, and also in the 14M and 28X modes. I could run some tests to see if the statement actually works properly in the real hardware, 08M in my case (although I have the 14M & 28X as well), but it is 11:15 pm here and I am off to the sack for the evening. Now that you have corroborated my results, though, Rev Ed is going to have to look into this and surely soon we will know if it is a recent revision Basic Interpreter problem or a Simulator problem, or both.

I have used the Exit command on other projects and I believe I simulated it before, and it worked correctly, so this is probably an upgrade problem.

Odessa
 

westaust55

Moderator
As Boriz has already mentioned and more in line with the example in the manual, try
Let Dirs=%00001


CFL:
For W6=W2 to 100
Gosub TFD
If W5<751 then : Exit : Endif
Pause 6
Next W6

b9=50
b3=178

Goto CFL

TFD:
ReadADC10 2,W5
Return
 

boriz

Senior Member
“Boriz, Exit is not a Label, but a bona fide Picaxe Basic command”

No. Really?

Because of the syntax you are using, whatever follows the THEN might be getting treated as a label. Usually only a label is allowed to follow the THEN. (Exit is a special case). Since Exit is a reserved word, it might be confusing the simulator if the simulator is expecting a label.

I was trying to be helpful by proposing an explanation and a solution.
 

hippy

Ex-Staff (retired)
There is an issue in the simulator causing the IF-THEN-EXIT to restart the program rather than continue after the FOR-NEXT which we will investigate. The issue does not affect a physical 08M chip.

For workrounds, westaust55's solution does work -

If b0 >= 5 Then : Exit : End If

An alternative is to temporarily rename Exit as a label name, for example -

If W5<751 then ExitForNext
Pause 6
Next W6
ExitForNext:

Whether this is an issue, as Boriz suggests, of the Simulator getting confused by the IF-THEN-EXIT and treating Exit as a label; I don't know, maybe. It's a reasonable stab-in-the-dark theory, but it could be something else.
 
Last edited:

Odessa

Senior Member
Ok, Hippy, thanks for the notification re the physical 08 behavior.

Perhaps all that is required would be for the simulator to flag an error such that the EndIf is mandatory.

Odessa.
 

Technical

Technical Support
Staff member
The endif is not mandatory, either of these work fine in the real chip (and in the simulator when we fix it! Untll then only 2 will work in simulation)

If W5<751 then Exit
If W5<751 then : Exit : endif
 
Top