The ZX80 Operating Manual

Sinclair ZX Spectrum
NOT SO BASIC
Nearly all digital computers (such as the ZX-80) talk to themselves in binary codes. We talk to each other in English. This means that either we have to learn binary codes, or we have to teach the computer English. Binary codes are about as difficult to learn as Chinese, but it can be done. Forty years ago you had to learn them if you wanted to use a digital computer at all.

But why should we do the work when we've got a computer to do it for us?

So we teach the computer English. There is-a snag, though. Computers, so far, aren't bright enough to learn English, something which a child of two does relatively easily. This is mainly because we have so many words and ways of saying things in English. A computer would have to learn every single one. We have to compromise. half-way between binary and English. Sometimes we compromise at a low level by using assembly codes which are more like binary than English. Sometimes we compromise at a high level by using languages such as ALGOL, PL/1, PASCAL, FORTRAN, and BASIC. These languages are much closer to English than binary. The ZX-80 uses BASIC because it is easy to learn and more than adequate for most purposes. BASIC stands for Beginner's All-purpose Symbolic Instruction Code and was devised at Dartmouth College, New Hampshire in 1964 as a simple beginners' programming language. Although it was intended just for beginners, it has since become one of the most widespread and popular high level languages. This isn't very surprising when you think about it, because even scientists and engineers prefer to concentrate on science and engineering instead of trying to talk to computers in complex and difficult languages.

Like English, BASIC has a variety of dialects, depending on which computer is being used. The ZX-80 BASIC differs from other BASIC'S in some respects. These differences are listed in the appendix "Summary of ZX-80 BASIC" at the end of this book.

As we said before, computers aren't that bright. We have to tell them exactly what to do by giving them a step-by-step list of instructions. This is called a program. Each instruction must be given in a clear and un-ambiguous way — the syntax must be right (in ZX-80 BASIC the computer will tell you if it thinks that the syntax is wrong before you can run the program. Some BASIC'S wait until you've tried to run the program before they say "nuts!"). Even if the syntax is right, the computer will be confused if you give it a badly thought out list of instruc- tions. Chapters 5 and 7 give some ideas for making sure that you're telling the computer to do the right things in the right order.

STATEMENTS AND COMMANDS

ZX-80 BASIC allows you to use 22 instructions or statements.

These are divided into several categories.

1. System commands:

NEW - Clears ZX-80 ready for a new program
RUN — Runs the current program
LIST — Lists the current program
LOAD — Loads a program from tape
SAVE — Saves a program on tape

2. Control statements:
GOTO
IF ... THEN ...
GOSUB
STOP
RETURN
FOR ... TO
NEXT
CONTINUE

These statements allow the programmer to control the order in which instructions are carried out. They are described in detail in chapters 7-10.

3. Input/output statements:

PRINT — allows computer to output data
INPUT— allows user to enter data
I/O statements provide a means for getting data into and out from BASIC programs.

4. Assignment statement:
LET ...=...
This versatile statement is used whenever an arithmetic operation is to be performed.

5. Other statements:

CLEAR — clears the stored values of variables
CLS — clears the screen
DIM — sets the size of an array
REM — indicates that what follows is a remark
RANDOMISE — sets up random number generator
POKE — allows user to talk to the computer in binary code

There are some normal BASIC statements which are not included in ZX-80 BASIC. These are:

READ
DATA
RESTORE
END
ON

Nearly everything that can be done by using these statements can be done in ZX-80 BASIC by using other statements. (The END statement is not needed at all in ZX-80 BASIC).

In a BASIC program all statements or lines are preceded by a statement number or line number which labels that particular line. Line numbers can vary between 1 and 9999. The computer carries out, or executes, statements in the order in which they are numbered. It makes life easier by always displaying programs in order of increasing statement numbers, so that the order in which the program is listed is also the order in which it would be executed.

VARIABLES

All the pieces of information stored in the computer for use in a program are labelled so that the computer can keep track of them. Each piece of information, or variable, has a name.

There are two sorts of variable:

1.   Numbers (integer variables) which can take any whole number value from —32768 to 32767 inclusive. Example: 142

2.   Strings which can be any sequence of any characters (except " ) of any length. Example: "AROUND THE WORLD IN 80 DAYS"

Integer variables have names which must always start with a letter and only contain letters and digits.

Integer variable names can be any length, so if you wish the name could be a mnemonic for the variable.

Some allowable variable names for integer variables are:

A    A2    AB    AB3    ANSWER    A4X    Y   Y8    YZ     YZ9    FREDBLOGS (N.B. no space)    AAAA    Z123ABC    QTOTAL

Some illegal names are:

44    4AD    (name must start with a letter)
FRED BLOGGS   (space not allowed)
A.B   (other characters not allowed)
FRED-BLOGGS    (not a variable, but two variables, one subtracted from the other)

String variables have names of the form: letter $

The dollar sign tells you (and the computer) that the variable is a string variable.

Because only one letter is allowed, this means that you can only have up to 26 string variables in a program.

Some allowable names for string variables: A$    P$    X$

Some illegal names:

2$ (name must start with letter)
A2$ (too many characters)
AC$ (too many characters)

All this may seem a little daunting at first. The good news is that, like so many things, it's easier than it sounds.

Sinclair ZX Spectrum

  Previous Page Back Next Page