In this thread, Dave Britten presented excellent prime factor finders for both the HP-20s and HP-32sii. This was also implemented on the HP-30b by Tim Wessman. Katie Wasserman pointed out that faster results will be obtained (on machines like the 30b and 32sii) by moving the most frequently-called subroutines to the top of code.

I recently acquired an HP-32s, a very beautiful machine. I wanted to implement the optimized algorithm on the 32s and reduce the label count if possible, since labels are a valuable resource on these machines. I was able to eliminate the V label (which was required because the 32s does not have a x<=y instruction like the 32sii) by reversing the order of variables M and F on the stack and using x>y, and I was able to eliminate the X label by simplifying the logic involved with displaying the final factor.

Here is the code that works on the HP-32s:

optimized prime factor program for HP-32sUsage:

num to factor

xeq f

r/s to see all factors

0 = donelbl w

rcl + f

sto f

rcl x

x<->y

/

fp

x=/=0

rtn

rcl x

rcl / f

sto x

sqrt

ip

sto m

view f

0

goto w

lbl z

4

xeq w

2

xeq w

4

xeq w

2

xeq w

4

xeq w

6

xeq w

2

xeq w

6

xeq w

rcl x

ln

x=0

rtn

rcl f

rcl m

x>y

goto z

rcl x

sto f

view f

clx

rtn

lbl f

sto x

sqrt

ip

sto m

0

sto f

2

xeq w

1

xeq w

2

xeq w

2

xeq w

rcl x

ln

x=0

rtn

goto z