Skip to content

48K, and Where It Goes

The machine is sold on 48K of memory. A useful amount of it is spoken for before your program starts.

  • Sinclair ZX Spectrum
  • Machine code

The Z80 can address 65,536 bytes, and on a 48K Spectrum every one of them is spoken for. Here is what sits where.

The map

Code
  $0000  +--------------------------------+
         |  ROM - BASIC, character set,   |   16K
         |  system routines               |
  $4000  +--------------------------------+
         |  Screen pixels                 |   6,144 bytes
  $5800  +--------------------------------+
         |  Screen colour                 |   768 bytes
  $5B00  +--------------------------------+
         |  Printer buffer                |   256 bytes
  $5C00  +--------------------------------+
         |  System variables              |   182 bytes
  $5CB6  +--------------------------------+
         |  Yours - channels, the BASIC   |   about 41K
         |  program, its variables, and   |
         |  the stacks working down       |
  $FFFF  +--------------------------------+

Two things read straight off it.

The first 16K is not memory you own. It is the ROM, and it is why the machine does anything at all when you switch it on. “48K” describes the RAM; the address space is 64K with a quarter already spent.

And the first thing in RAM is the screen — not somewhere convenient, not at the end. 6,912 bytes of picture sit at the bottom of the memory you were sold, because that is where the ULA reads from.

The ULA reads the bottom of your RAM

Which connects back to unit 2. The whole of $4000–$7FFF, not just the screen, is the bank the ULA shares with the processor, and everything in it slows down while the picture is drawn.

That gives the 48K a shape most machines do not have. It is not 48K of equivalent memory. It is 16K of slow memory with the screen at the bottom of it, and 32K of full-speed memory above $7FFF. Code that cares about speed lives in the top 32K and treats the bottom 16K as where the screen happens.

What the ROM keeps

Above the screen sit a few hundred bytes BASIC needs and a program is unwise to trample: the printer buffer, then the system variables — the machine’s notes about itself, including the current colours, the frame counter, and where it believes memory ends.

That last one is RAMTOP. On a cold 48K it starts at 65,367, short of the top of the address space, because BASIC reserves what is above it for its own stack and the user-defined graphics.

Which is where the standard trick comes from. CLEAR with a lower number moves RAMTOP down, and everything between the new top and the old is memory BASIC has promised not to touch — exactly where machine code goes to survive.

None of this is enforced by hardware. The chips do not know what a system variable is. It is convention the ROM imposes, which is why a program taking the whole machine can ignore most of it, and why one intending to call ROM routines afterwards cannot.

What reaches your program

Start from 48K. The screen takes 6,912 bytes whether it is used or not. The ROM’s working area takes a few hundred more. Whatever BASIC holds takes its share.

A machine-code program on a 48K Spectrum has something like 41K to work in, and that has to hold the code, the graphics, the level data, the music and the running state — with no disk to stream from, because there is not one.

That is the constraint behind most of the ingenuity on this machine: procedurally generated levels because the levels would not fit, tile-based graphics because full screens would not fit, and the compression in tape loaders because the game would not fit.

The four numbers

The briefing comes down to four, and they interlock. A processor with a fixed number of cycles between frames, sharing its most-needed memory with the screen. Colour stored eight times more coarsely than pixels. Sound that costs processor time directly. And 48K to hold all of it.

Everything in the Spectrum tracks — BASIC, assembly, whichever you take — is people working inside those numbers.

Sources

Sinclair Research, ZX Spectrum BASIC Programming, chapter 24, the memory: the map from the display file at 16384 through the attributes, printer buffer and system variables to 23734, and CLEAR moving RAMTOP; chapter 18, motion: the frame counter in the system variables at 23672. Chris Smith, The ZX Spectrum ULA: How to Design a Microcomputer (ZX Design and Media), chapter 18, p. 190: the ULA holding the processor for any address from 16384 to 32767 while it reads video bytes. The cold-start RAMTOP of 65,367 was read from RAMTOP (23730) in Emu198x after a 48K boot with the official ROM.