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 #41 background imageLoading...
Page #41 background image
1060
LET
S=
INT
(D/12)
1070
LET
D=(D-12*S)*E
1080
LET
L=
INT
(S/20)*E
1090
LET
S=S*E-20*L
1100
RETURN
On its own, this is not much use because there is no program to set up L, S & d beforehand, nor to do
anything with them afterwards. Type in the main program, & also another subroutine to print out L, S & D.
10
INPUT
L
20
INPUT
S
30
INPUT
D
40
GOSUB
2000
45
REM
PRINT THE VALUES
50
PRINT
60
PRINT
" = ";
70
GOSUB
1000
75
REM
THE ADJUSTMENT
80
GOSUB
2000
85
REM
PRINT THE VALUES
90
PRINT
100
GOTO
10
2000
REM
SUBROUTINE TO PRINT L,S AND D
2010
PRINT
"£";L;"..";S;"S..";D;"D";
2020
RETURN
(Recall from chapter 9 that the empty
PRINT
statement in line 50 prints a black line.)
Clearly we have saved on program by using the printing subroutine at 2000, & this in itself is a very
common use for subroutines: to storten programs. However, the adjustment subroutine in fact makes the
program longer - by a
GOSUB
& a
RETURN
; so program length is not the only consideration. Used with
skill, subroutines can make programs easier to understand for the ones that matter, humans.
The main program is simplified by its using more powerful statements: each
GOSUB
represents some
complicated BASIC, but you can forget that - only the net result matters. Because of this, it is much easier
to grasp the main structure of the program.
The subroutines, on the other hand, are simplified for a very different reason, namely that they are
shorter. They still use the same old plodding
LET
&
PRINT
statements, but they only have to do a part of
the whole jub & so are easier to write.
The skill lies in choosing the level - or levels - at which to write the subroutines. They must be big
enough to have a significant impact on the main program, yet small enough to be significantly easier to
write than a complete program without subroutines. These examples (not
recommended) illustrate this.
First,
10
GOSUB
1000
20
GOTO
10
1000
INPUT
L
1010
INPUT
S
1020
INPUT
D
1030
PRINT
" ";L;"..";S;"S..";D;"D";
TAB
8;"=";
1040
LET
D=240*L+12*S+D
: :
: :
2000
RETURN
& second
10
GOSUB
1010
20
GOSUB
1020

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