Interesting outcome of programming in Big Stack mode

Discussion around the SwissMicros DM42 calculator
Post Reply
HPMike
Posts: 439
Joined: Fri Jul 21, 2017 11:01 pm
Location: DFW, Texas

Interesting outcome of programming in Big Stack mode

Post by HPMike »

When programming in Big Stack (NSTK) mode, pressing the ENTER key results in the entry of the DUP command instead of ENTER. If you then upload the .raw file into the DM42 Programming Tool, this line will decode as XROM 31,39. At first this seems a little strange, until you realize that this is exactly how it works on RPL calculators such as the HP48s and HP50g with a dynamic stack. If you change back to 4STK mode, then ENTER appears as ENTER, and decodes as ENTER. Since I'd rather have all my programs be backwards compatible to my original HP42s, I'm now doing all my programming in 4STK made, unless I specifically want to avail myself of the NSTK commands, such as DUPN and DROPN.
DM15L, S/N 00548. DM42, SN: 00159. DM41X, SN: 00973. DM32, SN 00054.
User avatar
48GX
Posts: 180
Joined: Wed May 20, 2020 4:37 am

Re: Interesting outcome of programming in Big Stack mode

Post by 48GX »

This is the main reason I have avoided NSTACK for programming. Programs of old and the ones I have already written won't work as designed. I love the infinite stack, but I have trained myself to use RPN on the 42 and RPL on the 48.
Waiting for SM to release DM42 hardware with one additional row of keys.
DM42, DB48X, DM32, HP42s, DM41X, HP35s, DM41L
Raising a next generation RPN/RPL user.
Thomas Okken
Posts: 1100
Joined: Tue May 02, 2017 5:48 pm
Location: Netherlands
Contact:

Re: Interesting outcome of programming in Big Stack mode

Post by Thomas Okken »

I think those are two different issues. What Mike is describing is that the behavior of the ENTER key depends on the mode you are in: it performs ENTER in 4STK mode and DUP in NSTK mode, and this applies in both RUN and PRGM modes.

Once entered into a program, ENTER remains ENTER and DUP remains DUP, even when you switch between NSTK and 4STK modes.

You can keep using programs designed for the 4-level stack even if you prefer the big stack for interactive use, by putting L4STK after your programs' entry points. (There is also a request on my to-do list to designate L4STK or LNSTK as the default behavior for entire directories; that sounds like an excellent idea for legacy code, but I haven't gotten around to implementing this yet.)
User avatar
48GX
Posts: 180
Joined: Wed May 20, 2020 4:37 am

Re: Interesting outcome of programming in Big Stack mode

Post by 48GX »

Thanks for setting me straight, Thomas. This brings up an interesting note for me. What do you mean by putting L4STK after the programs' entry points? I will need a little help as I am a 48GX user. Does this mean put L4STK after the program label? That is all I have to do? Or do I have to insert that after each Label point in the program?
Waiting for SM to release DM42 hardware with one additional row of keys.
DM42, DB48X, DM32, HP42s, DM41X, HP35s, DM41L
Raising a next generation RPN/RPL user.
Thomas Okken
Posts: 1100
Joined: Tue May 02, 2017 5:48 pm
Location: Netherlands
Contact:

Re: Interesting outcome of programming in Big Stack mode

Post by Thomas Okken »

You'll need L4STK after each label that may be executed from the keyboard. That will ensure that 4STK mode is activated as soon as the program starts running. It is not necessary to put L4STK after labels that are only jumped to or executed by the program itself; 4STK mode will remain in effect until the final RTN or END.

To be precise: L4STK saves levels 5 and higher in a list in an invisible local variable, and then activates 4STK mode, truncating or padding the stack as needed to make it 4 levels. When the current subroutine level returns, by executing any of RTN, END, RTNYES, RTNNO, or RTNERR, the previous stack mode, and previous contents of levels 5 and up, are restored. If the current subroutine level is the top level, that is, if there are no pending RTNs, the program will stop at the next RTN/END/etc., but the same stack restoration will take place.

If the program stops running without returning from all subroutines, 4STK mode will remain in effect, and the stack restoration will happen whenever the final RTN/END/etc. is executed after program execution resumes.

If program execution is not resumed, and the RTN stack is cleared by user action, like performing GTO, XEQ, RTN, or BST, the saved stack mode will be restored, but not the saved stack contents.
Post Reply