diff --git a/src/rz/factor.27 b/src/rz/factor.28 similarity index 90% rename from src/rz/factor.27 rename to src/rz/factor.28 index e5837d5e..5b43c9e7 100644 --- a/src/rz/factor.27 +++ b/src/rz/factor.28 @@ -20,15 +20,20 @@ INFOC==3 PDLL==100 +;The inner loop of the trial division code. + +;On pre-KL10 machines, it's faster to run from the ACs. IFE KL10, LOC 7 -;This is the inner loop of the trial division code. +;On the KL10, we can't TRC/HRRI the ADDI at 101, but we have a free AC instead. +IFN KL10, INCR=11 + ;CD is the number being tested. DV is the candidate factor. -;The TRC/ADDI self-modifying code means that it alternates between -;adding 2 and 4 to DV on each iteration, so the factors it tries are -;5, 7, 11, 13, 17, 19, 23, 25... i.e. it skips multiples of 2 and 3. -;(See for more about this sequence.) -TEST: TRC INCR,6 ;Complement the 2 and 4 bits in ADDI below -INCR: ADDI DV,2 ;Next candidate; modified by TEST/NO3 +;The TRC means that it alternates between adding 2 and 4 to DV on each +;iteration, so the factors it tries are 5, 7, 11, 13, 17, 19, 23, 25... +;i.e. it skips multiples of 2 and 3. (See .) +TEST: TRC INCR,6 ;Complement the 2 and 4 bits in the step size +IFE KL10,INCR: ADDI DV,2 ;Next candidate; modified by TEST/NO3 +IFN KL10, ADD DV,INCR ;Next candidate RETEST: MOVE Z,C MOVE B,D IDIV Z,DV ;Z := Z div DV; A := Z mod DV @@ -36,11 +41,12 @@ RETEST: MOVE Z,C CAMLE DV,A JUMPE Z,PRIME ;No more factors to try, so CD is prime JUMPN B,TEST ;Not divisible by E; try the next candidate -;That's the end of the registers; the instruction below is at 20. +;If we started at 7, the instruction below is at 20 (after the ACs). JRST FOUND ;Found a factor (but CD may still be composite) -;Entry point IFE KL10, LOC 100 + +;Entry point GO: MOVE P,[-PDLL,,PDL] .OPEN TYIC,[.UAI,,'TTY] JRST KILL