EasyManuals Logo

Sinclair ZX81 User Manual

Sinclair ZX81
92 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #23 background imageLoading...
Page #23 background image
Chapter 9 - More computer programming
Type
NEW
This will erase any old programs & variables in the ZX81. (This is rather like
CLEAR
, but
CLEAR
only
erases the variables.) Now carefully type in this program:
10
REM
THIS PROGRAM EXTRACTS SQUARE ROOTS
20
INPUT
A
30
PRINT
A,SQR A
40
GOTO
20
(You will need to type in most of the spaces yourself in line 10).
Now run it. Apparently the screen goes blank, & nothing happenss, but look at the cursor in the bottom
left-hand corner: where you might have expected a there is instead an - the machine has gone into
input mode. This is the effect of the
INPUT
statement in line 20. The machine is waiting for you to type in a
number (or even an expression), & it won't carry on until you have. After that, it will have the effect of
20
LET
A=... whatever you typed
Just a minute though, what happened to line 10? It looks as though the computer has completely
ignored it. Well, it has.
REM
in line 10 stands for remark, or reminder, & there solely to remind you of what
the program does. A
REM
statement consists of
REM
followed by anything you like, & the computer will
ignore it.
All right, so we're in input mode for line 20. Type some number, 4, say, & then
NEWLINE
. The 4 & its
square root appear on the screen, & you might think that was that. But, no - it seems to want another
number. This is because of line 40,
GOTO
20, which means exactly what it says. Instead of running out of
program & stopping, the computer jumps back to line 20 & starts again. So, type another number (2, say;
at any rate you had better make it positive).
After a few more of these you might be wondering if the machine will ever get bored with this game; it
won't. Next time in its instability it asks for another number, type
STOP
(shifted A) instead; it will take the
hint. The computer reports back with report D/20 - look up D in the list of reports (appendix B). 20 is the
line where it was waiting for some input when you stopped it.
Have you suddenly remembered some more numbers that you wanted the square root of? Then type
CONT
(short for CONTINUE) & the computer will clear the screen & ask you for another number.
For
CONT
, the computer remembers the line number in the last report that it sent you that had a code
other than 0, & jumps to that line. Since the last report was D/20 (& D is not 0), in our case
CONT
is
identical to
GOTO
20.
Now type in numbers until the screen starts getting full. When it is full, the computer will stop with the
report 5/30. 5 means 'screen full', & 30 is the number of the
PRINT
statement it was trying to execute when
it discovered there was no room. Again,
CONT
will clear the screen & carry on - this time,
CONT
means
GOTO
30.
Note that the screen is cleared not because this is a
CONT
statement, but because it is a command. All
commands (except
COPY
, which appears in chapter 20) clear the screen first.
When you're tired of this, stop the program using
STOP
& get the listing by pressing
NEWLINE
.
Look at the
PRINT
statement on line 30. Each time the pair of numbers A &
SQR
A is printed, it is on a
new line, & this is because the
PRINT
statement does not end with a comma or semicolon. Whenever this
is the case, then the next
PRINT
statement starts printing on a new line. (Thus to put in a blank line, use a
PRINT
statement in which there is nothing to be printed - just
PRINT
on its own.)
However, a PRINT statement can end in a comma or semicolon, & then the next
PRINT
statement
carries on printing as though the two had been one long statement.

Other manuals for Sinclair ZX81

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Sinclair ZX81 and is the answer not in the manual?

Sinclair ZX81 Specifications

General IconGeneral
ProcessorZilog Z80A
Processor Speed3.25 MHz
ROM8 KB
InputMembrane keyboard
StorageCassette tape
Power Supply9V DC
Dimensions167 mm x 40 mm x 175 mm
Release Year1981
ManufacturerSinclair Research
Weight350 g
Operating SystemSinclair BASIC
RAM1 KB
PortsTV out, expansion port
DisplayTelevision (RF modulator output)

Related product manuals