HP Forums

Full Version: HP 42s Stack Save/Restore Tool
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

After using 42s on my iPod for a while now, I was getting sick of having to code stack save/restore routines at the beginning and end of every program. So I decided to do something about it!

http://dave.brittens.org/HP42s/StackSave.html

Without repeating myself too much, there are two programs: SAVE and RESTORE. You only have to set a few options before calling either. For example, suppose I were writing a program to calculate a logarithm to any base, which uses two values from the stack and returns one. (An overly simple, contrived example, I know.) At the beginning of the program, I would do this:

"LOG"
CF 91
CF 92
XEQ "SAVE"

Then at the end of the program, these steps:

2
STO "_A"
RDown
1
STO "_O"
RDOWN
"LOG"
CF 91
XEQ "RESTORE"

The result would be the T and Z registers from before the program was run being rolled down to Z and Y, with the T register being copied as is the norm for built in functions.

There are some run-time options to control the number of arguments your program takes from the stack, the number of outputs it returns, how to deal with LAST X, and whether or not to save and restore REGS.

Anyway, try it out, see if you can break it, and hopefully my quick and dirty writeup will make a little bit of sense. :)

-Dave

Quote:
After using 42s on my iPod for a while now, I was getting sick of having to code stack save/restore routines at the beginning and end of every program. So I decided to do something about it!

The next feature to implement in the 42s is Undo and Redo. Will probably be out in time for a stocking stuffer.

However, the functionality is not the same as your program, so may not provide the same utility.

Very cool. I've always liked the Last Stack/Undo feature on the 48. It comes in quite handy when I fat-finger something during a lengthy calculation!