Forum Index
Possible MID function error

 
Author Message
cloxwerx



Joined: 01 Dec 2005
Location: Tucson, Arizona

Posted: 08 February 2006, 23:09 PM    Post subject: Possible MID function error

The following code indicates that variable, DummySpacer, which should not be changed, is changed. The long beep indicating this occurs in my test system. I ran some For statements to step the MID index and the MID length and the glitch occured for a position of 6 and lengths of 1 through 5. If the first Delay statement is commented out, there is no glitch.

Code:
Option   Explicit

'
'   Demonstrate MID left side function glitch
'
Public Const FreqOutPin     As Byte = 15    'Pin for Tone out

Public Wka (1 To 15)        As Byte         'TNC/GPS input work area
Public OtherCall            As String * 9   'Others CALLSIGN+SSID
Public DummySpacer          As Byte         'In case of erroneous string overflow
Public TNCInQue (1 To 50)   As Byte         'I/O queues
Public ii                   As Byte         'Loop counter
Public jj                   As Byte         'Loop counter

Public Sub Main ()
OtherCall="         "                       '9 spaces
DummySpacer=100                             'Just some initial value

Call Delay (0.5)
Wka(3)=6
Wka(4)=1
Mid(OtherCall,Wka(3),Wka(4))="     "        'Pad with up to five spaces
      
If DummySpacer <> 100 Then                  'Did it remain untouched?
   Call FreqOut(FreqOutPin,3900,3908,3000) 'No, Send a long beep
   Call Delay (1.0)
End If

End Sub



IDE V 1.0.3
ZX-24 firmware version 1.1.2

This one kept me awake for a while trying to discover what was happening in a 1500 line program.

Dennis
Back to top
mikep



Joined: 24 Sep 2005
Location: Austin, TX

Posted: 09 February 2006, 0:14 AM    Post subject:

I'm sure Don is looking into this problem right now.

My guess is that you have found a compiler optimization problem whereby it generates the wrong code. These are unfortunate and hard to isolate. To prove it you can turn off compiler optimization by adding the following line to the top of your PRJ file:
Code:
–-optimize=no-optimize
Back to top
cloxwerx



Joined: 01 Dec 2005
Location: Tucson, Arizona

Posted: 09 February 2006, 1:08 AM    Post subject:

Mike,

Thanks, that would be a good starting point except that optimization has been off in the larger program since the "early days". Though optimization was not off in the smaller test example, I just tried it and no change, so maybe this will be a bit easier to solve.

Dennis
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Location: Portland, OR

Posted: 09 February 2006, 2:21 AM    Post subject:

Quote:
If the first Delay statement is commented out, there is no glitch.

I was able to reproduce the problem but it still manifested with the delay commented out. In both cases, I compiled with optimization off.

It turns out that it is not an optimization problem. Rather it is an error in the VM code. The problem is caused by an incorrect comparison in the code that computes the number of characters that should be modified. As stated in the manual, the number of characters affected is supposed to be the minimum of:

1) the number of characters in the string from the specified position (second parameter) through the end of the string

2) the number of characters specified by the third parameter

3) the number of characters in the replacement string (the right hand side of the assignment).

The solution was simple and very localized. I'll post a new version of the VM after the regression tests (updated to check for this problem) are run. In the interim, if you'd like to begin using v1.1.3 while it is being tested you can retrieve the update image using the links below.

ZX-24
ZX-40
ZX-44

Thank you, Dennis, for taking the time to produce a succinct test case that demonstrated the problem.

Quote:
...optimization has been off in the larger program since the "early days".

I would encourage you to use the default optimization. There are no known optimization problems at present. There has been only one optimization problem discovered since the offical public release and it was fixed in the v1.1.0 release (mid December).
Back to top
cloxwerx



Joined: 01 Dec 2005
Location: Tucson, Arizona

Posted: 09 February 2006, 6:02 AM    Post subject:

You're welcome, Don. There's a perverse sense of accomplishment in discovering glitches in a well put together system. Glad I can contribute in a small way to the ZBasic robustness.

I'll have to turn on optimization after your statement of confidence in it. If there's a problem it has a good chance of showing up in this program.

Dennis
Back to top
mikep



Joined: 24 Sep 2005
Location: Austin, TX

Posted: 09 February 2006, 6:08 AM    Post subject:

cloxwerx wrote:
There's a perverse sense of accomplishment in discovering glitches in a well put together system. Glad I can contribute in a small way to the ZBasic robustness.
Well said Dennis.
Back to top
Display posts from previous:   
Page 1 of 1

 



ZBasic Microcontrollers Home
All content Copyright © 2005, 2006, 2007, 2008, 2009, 2010 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group