# hp 41cx

 the 41cx was the last generation hp-41c and came out in 1983. it had many of the expandable features of the 41c built in but still retained the four expansion ports for even more expansion and peripheral connection. this model had 319 registers' worth of memory (compared to 63 on the original 41c) and also the time module built in. the time module added a real-time clock, stopwatch and calendar that continued to operate whilst off.

## example program: list prime numbers

 LBL "PRIMES" 5 LBL 00 STO 00 9 + 6 / STO 02 RCL 00 SQRT 3 STO 03 / INT 1 + 3 * STO 01 XEQ 04 RCL 00 2 + STO 00 9 + 6 / STO 02 1 STO 03 RCL 00 SQRT ENTER^ INT STO 01 RDN XEQ 02 RCL 00 4 + GTO 00 LBL 01 RCL 01 RCL 01 * RCL 00 - SQRT LBL 02 FRC X=0? GTO 03 LBL 04 RCL 03 ST+ 01 RCL 02 RCL 01 X<=Y? GTO 01 RCL 00 VIEW X LBL 03 END

## example program: Deep Pi

this program calculates the digits of π. it is based on the algorithms of Simon Plouffe and Xavier Gourdon. see the papers nthdigit.pdf and nthdecimaldigit.pdf

 the program calculates 5 digits at a time. enter decimal place of the start digit and XEQ "DPI" for example, 1 XEQ "DPI" will give 14159. press R/S for the next 5 digits and so on. here is another example, 999 XEQ "DPI" will compute the 1000'th to 1005'th digits of π (accounting for the 3 at the start). the eventual answer is: 89380 LBL "DPI" STO 22 LBL 25 XEQ 24 1e5 * INT STOP 5 ST+ 22 RCL 22 GTO 25 LBL 24 STO 17 20 + .8847 * INT STO 16 3 * LN 2 LN / INT RCL 16 + RCL 17 - STO 12 0 STO 13 RCL 12 X<=0? GTO 09 2 RCL 12 Y^X STO 8 2 RCL 12 1 + 2 / INT Y^X STO 9 0 STO 11 1 STO 10 STO 7 STO 15 RCL 17 CHS STO 6 LBL 10 1 CHS STO 1 RCL 15 STO 0 XEQ 11 RCL 0 RCL 15 2 * 1 - * RCL 7 XEQ 18 STO 7 1 STO 1 RCL 15 9 * 3 - STO 0 XEQ 11 RCL 0 RCL 10 XEQ 18 STO 10 1 STO 1 RCL 15 3 * 2 - STO 0 XEQ 11 RCL 0 RCL 10 XEQ 18 STO 10 RCL 6 X<=0? GTO 12 RCL 8 RCL 10 XEQ 19 RCL 7 XEQ 18 2 RCL 12 RCL 6 - Y^X RCL 15 25 * 3 - * XEQ 18 RCL 11 + RCL 8 MOD STO 11 LBL 12 1 ST+ 15 RCL 16 RCL 15 X<=Y? GTO 10 RCL 17 1 - 5 XEQ 21 RCL 11 XEQ 18 RCL 8 / STO 13 LBL 09 3 STO 14 LBL 13 RCL 14 RCL 16 3 * LN RCL 14 LN / INT STO 12 Y^X STO 8 RCL 17 2 XEQ 20 STO 7 0 STO 11 STO 6 STO 18 1 STO 10 STO 15 CHS STO 19 2 CHS STO 21 3 CHS STO 20 LBL 14 RCL 15 2 ST+ 18 * STO 0 18 STO 5 1 CHS STO 9 XEQ 15 RCL 0 RCL 7 * RCL 8 MOD STO 7 RCL 15 2 ST+ 19 * 1 ST+ 5 - STO 0 XEQ 15 RCL 0 RCL 7 * RCL 8 MOD STO 7 RCL 15 9 ST+ 20 * 3 - STO 0 1 STO 9 ST+ 5 XEQ 15 RCL 0 RCL 10 * RCL 8 MOD STO 10 RCL 15 3 ST+ 21 * 2 - STO 0 1 ST+ 5 XEQ 15 RCL 0 2 * RCL 10 * RCL 8 MOD STO 10 RCL 6 X<=0? GTO 17 RCL 12 RCL 6 - RCL 14 XEQ 20 RCL 15 25 * 3 - * RCL 8 MOD STO 9 RCL 8 RCL 10 XEQ 19 RCL 7 * RCL 8 MOD RCL 9 * RCL 8 MOD RCL 11 + RCL 8 MOD STO 11 LBL 17 1 ST+ 15 RCL 16 RCL 15 X<=Y? GTO 14 RCL 17 1 - 5 XEQ 20 RCL 11 * RCL 8 MOD RCL 8 / RCL 13 + FRC STO 13 RCL 14 XEQ 23 STO 14 RCL 16 3 * X<>Y X<=Y? GTO 13 RCL 13 RTN LBL 15 RCL IND 5 RCL 14 X>Y? RTN MOD STO IND 5 X<>0? RTN LBL 16 RCL 14 ST/ 0 RCL 9 ST+ 6 RCL 0 RCL 14 MOD X=0? GTO 16 RTN LBL 11 RCL 0 2 MOD X<>0? RTN 2 ST/ 0 RCL 1 ST+ 6 GTO 11 LBL 18 ENTER ENTER RCL 9 / INT STO 0 RCL 9 * - STO 1 X<>Y ENTER ENTER RCL 9 / INT ST* 1 RCL 9 * - ST* 0 * RCL 0 RCL 1 + RCL 9 MOD RCL 9 * + RCL 8 MOD RTN LBL 19 STO 0 RDN STO 1 STO 5 1 STO 2 0 STO 3 LBL 00 RCL 3 RCL 1 RCL 0 / INT STO 4 RCL 2 STO 3 * - STO 2 RCL 0 RCL 1 RCL 4 RCL 0 STO 1 * - STO 0 X<>0? GTO 00 RCL 3 RCL 5 MOD RTN LBL 20 STO 0 X<>Y STO 1 1 STO 2 LBL 01 RCL 1 RCL 1 2 / INT STO 1 2 * - X=0? GTO 02 RCL 0 RCL 2 * RCL 8 MOD STO 2 LBL 02 RCL 1 X=0? GTO 03 RCL 0 RCL 0 * RCL 8 MOD STO 0 GTO 01 LBL 03 RCL 2 RTN LBL 21 STO 2 X<>Y STO 3 1 STO 4 LBL 04 RCL 3 RCL 3 2 / INT STO 3 2 * - X=0? GTO 05 RCL 2 RCL 4 XEQ 18 STO 4 LBL 05 RCL 3 X=0? GTO 06 RCL 2 RCL 2 XEQ 18 STO 2 GTO 04 LBL 06 RCL 4 RTN LBL 23 STO 2 LBL 08 2 ST+ 2 RCL 2 SQRT STO 0 3 STO 1 LBL 07 RCL 2 RCL 1 MOD X=0? GTO 08 RCL 0 RCL 1 2 + STO 1 X<=Y? GTO 07 RCL 2 RTN END

the syntax of the listing is compatible with the V41 emulator. here is a text file and here is the raw (binary) file.

unfortunately, in running tests it gets very slow quickly. i was hoping it might be good to leave it running with a printer for, say, 24 hours, but in that time it barely calculates a few hundred digits. i developed the program by taking some C code written by Fabrice Bellard and hacked it mercilessly for calculators. the hacking involved unrolling the case of a=2 since this is the only case that can overflow 10 digits, and required a specialised subroutine.

here is my hacked version of pi3.c if you want to attack it.