Alpha stack on the HP-41C and HP-42S
A while back, another member of the MoHPC forum mentioned a program he'd written for the HP-41C that allows the user to manage multiple alpha registers. I responded saying that I had written something similar many moons ago that behaved like a LIFO (last-in-first-out) stack rather than an indexed array of datasets and said that I'd look it up.
I have no idea whatsoever what I did with my little utility so I decided to rewrite it, purely and simply. So here it is.
NB: This program creates and manages a data file in Extended Memory called "ASTACK". If you already have a file of that name, it will be deleted! Note also that running these programs uses Flag 01 and trashes registers R07-R10. Finally, since this uses Extended Memory, you will need to run this on a 41CX or SwissMicros DM41, or on a 41C or 41CV with the "X-Function" module.
The size of the data file created in Extended Memory depends on the depth of the alpha stack that you want to create. Two registers are needed for a header in the file and four registers per stack level are needed. So, if you want a stack that's 6 levels deep, for example, then you'll need room in your Extended Memory for a file that's 2+6*4= 26 registers in size. You'll actually need 28 registers free because the calculator also steals 2 registers for its own internal housekeeping when you create a file in X-Mem.
The three utilities provided are "ASINIT", "APUSH" and "APOP".
ASINIT
Run this with the depth of the desired stack in X, The '41's own error detection will prevent you from creating a file that's too big or from running this on a machine with no "X-Function" module installed (remember, the 41CX and the DM41 have this module baked into their ROM).
APUSH
This will save the current contents of your alpha register onto the alpha stack and return 0 in X, unless the stack is already full, in which case you'll get -3 back instead. If the alpha stack hasn't been initialized (by running ASINIT) then you'll get -1 back in X.
APOP
This takes the string on the top of the alpha stack and transfers it into the '41's alpha register, removing it from the stack. If all went well, X will contain 0 after returning from this program. If the alpha stack has not yet been initialized then you'll get -1 back, or if the stack was already empty (everything already popped off it) when you called APOP then you'll get -2 back.
You can go and grab these utilities here: alpha-stack.zip
Software provided, as usual, as a text listing, a .raw file and a PDF with bar codes.
Edit: I wrote something similar for HP-42S/DM42. This machine has no Extended Memory but can store register data into a matrix. That's exactly what we do with this version.
Grab the listing here: astack.txt and the .raw file for DM42/Free42 here: astack.raw
Listing reproduced here:
00 { 196-Byte Prgm } 01▸LBL "ASINIT" 02 ABS 03 IP 04 STO ST Y 05 8 06 × 07 2 08 + 09 1 10 NEWMAT 11 STO "ASTACK" 12 CLX 13 R↓ 14 INDEX "ASTACK" 15 STOEL 16 RTN 17▸LBL 10 18 CLX 19 SF 25 20 INDEX "ASTACK" 21 FC?C 25 22 -1 23 RTN 24▸LBL "APOP" 25 XEQ 10 26 X≠0? 27 RTN 28 RCLEL 29 I+ 30 RCLEL 31 X≠0? 32 GTO 01 33 -2 34 RTN 35▸LBL 01 36 8 37 × 38 5 39 - 40 1 41 STOIJ 42 CLA 43 8 44▸LBL 11 45 RCLEL 46 I+ 47 ARCL ST X 48 R↓ 49 DSE ST X 50 GTO 11 51 FS?C 01 52 GTO 04 53 2 54 1 55 STOIJ 56 RCLEL 57 1 58 - 59 STOEL 60▸LBL 04 61 CLST 62 RTN 63▸LBL "APUSH" 64 XEQ 10 65 X≠0? 66 RTN 67 RCLEL 68 I+ 69 RCLEL 70 X=Y? 71 GTO 02 72 1 73 + 74 STOEL 75 8 76 × 77 5 78 - 79 1 80 STOIJ 81 8 82 R↑ 83▸LBL 09 84 ASTO ST X 85 STOEL 86 I+ 87 ASHF 88 DSE ST Y 89 GTO 09 90 SF 01 91 GTO "APOP" 92 END