Egghead.page Logo

How Sinclair ZX81 NEW Command Clears Memory

The Sinclair ZX81 was a pioneering home computer known for its minimalistic design and efficient use of limited resources. When users typed the NEW command, the system did not simply wipe memory but instead reset specific system variables to reclaim space for new programs. This article explores the technical process behind the NEW command, detailing how the ZX81 managed memory pointers and cleared the program area without disrupting the core operating system.

The ZX81 Memory Architecture

To understand how the NEW command functions, one must first look at the ZX81’s memory map. The machine typically came with 1KB of RAM, starting at decimal address 16384. Unlike modern computers that might isolate operating system memory from user memory strictly, the ZX81 stored its system variables at the very beginning of this RAM block. These variables acted as pointers, telling the Z80 processor where the basic program started, where variables were stored, and where the display file resided. This pointer-based system was crucial for a machine with such constrained resources, as it allowed for dynamic memory allocation without needing complex memory management hardware.

Executing the NEW Command

When a user typed NEW and pressed enter, the ROM-based BASIC interpreter triggered a specific routine designed to reset the user environment. The command did not physically zero out every byte of RAM, which would have been a slow and unnecessary process on the 3.25 MHz processor. Instead, the routine logically cleared the memory by manipulating the system variable pointers. It reset the program start pointer to the immediate end of the system variable area, effectively telling the computer that the program space was empty. Simultaneously, it reset the variable storage pointer to the same location, ensuring that any previously stored numerical or string variables were no longer accessible.

System Variables and Pointers

The core of this operation relied on specific memory addresses within the system variable block. Addresses 16386 and 16388 were particularly important, storing the locations for variables and the program text respectively. Upon executing NEW, the ROM routine wrote new values to these addresses. By pointing the program start address to the bottom of the available RAM just after the system variables, the interpreter ignored any residual data left in the higher memory addresses. This data remained physically present in the RAM chips until it was overwritten by new program lines or variables, but it was logically inaccessible to the BASIC interpreter.

Efficiency and Design Philosophy

This method of clearing memory highlights the engineering philosophy behind the Sinclair ZX81. Speed and efficiency were prioritized over thoroughness. A physical memory wipe would have consumed valuable processing cycles and made the NEW command feel sluggish to the user. By simply moving the pointers, the computer could return to a ready state almost instantly. This approach also preserved the integrity of the ROM operating system, which remained untouched in its own separate chip. The distinction between logical clearing via pointers and physical clearing via zeroing is a key example of how early home computers maximized performance within severe hardware limitations.