Simulator & program issues, @ptrdec

BCJKiwi

Senior Member
The following code does not behave as expected.

Code:
 Let b6=0
' read 137,b21  
 ptr = 37
 b20 = @ptr +9 /20 +@ptr   
 If b1 > b20 Then     
'  hi2cout [IO_3],$12,(%11111111)
  Goto SpeedEnd
 EndIf 
 If b1 >= @ptrdec Then                 '## REF 1
  b6=180
  goto SpeedOut
 EndIf 
' read 136,b21
 If b1 >= @ptrdec Then                 '## REF 2
 b6=179
  goto SpeedOut
 EndIf
The issue is that if the values are as follows;
ptr 37 = 110
ptr 36 = 100
ptr 35 = 88
b1 = 105,
b20 calculates to 115
the logic will take the process through to REF 2 at which stage the ptr should be at 36. The simulator says it is still at 37.
However it uses value stored at ptr 35!

Following this closely in the simulator,
at REF 1, the ptr does not change but after the then of the test at REF 2 it has jumped to 35.

So even though the line is processed and the test undertaken at REF 1, AND the ptr has decremented to 36 it does not show up that way in the simulator. It has decremented else it would not decrement to 35 at the next @ptrdec.

However at REF 2, it does not use the value for ptr 36 (as it should) but uses the value for ptr 35.

It seems to behave inconsistently.
The behaviour in hardware is the same as that in the simulator.
 
Last edited:

hippy

Senior Member
Using this cut-down and modified version of that code snippet ...

Code:
b0  = 0
ptr = 37 : @ptr = 110
ptr = 36 : @ptr = 100
ptr = 35 : @ptr = 88
ptr = 37
if b0 <= @ptrdec Then
  b1 = ptr 
  b2 = @ptr  
EndIf 
If b0 <= @ptrdec Then
  b3 = ptr 
  b4 = @ptr
EndIf
The problem seems to be that "IF @ptrdec" does what it is meant to but the simulator doesn't update the variable display until the next time 'ptr' or '@ptr' is referenced.

Changing that again, and it seems that at "REF 2", 'ptr' has the right value (36), as does '@ptr' (100), or it wouldn't execute 'End' ...

Code:
b0  = 100
ptr = 37 : @ptr = 110
ptr = 36 : @ptr = 100
ptr = 35 : @ptr = 88
ptr = 37
if b0 = @ptrdec Then
EndIf 
If b0 = @ptrdec Then '## REF 2
  End
EndIf
 

BCJKiwi

Senior Member
I've found with further testing where the execution issue is;

As reported and as you, Hippy, have also found, the simulator does not update the ptr address properly but the underlying ptr value does change.

There were two issues that led me to the conclusion that the ptr value was incorrect;
1. The sertxd in the program code was AFTER the b6= so it reported the value after the next @ptrdec (correctly pointing to 35).
2. The code in the Speedout subroutine worked off @ptr so it also had the benefit of the second @ptrdec (35) the same as the sertxd.

This works correctly;
Code:
 Let b6=0
' read 137,b21  
 ptr = 37       
 b20 = @ptr +9 /20 +@ptr   
pause 1200
 If b1 > b20 Then     
'  hi2cout [IO_3],$12,(%11111111)
  Goto SpeedEnd
 EndIf 
 If b1 >= @ptr Then    
  b6=180
  goto SpeedOut
 EndIf 
' read 136,b21
ptr =36
 If b1 >= @ptr Then    
  b6=179
  goto SpeedOut
 EndIf
Replacing each "@ptrdec" with an "@ptr" followed by a separate "dec ptr" adds 4 bytes to the program!
However using an @ptr and ptr=xx instead of dec ptr takes less program space.

So we still need Technical to arrange a fix for the simulator!
 
Last edited:

Technical

Technical Support
Staff member
The simulator is working with the correct values, but simply not refreshing the visual display when the @ptrinc/dec is used. This gives the appearance of the wrong value. We will fix this in the next release.
 
Top