int e l 1.7 STORAGE ALLOCATION This section is intended to answer the question -- where does MCS BASIC-52 store its variables and strings? Two 16 bit pointers stored in external memory control the allocation of strings and variables and an additional two pointers control the allocation of scalar variables and dimensioned variables. These pointers are located and defined as follows: LOCATION (H-L) NAME DESCRIPTION 10A H- 10B H MTOP THE TOP OF RAM THAT IS ASSIGNED TO BASIC 104 H- 105 H VARTOP VARTOP = MTOP - (THE NUMBER OF BYTES OF MEM- ORY THAT THE USER HAS ALLOCATED FOR STRINGS).
IF STRINGS ARE NOT USED, VARTOP = MTOP 106 H- 107 H VARUSE AFTER A NEW, CLEAR, OR RUN IS EXECUTED, VARUSE = VARTOP, EVERYTIME THE USER ASSIGNS OR USES A VARIABLE VARUSE IS DECREMENTED BY A COUNT OF 8. 108 H- 109 H DIMUSE AFTER A NEW, CLEAR, OR RUN IS EXECUTED, DIMUSE = [LENGTH OF THE USER PROGRAM THAT IS IN RAM MEM- ORY + STARTING ADDRESS OF THE USER PROGRAM IN RAM (512) + THE LENGTH OF ONE FLOATING POINT NUMBER (6)]. IF NO PROGRAM IS IN RAM MEMORY, DIMUSE = 518 AFTER A CLEAR IS EXECUTED MCS BASIC-52 stores string variables between VARTOP and MTOP.
$(0) is stored from VARTOP to VARTOP + (user defined string length + I ), $(1 ) is stored from VARTOP + (user defined string length + I) + I to VARTOP + 2 * (user defined string length + 1) etc. If MCS BASIC-52 attempts to access a string that is outside the bounds established by MTOP, a MEMORY ALLOCATION ERROR is generated. Now, Scalar variables are stored from VARTOP "down" and Dimensioned variables are stored from DIMUSE "up." When the user dimensions a variable either implicity or explicity the value of DIMUSE increases by the number of bytes required to store that dimensioned variable. For example, if the user executes a DIM A(10) statement, DIMUSE would increase by 66.
This is because the user is requesting storage for 11 numbers (A(0) through A(10)) and each number requires 6 bytes for storage and 6 * 11 = 66. - 185 -