I would humbly like to submit my program (written for the HP29C) to find the prime factors of a given integer, or find all primes between 2 given integers. This program could be adapted to any machine with >= 98 program lines, conditional branching, and at least 6 storage registers. Note that since the 29C doesn't have flags, I have used register 0 as a pseudo flag.
Instructions:
To find prime factors of an integer...put integer in x register and GSB 9. Factors are displayed successively. R/S to see the next factor. 1 is always the final factor displayed. If given integer is prime, factors displayed will be it and 1.
To find primes between two integers, put lower integer into register 6, and upper integer into register 9, and GSB 8.
primes will display from lowest to highest. R/S to view next prime. Display will flash one zero, then 10 zeros, then 3 zeros (fix 2) when finished.
Best regards, Hal
step# mnewmonic1 lbl 9
2 0 set flag register to 0 for prime
3 sto 0 factors routine
4 x<>y
5 lbl 7
6 sto 04
7 sqrt
8 sto 05 set bail out point for finding factors
9 2
10 sto 1
11 gsb 1
12 3 manually check 2,3,5,7 for divisibility
13 sto 1
14 gsb 1
15 5
16 sto 1
17 gsb 1
18 7
19 sto 01
20 gsb 1
21 lbl 3
22 4 increment trial divisor by sequence
23 sto + 1 such that multiples of 2,3 and 5
24 gsb 1 are skipped
25 2
26 sto + 1
27 gsb 1
28 4
29 sto + 1
30 gsb 1
31 2
32 sto + 1
33 gsb 1
34 4
35 sto + 1
36 gsb 1
37 6
38 sto + 1
39 gsb 1
40 2
41 sto + 1
42 gsb 1
43 6
44 sto + 1
45 gsb 1
46 gto 3
47 lbl 1
48 rcl 5
49 rcl 1
50 x>y?
51 gto 5
52 rcl 04
53 x<>y
54 /
55 enter
56 frc
57 x=0?
58 gto 4
59 rtn
60 lbl 4
61 rcl 0
62 x<>0?
63 gto 2
64 rcl 1
65 r/s
66 roll dn
67 roll dn
68 roll dn
69 gto 7
70 lbl 5
71 rcl 4
72 r/s
73 rcl 0
74 x<>0?
75 gto 2
76 1
77 r/s
78 rtn
79 lbl 8
80 9 set flag register to non-zero for
81 sto 0 primes between integers routine
82 rcl 6
83 gto 7
84 lbl 2
85 1
86 sto + 6
87 rcl 9
88 rcl 6
89 x>y?
90 gto 6
91 gto 7
92 lbl 6
93 0
94 pause
95 fix 9
96 pause
97 fix 2
98 r/s