Primes by Trial Division - Laser 50 BASIC
20 August 2016
This benchmark exposes all kinds of warts deriving from the Laser 50's profound limitations.
- FOR..NEXT is a valid construct in this BASIC, but a version of this benchmark which uses FOR..NEXT similarly to the Applesoft reference version stops with no error after finding just 3 primes. I suspect that there is a pathological interaction between the stack and the results array owing to the extremely small memory size, but did not pursue a definite answer. Thus, the version below uses only GOTO.
- Although variable names may be longer than one character, the length of a single BASIC line is limited to 40 characters. While that isn't an issue in the final version shown below, it was at certain times while I was experimenting with ways to work around the FOR..NEXT quirk. So this version uses single character variable names even though it wasn't strictly required.
- Because the LCD displays only a single line, the machine pauses after each line of output and waits for the user to press a key. To avoid this, we send output to the printer (whether it's attached or not) using LPRINT.
10 DIM P(99) 20 C=2 30 F=0 40 LPRINT C 50 P(F)=C 60 F=F+1 70 IF F>99 THEN GOTO 160 80 C=C+1 90 I=0 100 V=C/P(I) 110 IF INT(V)=V THEN I=F+1 120 IF I>F THEN GOTO 80 130 I=I+1 140 IF I=F THEN GOTO 40 150 GOTO 100 160 END