[Coco] CoCo BASIC
Arthur Flexser
flexser at fiu.edu
Wed Mar 24 01:09:06 EDT 2021
Steve, I just ran the following Basic program in the Mocha online emulator.
10 DIM A(4,5)
20 PRINT HEX$(VARPTR(A(1,1)))
30 PRINT HEX$(VARPTR(A(2,1)))
40 PRINT HEX$(VARPTR(A(1,2)))
The output was:
1E76
1E7B
1E8F
This tells me that the array elements are stored consecutively (in the
array storage area following the end of the program) as 5-byte quantities,
with the first subscript varying fastest:
A(0,0), A(1,0), A(2,0), A(3,0), A(4,0), A(0,1), A(1,1), A(2,1), A(3,1),
A(4,1), A(0,2), A(1,2), A(2,2), A(3,2), A(4,2), A(0,3), A(1,3) ....,
etc.
This follows from the fact that the output shows that A(1,1) and A(2,1) are
stored 5 bytes apart, while A(1,1) and A(1,2) are 25 bytes apart.
Further peeking showed that the array area pointer at $1D-1E points to
$1E4F, which, if you add 9 bytes for the header, agrees with the location
of A(0,0), which is stored at $1E58,
Art
On Tue, Mar 23, 2021 at 8:51 PM Steve Ostrom <smostrom7 at comcast.net> wrote:
> I’m trying to understand how BASIC handles arrays.
>
> The routine to evaluate an array variable starts at location $B401. The
> start address of the table for declared arrays is stored at $001D-$001E.
> The end of this table +1 is stored at $001F-$0020. The array flag is
> stored at $0005.
>
> Each element in an array is stored as a 5-byte value. In the array table,
> each array is preceded by a header block of 7 bytes for single dimensioned
> arrays or 9 bytes for a two dimensional array. Those bytes are made up of
> 2 bytes for the array name, 2 bytes containing the length of the array plus
> the header, the fifth byte holds the number of dimensions, followed by 2
> bytes for each dimension that contains the length of the dimension.
>
> My guess is that the values for a single-dimensioned array are stored
> sequentially in the memory location reserved for arrays. But how are the
> values for multidimensional arrays stored? Sequentially by the first
> dimension, followed by values for the second dimension?
>
> My goal is to set up arrays in BASIC, then access those arrays via
> assembly language.
>
> Thanks again for the help. Relearning this stuff has been fun, and good
> exercise for my 72 year old brain !! 😊
>
> --- Steve ---
>
>
>
> Sent from Mail for Windows 10
>
>
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> https://pairlist5.pair.net/mailman/listinfo/coco
>
More information about the Coco
mailing list