The following program (64 bytes) will find the number of registers in nine lookup. (160, 80, 40, 20, 10, 5, 3, 2, 1)
Code:
01 LBL "SIZE?" // Entry Point
02 SF 25 // Start with substraction
03 0 // Register index
04 320 // Register offset (startup value, max number of registers)
05 LBL 00 // Loop
06 2 //
07 / // Divide register offset by 2
08 .5 //
09 + // Add .5 for odd divisions
10 INT // Get interger part
11 FS? 25 // If last memory access was valid
12 + // Add register offset to register index
13 FC? 25 // If last memory access was invalid
14 - // Substract register offset from register index
15 LASTX // Get back register offset
16 SF 25 // Ignore next error
17 RCL IND Y // Memory access request
18 FS? 25 // If successful
19 RDN // Drop unneeded recalled value
20 1 // Exit loop condition
21 X=Y? //
22 GTO 01 // leave loop if the offset is 1
23 RDN // Drop exit loop test value
24 GTO 00 // Loop for next iteration
25 LBL 01 // Almost done
26 RDN // Drop exit loop test value
27 RDN // Drop register offset
28 SF 25 // Ignore next error
29 RCL IND X // Memory access request
30 FC? 25 // If last memory access was invalid
31 GTO 02 // Odd number of registers allocated, no compensation needed
32 RDN // Drop unneeded recalled value
33 1 // Even number of registers allocated, compensation needed
34 + // Compensate the value found by 1
35 LBL 02 // Compensation terminated
36 X<0? // If the number is negative, thene there was no data register allocated
37 0 // 0 for no data registers
38 END // The number of registers has been found
On a unmodified HP-41CX Halfnut, the program consistently runs in 5.7 seconds.
Measured with the stopwatch
Insert after LBL "SIZE?" -> 0, SETSW, RUNSW
Insert before END -> STOPSW, RCLSW, X<>Y
Have fun!
Sylvain
Edit: add run time