Speed Up Your Programs

Author(s): Mort Butler
Publication: Syntax
Pub Details: Syntax/Syntax ZX80 v3 n1 (Volume 3, Issue 1)
Date: January 1982
Pages: 2

Most Sinclair users are new to the programming game. Many will use lines like: 350 GO TO 710

In most cases this is fine, especially in a short program. But in a long program with many GO TO statements, the computer takes a long time for each TV display.

Try this: With the Super Monzxer program (Nov.81) (as an example of a long program) in the computer, add these lines:

   3 LET A1=1
4 IF A1<100 THEN LET A1=A1+1
5 IF A1>=100 THEN STOP
6 GOTO 4

RUN and the computer will stop at line 5 in about 1 second.

Now change lines 3 to 6:

   3 GOSUB 6000                    delete line 4                   delete line 6
5 STOP
6000 LET A1=1
6001 IF A1<100 THEN LET A1=A1+1
6002 IF A1>=100 THEN RETURN
6003 GOTO 6001

RUN and the computer stops at line 5 in about 3 seconds.

The difference in run times is because the computer goes to line 1 every time it finds a GO TO statement. It compares that line number with the GO TO number and continues until they match. Then it executes as required.

To speed up execution, move the calls for actions (GOTO, GOSUB) to high line numbers. ZX80/81s can use line numbers up to 9999. The program might then have a REM statement at line 1 and then some GO SUB destinations, depending on how many groups of action statements you moved. Remember to add a RETURN statement for each GO SUB. Then comes the rest of the program. This way, most of the GO TO destinations are near line 1, the first place the computer looks for them.

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.