80-Bus News |
May–June 1983 · Volume 2 · Issue 3 |
Page 31 of 59 |
---|
The workings of Nascom ROM BASIC Ver 4.7 | PAGE 8 | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
******** How variables and arrays are stored ******** | |||||||||||||||||||||||||||||
Variables such as AB AB$ and FN AB are all stored in the simple variable area of memory. The start address of this area is held in PROGND and the end address is held in VAREND. | |||||||||||||||||||||||||||||
If AB=10 and AB$="TEXT” and FN AB(XY) had been defined then the memory would look like this | |||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||
Arrays such as AB(1,3) and AB$(3,1) are stored in the array area of memory. The start address of this area is held in VAREND and the end address is held in ARREND. | |||||||||||||||||||||||||||||
If DIM AB(1,3),AB$(3,1) had been entered then the memory would look like this:– | |||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||
The workings of Nascom ROM BASIC Ver 4.7 | PAGE 9 | |||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
******** Usage of the stack for GOSUB/RETURN and FOR/NEXT ******** | ||||||||||||||||||||||||
GOSUB and RETURN usage of the stack | ||||||||||||||||||||||||
When a GOSUB is executed the address of where to RETURN to and the number of the line to RETURN to are PUSHed on the stack as follows:– | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
This GOSUB block remains on the stack until a RETURN is executed at which point BASIC looks back through the stack until it finds a GOSUB block and then sets the stack there and then POPs the line number and the address of the statement after the GOSUB and continues execution. | ||||||||||||||||||||||||
The fact that the stack is set to this GOSUB block kills all active FOR loops which were set up inside the subroutine. | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
FOR and NEXT usage of the stack | ||||||||||||||||||||||||
When a FOR is executed the address of the first statement in the loop, the line number of the loop statement, the TO value, the STEP value and the sign of the STEP are all PUSHed onto the stack as follows:– | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
This FOR block remains on the stack until a matching NEXT is executed. When next is executed BASIC looks back through the stack to find the matching FOR block. If it is found then the STEP value is added to the value of the index variable and the result is compared with the TO value. With the use of the TO value and the sign of the step BASIC knows if the loop has been completed or not. If it has not been completed then the FOR block remains on the stack until the loop has been completed. The stack is set to point to this FOR block and effectively kills all FORs nested within this loop. When the loop is completed the FOR block is removed from the stack and execution continues from after the NEXT instruction. | ||||||||||||||||||||||||
If the FOR block cannot be found then a “?NF Error” occurs. | ||||||||||||||||||||||||
NASCOM ROM BASIC dis-assembled is available in ASM and LST file format.
Page 31 of 59 |
---|