ZX80 BASIC reference
Every command, function and operator in Sinclair ZX80 integer BASIC.
In this reference: Hardware · Escape codes · File formats · Argument notation
Notes and caveats
- Arithmetic is 16-bit signed integer only — there is no floating point, and division truncates.
- One numbered statement per line; line numbers must be strictly ascending. There are no multi-statement lines and no
ELSE. - Variable names are single letters (
A–Z, with a$suffix for strings); strings are taken apart withTL$andCODErather than slicing. AND,ORandNOTcombine their operands bit by bit —5 AND 3is1andNOT 5is-6— and a true comparison is-1. The ZX81 that replaced this machine answers5and0and1to the same three expressions, so logic is one of the things a program carried between the two Sinclairs has to be read for.- There is no
<=,>=or<>. Combine the ones there are:NOT A<Bis how a program saysA>=B. - The power operator is
**, folding left to right, on integers like everything else here.
Command Function Operator
| Syntax & description | |
|---|---|
- | <number> - <number> | -<number>Subtracts one integer from another, or negates a single value. All arithmetic is integer-only with no fractional part. |
, | PRINT <expr>, <expr>PRINT separator that moves the cursor to the next tab field before printing the following item, lining output up into columns. |
; | PRINT <expr>;<expr>PRINT separator that joins items together with no spacing, printing the next value immediately after the previous one. |
( | (Opens a parenthesised group, used to control evaluation order or to index an array element. |
) | )Closes a parenthesised group, such as an array subscript or a bracketed sub-expression. |
* | <number> * <number>Multiplies two integers together. |
** | <number> ** <number>Raises one integer to the power of another. The ZX80 spells exponentiation as ** rather than ^, and the result is an integer. |
/ | <number> / <number>Integer division: the result is truncated to a whole number, since the ZX80 has no floating point and discards any remainder. |
+ | <number> + <number>Adds two integers together. |
< | <number> < <number>Less-than comparison. There is no <= operator; combine with AND/OR/NOT instead. |
= | <number> = <number>Tests two values for equality in conditions, and also assigns a value in a LET statement. |
> | <number> > <number>Greater-than comparison. There is no >= operator; combine with AND/OR/NOT instead. |
ABSintegral function | ABS(<number>)Returns the absolute (unsigned) value of the argument. |
AND | <number> AND <number>Logical AND of two conditions, giving a non-zero (true) result only when both operands are non-zero. |
CHR$integral function | CHR$(<number>)Returns the single-character string for the given ZX80 character code. The inverse of CODE. |
CLEAR | CLEARDeletes all variables while leaving the program itself intact. |
CLS | CLSClears the display, leaving a blank screen. |
CODEintegral function | CODE(<string>)Returns the ZX80 character code of the first character of the string (0 for the empty string) - the machine's own codes, not ASCII. The inverse of CHR$. |
CONTINUE | CONTINUEResumes a program that was halted by STOP or by BREAK. |
DIM | DIM <numvar>(<number>)Declares a numeric array with the given number of elements. Array names are a single letter, and elements hold integers only. |
FOR | FOR <numvar> = <number> TO <number>Begins a counting loop. The control variable is a single letter, the bounds are integers, and there is no STEP, so the counter always increments by one. |
GOSUB | GOSUB <number>Calls a subroutine at the given line number; a later RETURN comes back to the statement after the GOSUB. |
GOTO | GOTO <number>Jumps to a line number. The target may be a computed expression, not just a literal line number. |
IF | IF <number> THEN <statement>Runs the statement after THEN when the condition is true. Conditions use =, <, >, AND, OR and NOT; there is no ELSE. |
INPUT | INPUT <var>Pauses the program to read a value typed at the keyboard into the given variable. |
LET | LET <var> = <expr>Assigns a value to a variable. LET is mandatory on the ZX80 - assignment cannot be written without it. |
LIST | LIST [<line>]Lists the program to the screen, optionally starting from a given line number. |
LOAD | LOADLoads a program from cassette tape. As with SAVE, tapes are anonymous since the ZX80 has no named files. |
NEW | NEWErases the current program and all variables, leaving an empty workspace. |
NEXT | NEXT <numvar>Marks the end of a FOR loop, incrementing the named control variable and looping back until its limit is passed. |
NOT | NOT <number>Logical negation: yields 1 when its argument is 0 and 0 for any non-zero value. Useful for building comparisons the ZX80 lacks, e.g. NOT A<B for A>=B. |
OR | <number> OR <number>Logical OR of two conditions, giving a non-zero (true) result when either operand is non-zero. |
PEEKintegral function | PEEK(<addr>)Returns the byte (0–255) stored at the given memory address. |
POKE | POKE <addr>, <byte>Writes a single byte (0–255) directly into memory at the given address. |
PRINT | PRINT [<expr>][;|,]…Writes to the display. ZX80 BASIC is integer-only, so numeric values print without a fractional part; ; joins items tightly and , tabs to the next field. |
RANDOMISE | RANDOMISE [<number>]Seeds the random number generator that the ZX80 RND function draws on. RANDOMISE 0 (or with no argument) seeds it from the frame counter for an unpredictable start. |
REM | REM <comment>Marks the rest of the line as a comment, which is ignored when the program runs. |
RETURN | RETURNReturns from a subroutine, resuming execution at the statement after the matching GOSUB. |
RNDintegral function | RND(<number>)Returns a pseudo-random number. On the ZX80, RND takes an argument and must be written with parentheses (unlike the later ZX81). Seed the sequence with RANDOMISE. |
RUN | RUN [<line>]Clears all variables and runs the program, optionally starting from a given line number. |
SAVE | SAVESaves the current program to cassette tape. The ZX80 has no named files, so the dump is anonymous. |
STOP | STOPHalts the program, reporting where it stopped so it can be resumed with CONTINUE. |
STR$integral function | STR$(<number>)Returns the number formatted as a string, exactly as PRINT would display it. |
THEN | IF <number> THEN <statement>Introduces the single statement run when the IF condition is true. The ZX80 has no ELSE and no multi-statement lines, so exactly one statement may follow. |
TL$integral function | TL$(<string>)Returns the "tail" of a string: everything after the first character (the ZX80 equivalent of MID$(a$, 2) on other machines). |
TO | FOR <numvar> = <number> TO <number>Separates the start and end values of a FOR loop. Both bounds are integers, since ZX80 BASIC has no fractional numbers, and there is no STEP clause. |
USRintegral function | USR(<addr>)Calls machine code at the given address and returns the value of the BC register pair on RET. |
Argument notation
Anything in <angle brackets> is a value you supply; everything else is typed exactly as shown. [square brackets] mark an optional part, | separates alternatives, and … means the part before it can repeat. The arguments on this page are:
<number>- a numeric expression
<string>- a string expression
<expr>- a value of either type, where the keyword takes both
<byte>- a value from 0 to 255
<var>- a variable of either type
<numvar>- a numeric variable
<line>- a line number
<statement>- one BASIC statement
<comment>- free text, to the end of the line
<addr>- a memory address
Showing 47 of 47 keywords