Post Reply 
Free42 with big stack, test version
01-30-2021, 01:18 AM
Post: #1
Free42 with big stack, test version
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.
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Free42 with big stack, test version - Thomas Okken - 01-30-2021 01:18 AM



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