<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Sun, 31 Oct 2004 14:55:43 +0000
From   : Richard Gellman <splodge@...>
Subject: Re: Dimensioned area space

Andrew W wrote:

>>To elaborate further, A%-Z% and @% are referred to as the "System 
>>Integers". BASIC allocates these in a separate memory space (&400-&700 I 
>>think?) so DIMing them doesn't take up memory to store that they exist.
>>
>>GH% however is simply an integer (exactly the same as if you did gh%) 
>>and so BASIC has to allocate memory for its name and value.
>>    
>>
>So if it takes up 3 bytes for the name and two bytes for the location
>address I where are the remaining 4 bytes going?
>
>A.Weston
>  
>
 From BBC Master Reference Manual Part 2, Section N, Page N4-4:

[snip]
LOMEM to VAR_TOP-1 (End of Program space to end of variable space, less 1)
The BASIC program's dynamic variable lie in this region. They are stored 
as 54 linked lists. The pointer to th head of each list is stored at 
&400+2*ASC(c$) and &401+2*ASC(c$), where c$ is the first character of 
the variable name. The format for a variable entry is:

LINK POINTER (TWO BYTES)      INCREASING ADDRESS
                                                                         
   |
NAME MINUS FIRST LETTER                        v
BUT INCLUDING $, %, or ( .

ZERO BYTE

VALUE OF VARIABLE

The end of hte list is marked by a zero high-byte in the linke pointer 
(or the head pointer in page four). The size of the variable depends on 
its type, e.g. four bytes for integers, five bytes for reals, a 
four-byte string information  block (SIB) for strings, etc.

Procedures and functions have their own linked lists. The value part 
gives the address of the DEF of the procedure/function in the program.
[snip]

I'm assuming 54 is 27 *2, 27 being 26 alphabet characters plus the 
underscore(?), and 2 being 1 for upper case, one for lower case 
(excepting the underscore, which may have an alternate?).

Thus your DIM GH% is: two bytes for the Link Pointer, 2 bytes for the 
name (H%, the G is implicit from the list number), one ZERO byte,  and 
four bytes for the value (0).

The total is 9 bytes. I believe the reason you are seeing 10, is because 
you have VAR_TOP-TOP. Since TOP points to the last byte of the program, 
you should be using DIM A%-1:P. A%-(TOP+1) - which would give you the 
correct value of 9.

-- Richard
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>