A 31-byte machine-code routine for the ZX80 (4K ROM) that adds up the bytes of the BASIC program in memory and returns the total, the Syntactic Sum that Syntax printed under its listings so readers could find typing mistakes. Program 1 lowers the top of memory (a technique credited to David Ornstein of Sinclair Research) to protect the routine from BASIC; Program 2 INPUTs the 31 decimal bytes into an array and POKEs them into the protected area. You then type PRINT USR(17376) on a 1K machine.
Line 20 of Program 1 is printed as POKE 17153,M-(M/256), not M-(M/256)*256. The ZX80 keeps only the low byte, so it still works but reserves 100 bytes instead of 32.
The download has both programs: load and RUN Program 1, then LOAD Program 2 and type GO TO 6 (not RUN, which would clear the array holding the bytes). Program 2 is saved the way the article tells you to save it, with lines 1-5 deleted and the 31 bytes already in its array, so there is nothing to type in. The programs are set for a 1K ZX80; with more memory, change line 6 in both as the article explains.
Published in Syntax February 1981 (Syntactic Sums).
Source Code
PROGRAM 1
6 LET M=1024
7 LET M=M+16351
10 POKE 17152,33
20 POKE 17153,M-(M/256)
30 POKE 17154,M/256
40 POKE 17155,195
50 POKE 17156,107
60 POKE 17157,2
70 LET X=USR(17152)
PROGRAM 2
1 DIM P(31)
2 FOR L=1 TO 31
3 INPUT P(L)
4 NEXT L
5 STOP
6 LET M=1024
7 FOR L=M+16352 TO M+16382
8 POKE L,P(L-M-16351)
9 NEXT L
DECIMAL LISTING
33 40 64 237 91 8 64 221
33 0 0 124 186 32 8 125
187 32 4 221 229 225 201 78
6 0 221 9 35 24 236Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
