|HP 42s Stack Save/Restore Tool|
Message #1 Posted by Dave Britten on 16 Nov 2009, 1:51 p.m.
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!
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:
Then at the end of the program, these steps:
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. :)