240 HIMEM highest memory location Purpose BASIC uses the computer’s random access memory (RAM) to store the user’s program, all the variables that the program uses, and memory for high-resolution graphics displays. In the absence of other instructions the computer divides the available memory up logically. However there are occasions, particularly when changing display modes and when writing machine code programs, when you may wish to tell BASIC how to divide up the available memory. One way of changing the allocation is by altering the value of the variable HIMEM . This variable contains the address of the highest memory location that BASIC uses for your program and variables.
It is automatically set to just below the memory used for the screen when the MODE is selected. Addresses above HIMEM are not used by BASIC. If it is manually altered then locations above HIMEM may be used by the programmer for other things, for example for machine code subroutines. If you wish to change the value of HIMEM you should normally do so very early in your program – preferably right at the beginning. The beginning of the program is also the place to select the display mode that you will be using. Other important boundaries are PAGE , TOP and LOMEM . The memory map in Appendix J gives an indication of their relative positions.
Note that in the ‘shadow screen’ mode, HIMEM always returns a value of &8000 (see chapter 42 for more details). Examples 100 HIMEM=HIMEM-40 100 PRINT HIMEM 100 HIMEM = &2800 Description HIMEM contains the address of the first byte that BASIC does not use. This pseudo-variable must not be altered while executing a function or a procedure. Alter it with great care! When using a second processor, or if the computer is being used in shadow mode, HIMEM will not be altered when changing MODE .