Did ZX80 BASIC have a way to check how much memory you were using and how much was left?

Or otherwise: if you were writing a program on a machine with the RAM expansion, was there a way to tell whether you were using enough memory that your program actually required the expansion?

3 Answers 3


The ZX80 puts the display file immediately after the storage necessary for your program, and puts a pointer to that at $400C. So you can figure out how many bytes you are using with:

PRINT (PEEK(16396) + 256 * PEEK(16397)) - 16384

That's sufficient if you know how much RAM there is in total. I'm hunting around for an equivalent of the ZX81's RAMTOP to do that automatically but can't find anything yet; will update answer if I find something.


You can detect ZX-80 memory by determining the current address of the stack pointer. This will obviously only work using machine code - Unfortunately, the ZX-80 has no such thing as RAMTOP, which is available in the ZX-81:

LD HL,0000        210000
ADD HL,SP         39
RET               C9

You can get that to run by

10 REM 12345
20 POKE 16427,33
30 POKE 16428,0
40 POKE 16429,0
50 POKE 16430,57
60 POKE 16431,201
70 PRINT USR(16427)

(Note, the USR is not a 1-key token, but has to be typed in character by character.)

From the other (lower) end of the memory, the display file and the program grow upwards - So the amount of free memory is the difference of what you get in this program and what you got in the other (accepted) answer.


I've had a quick browse around on this and there doesn't seem to be an easy way, top of memory is found by writing/reading values to and from memory during startup.

The ROM checks by using the Z80 stack pointer as indicator of top of memory (see RST 30 for details) Peeking DFEND should tell you if you definitely need more than 1K (if you're writing code on a 16K machine) but I'm not sure how much space you'd need to leave for the stack.

There is a test machine code routine in the 16K ram pack instructions which prints out memory size, I've not disassembled the code but my guess is it's copying the stack pointer somewhere.

So short of writing a small machine code stub to read the stack pointer (or peeking and poking say 8K into the RAM space) I can't see how to do this in BASIC.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .