Thanks for those conversions! BBC Basic does allow GOTO <Variable> so I'd hoped to be able to emulate the behaviour of !. It should be possible, but I didn't get it working.
I made some small changes to both your conversions, to convert to BBC Basic, and then in one case to convert to integer variables - as Klaus says, they have the advantage of being integers, and in the case of single-letter variables the advantage of being placed in fixed locations known to the interpreter.
Klaus' EhBASIC version needs a tweak or two:
Code:
400 PRINT;N;" ";:X=X-1
1220 X=1000:REM NUMBER OF PRIMES
and then takes 153s on a BBC Master (2 MHz)
Mike's Integer Basic version needs a tweak or two:
Code:
400 PRINT;" ";N;:X=X-1
430 IF X<>0 THEN RETURN
1220 X=1000: REM NUMBER OF PRIMES
and then takes 125s on a BBC Master (2 MHz)
After further conversion of this version to integer variables, it takes 93s on a BBC Master (2 MHz)
That version reads as:
Code:
10 GOTO 1000
100 N%=N%+2: GOSUB 200
120 N%=N%+4: GOSUB 200: GOTO 100
200 IF N%<25 THEN 400
210 IF N%<U% THEN 300
230 V%=V%+2:U%=V%*V%
300 D%=5
310 IF N% MOD D%=0 THEN RETURN
330 D%=D%+2: IF D%>=V% THEN 400
350 IF N% MOD D%=0 THEN RETURN
370 D%=D%+4: IF D%<V% THEN 310
400 PRINT ;" ";N%;:X%=X%-1
430 IF X%<>0 THEN RETURN
440 END
1000 V%=5:U%=25
1220 X%=1000: REM NUMBER OF PRIMES
1230 N%=2: GOSUB 200
1240 N%=3: GOSUB 200
1250 N%=5: GOSUB 200
1260 GOTO 100
I further converted the constant integers and constant line numbers to variables, but it slowed down slightly to 96s. So instead I stripped spaces and removed some comparisons to zero, and got it down to a tad under 89s. It's less readable:
Code:
10GOTO1000
100N%=N%+2:GOSUB200:N%=N%+4:GOSUB200:GOTO100
200IFN%<25THEN400
210IFN%<U%THEN300
230V%=V%+2:U%=V%*V%
300D%=5
310IFN%MODD%:ELSERETURN
330D%=D%+2:IFD%>=V%THEN400
350IFN%MODD%:ELSERETURN
370D%=D%+4:IFD%<V%THEN310
400PRINT;" ";N%;:X%=X%-1
430IFX%RETURN
440END
1000V%=5:U%=25
1220X%=1000: REM NUMBER OF PRIMES
1230N%=2: GOSUB 200
1240N%=3: GOSUB 200
1250N%=5: GOSUB 200
1260GOTO 100