Post Reply 
User-defined functions in Free42
01-13-2021, 05:56 PM
Post: #22
RE: User-defined functions in Free42
(01-13-2021 05:19 PM)Dave Britten Wrote:  I have some stack save/restore routines on my 42S that might offer some inspiration on how to design this.

There's just one save routine:

SS - Save stack (saves the entire stack, including L)

Then there are a few different restore routines that restore the stack in various ways, called just before the program returns. The names start with R, followed by a list of what to restore to each stack register - X, Y, Z, T, L, in that order. An underscore signifies "leave it alone", i.e. that register contains an output of the program that's calling the save/restore routines.

R_YZTX - Leave X alone, restore Y, Z, T to their original positions, restore previous X into L. Similar to one-input, one-output functions like LN, or some two-input, one-output functions like %.

That corresponds to the behavior of FUNC 11.

(01-13-2021 05:19 PM)Dave Britten Wrote:  R_ZTTX - Leave X alone, restore Z to Y, T to Z and T, and X to L. Similar to two-input, one-output functions like +.

That corresponds to the behavior of FUNC 21.

(01-13-2021 05:19 PM)Dave Britten Wrote:  R_TTTX - Leave X alone, restore T into Y, Z, and T, and restore X to L. Three-input, one-output function, or a four-input, one-output function. (Are there any examples of these?)

That corresponds to the behavior of FUNC 31.

The HP-42S doesn't have any built-in functions like this, but in Free42, FMA fits that pattern.

(01-13-2021 05:19 PM)Dave Britten Wrote:  A few other examples that I could potentially implement if I needed them:

RYZTTX - A one-input, no-output function that drops the stack, and saves the previous X in L.

That corresponds to the behavior of FUNC 10.

(01-13-2021 05:19 PM)Dave Britten Wrote:  R_XYZL - A no-input, one-output function, like RCL, DATE, etc.

That corresponds to the behavior of FUNC 01.

(01-13-2021 05:19 PM)Dave Britten Wrote:  R__ZTL - A no-input, two-output function that overwrites X and Y, such as MEAN.

That almost corresponds to the behavior of FUNC 22, except for what ends up in LASTx... but note that MEAN puts the old X in LASTx, so the pattern is R__ZTX, and that does match the behavior of FUNC 22.
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: User-defined functions in Free42 - Thomas Okken - 01-13-2021 05:56 PM



User(s) browsing this thread: 1 Guest(s)