How the Sinclair ZX80 Stored Array Data in Memory
This article explores the technical mechanisms behind array storage on the Sinclair ZX80. It details the memory layout, the five-byte floating-point format used for numbers, and the linear mapping strategy employed by Sinclair BASIC to manage multi-dimensional data within severe hardware constraints.
The Sinclair ZX80, released in 1980, was defined by its extreme hardware limitations, most notably its standard 1KB of RAM. This tiny memory pool had to accommodate the video display, the machine code monitor, the BASIC interpreter, the user’s program, and all variable data. Because memory was so scarce, the engineers at Sinclair Research designed a highly compact system for storing data structures. Understanding how arrays were stored requires looking at the specific variable storage area within the RAM map and the data representation standards used by the built-in BASIC interpreter.
When a user defined an array using the DIM command, the
Sinclair BASIC interpreter reserved a contiguous block of memory within
the variable storage area. This area was located immediately after the
program text in RAM. Unlike modern systems that might use complex
headers or pointers for every element, the ZX80 stored array elements
sequentially. This linear storage method minimized overhead but required
the interpreter to calculate the exact memory offset every time an array
element was accessed during program execution.
Numeric data on the ZX80 was stored using a five-byte floating-point format. Each number consumed 40 bits of memory, consisting of one byte for the exponent and four bytes for the mantissa. This format allowed for a wide range of values but meant that even simple integer arrays consumed significant space. For example, a dimensioned array of ten numbers required 50 bytes of RAM, which was a substantial portion of the available user memory after the display file and system variables were accounted for.
Multi-dimensional arrays were handled through a process of
linearization. Although a programmer might define a grid using two or
more dimensions, such as DIM A(10,10), the memory itself
was one-dimensional. The interpreter mapped these dimensions into a
single sequence using a row-major order, where the last subscript varied
the fastest. To access a specific element, the BASIC interpreter
performed multiplication and addition operations on the indices to
determine the correct offset from the start of the array block. This
calculation happened in real-time, which could impact performance in
tight loops but saved the memory cost of storing additional lookup
tables.
String arrays followed a different structure, requiring storage for the length of each string alongside the character data itself. This added further complexity to the memory management system. Due to the lack of memory protection hardware, attempting to access an index outside the defined dimensions could lead to the interpreter overwriting adjacent memory areas. This often resulted in program crashes or corrupted variables, a common hazard for developers working within the ZX80’s unforgiving 1KB environment. Ultimately, the ZX80’s array storage was a testament to efficient software engineering, maximizing utility within a minimalistic hardware framework.