Difference between revisions of "DIM Basic432"

From BeebWiki
Jump to: navigation, search
m
m (Slight tweeks.)
 
Line 1: Line 1:
 
[[Category:BASIC_Corrections]]
 
[[Category:BASIC_Corrections]]
 
 
Correction to the [[DIM]] statement for BASIC 4r32.
 
Correction to the [[DIM]] statement for BASIC 4r32.
  
[[6502_BBC_BASIC#BASIC_4.32.2C_HIBASIC_4.32|HIBASIC 4.32]] added the following check in the Multiply Upper Dimension by Lower Dimension routine:
+
[[6502_BBC_BASIC#BASIC_4.32.2C_HIBASIC_4.32|HIBASIC 4.32]] added the
 +
following check in the Multiply Upper Dimension by Lower Dimension routine:
 
<pre>      [&95E4] BCS 11 --> &95F1 Bad Dim error</pre>
 
<pre>      [&95E4] BCS 11 --> &95F1 Bad Dim error</pre>
  
this occurs after we have multiplied &2A-&2B by 2, and avoids memory corruption if the number of elements to dimension (&2A-&2B) is too large.
+
this occurs after we have multiplied &2A-&2B by 2, and avoids memory
This check now correctly disallows arrays to be DIMmensioned, where the number of elements would exceed 65535 (&FFFF).
+
corruption if the number of elements to dimension (&2A-&2B) is too large.
In BASIC IV, DIM K(1582,127) was allowed (total of 200914 elements!) which caused the following weird bug:
+
This check now correctly disallows arrays to be DIMmensioned where the
 +
number of elements would exceed 65535 (&FFFF). In BASIC IV, DIM K(1582,127)
 +
was allowed (total of 200914 elements!) which caused the following weird
 +
bug:
  
 
<pre>
 
<pre>
Line 31: Line 34:
 
</pre>
 
</pre>
  
Memory was corrupted, causing BASIC to become confused. In BASIC4 r32, DIM K(1582,127) now produces 'Bad DIM' error.
+
Memory was corrupted, causing BASIC to become confused. In BASIC4 r32, DIM
 +
K(1582,127) now correctly produces 'Bad DIM' error.

Latest revision as of 13:47, 17 October 2020

Correction to the DIM statement for BASIC 4r32.

HIBASIC 4.32 added the following check in the Multiply Upper Dimension by Lower Dimension routine:

      [&95E4] BCS 11 --> &95F1 Bad Dim error

this occurs after we have multiplied &2A-&2B by 2, and avoids memory corruption if the number of elements to dimension (&2A-&2B) is too large. This check now correctly disallows arrays to be DIMmensioned where the number of elements would exceed 65535 (&FFFF). In BASIC IV, DIM K(1582,127) was allowed (total of 200914 elements!) which caused the following weird bug:

>L. 
10 DIM K(1582,127) 
20 FOR I% =1 TO 1582 
30 FOR J%=1 TO 127 
40 K(I%,J%)=56.77777 
50 NEXT J% 
60 NEXT I% 
>RUN 

Array at line 40 
>L. 
0 DIM K(1582,127) 
0 FOR I% =1 TO 1582 
0 FOR J%=1 TO 127 
0 K(I%,J%)=56.77777
0 NEXT J% 
0 NEXT I%
>

Memory was corrupted, causing BASIC to become confused. In BASIC4 r32, DIM K(1582,127) now correctly produces 'Bad DIM' error.