Post Reply 
Free42 with big stack, test version
03-10-2021, 08:18 AM
Post: #65
RE: Free42 with big stack, test version
(01-30-2021 01:18 AM)Thomas Okken Wrote:  I finished implementing the big stack logic in Free42. This isn't an official release; depending on the feedback I get, additions and changes to the instruction set are still possible. But I think this is useful enough as it is to share it around. Comments welcome!

https://thomasokken.com/free42/download/...indows.zip

I made some changes to the FCN catalog: because the number of additional functions in Free42, compared to the HP-42S, keeps getting larger, the FCN catalog became more and more messy. Because what to do: keep it strictly alphabetic, or group the new functions logically, but if the latter, how is that grouping obvious? So I split off the extensions into sections of their own, which are in a new row at the top level of the CATALOG menu.

The new functions in the STK section are:

NSTK N-level Stack. Turns on big stack mode.

4STK 4-level Stack. Turns off big stack mode, returning to the TZYX stack.

LNSTK and L4STK Local N-level / 4-level Stack. These switch to N-level or 4-level stack mode, respectively, but in addition, they automatically restore the previous stack mode when the current function returns. Further, L4STK saves levels 5 and up in a hidden list, and also restores them when the previous stack mode is restored. (The non-local 4STK function simply discards levels 5 and up.)

All of these functions are no-ops when the selected stack mode is already active.

DEPTH Returns the current stack depth.

DROP and DROPN n Drops level 1, or levels 1..n. In 4-level mode, the stack is replenished with zeroes from the top.

DUP and DUPN n Duplicates level 1, or levels 1..n. In 4-level mode, n must be 2 or less.

R↓N n and R↑N n Rolls levels 1..n down or up. Note that the standard R↓ and R↑ are equivalent to R↓N depth and R↑N depth.

PICK n and UNPICK n Gets the object from level n, or puts an object into level n. Note that UNPICK consumes the contents of level 1, unlike STO, and n refers to the stack level number after X has been dropped. The effect is that you can modify an object at level n by doing PICK n, <modify the object>, UNPICK n, without having to add 1 to the level number for UNPICK. Also note that this is similar to the behavior of PICK and UNPICK in RPL.

Here's a fairly useless but hopefully enlightening example:

Code:
00 { 31-Byte Prgm }
01▸LBL "FAC"
02 LNSTK
03 DUP
04 1
05 X<Y?
06 GTO 00
07 R↓N 3
08 DROPN 2
09 RTN
10▸LBL 00
11 -
12 XEQ "FAC"
13 ×
14 END

This uses the big stack to implement the factorial recursively, and because of how it uses LNSTK, you can call it even if you're in 4-level mode.

Although not shown here, the big stack is compatible with FUNC as well. Further, it is possible to combine FUNC and LNSTK or L4STK in one function; the only restriction is that FUNC must be called before LNSTK / L4STK.

Hi Thomas.
I found one minor improvement, at least to me.
As the big stack does not "purge" automatically old objects, in real life use the stack may became very deep.
In RPL models i use a lot the CLEAR function (on the 50g is Orange_Sht+bksp) to periodically purge the stack.
In Free42 the CLST command is buried in CLEAR menu and need a lot of keystrokes to be reached.
At present i mad a workaround by mean of custom menu.
In would be nice to have CLST mapped somewhere in the keyboard.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Free42 with big stack, test version - Marco Polo - 03-10-2021 08:18 AM



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