Free42 LSTO REGS
09-25-2019, 03:52 PM
Post: #1
 Epidiah Junior Member Posts: 1 Joined: Mar 2018
Free42 LSTO REGS
Greetings,

This is my first time posting. Generally, I've been content with just reading these forums, but I just discovered something about Free42's LSTO feature that I haven't seen mentioned anywhere and it's too exciting not to share!

This is how it started:

Code:
00 { 23-Byte Prgm } 01▸LBL "TstLSTO" 02 RCL "REGS" 03 LSTO "REGS" ...

If LSTO was used to create a local REGS, would all the commands that normally interact with REGS address that local REGS and leave the global REGS untouched?

I tried STO and RCL and their arithmetic, an assortment of STAT functions, ISG, DSE, printing the REGS, CLΣ and CLRG. I'm sure there's more, but all of these interacted with the local REGS and ignored the global one!

At the moment, I have no real need for this, but I rather like the idea that I can use the whole suite of REGS-related functions in a subroutine without worrying about their impact on previously stored data.
09-26-2019, 05:50 PM
Post: #2
 David Hayden Member Posts: 271 Joined: Dec 2013
RE: Free42 LSTO REGS
Wow that's cool!

It might also mean that if you have an old program that uses lots of registers and stores it's results on the stack, then you might be able to run it cleanly by doing LSTO "REGS" and then calling the program.
09-26-2019, 08:10 PM
Post: #3
 Guenter Schink Senior Member Posts: 316 Joined: Dec 2013
RE: Free42 LSTO REGS
(09-26-2019 05:50 PM)David Hayden Wrote:  Wow that's cool!

It might also mean that if you have an old program that uses lots of registers and stores it's results on the stack, then you might be able to run it cleanly by doing LSTO "REGS" and then calling the program.

You even can create temporary "REGS" for use in manual mode only
Code:
 01 LBL "AREGS" 02 NEWMAT 03 LSTO "REGS" 04 STOP 05 RTN

Put your desired nRows and 1 on the STACK and run AREGS. After that you'll have that new set of registers available until you hit R/S, this will invoke RTN and thus reactivate the standard REGS.

But wait a minute. Before you hit R/S you could save your "local" REGS as a normal VAR e.g. "REGS1" for later use. Then when you sometime later want to reactivate "REGS1" just recall it and LSTO it to "REGS" but then to return to the original "REGS" you have to do a RTN. GTO .. does it also.

Cool? Günter
09-28-2019, 02:53 AM
Post: #4
 Thomas Okken Senior Member Posts: 865 Joined: Feb 2014
RE: Free42 LSTO REGS
You can also use LSTO from the keyboard; it is not program-only. Like in Günter's example, you end up with a variable that will go away when you do run-mode GTO, XEQ, RTN, BST, edit a program, etc. Specifically, all local variables are deleted by the same set of actions that cause the RTN stack to be cleared on the HP-42S.
09-28-2019, 03:19 AM
Post: #5
 Thomas Okken Senior Member Posts: 865 Joined: Feb 2014
RE: Free42 LSTO REGS
To elaborate a bit: every local variable is associated with a level of the RTN stack. LSTO creates variables on the current level, and when that level is popped, the associated variables are deleted. And, any action that clears the entire RTN stack, like GTO, XEQ, or RTN in RUN mode, clears all local variables.

There is one quirk to this: LSTO can also create variables when the RTN stack is already empty. It has to be able to do this, in order to work in a subroutine that is invoked from the keyboard. Say you do XEQ "FOO" from the keyboard with this in program memory:

Code:
01 LBL "FOO" 02 LSTO "X" 03 R↓ 04 LSTO "Y" [...]

When the LSTO instructions are performed, there is nothing on the RTN stack, unlike when the XEQ "FOO" is done from a program, but of course you'd want LSTO to work even in this scenario.

When a program performs RTN while the RTN stack is empty, this causes the empty-stack locals (referred to as "level 0" in the source code, the RTN stack "level" being the number of pending returns) to be deleted, so when the program "FOO" above ends with a RTN, its locals disappear, even though they were never associated with an actual RTN. And this same mechanism can be used in RUN mode.
10-04-2019, 12:34 PM (This post was last modified: 10-04-2019 12:36 PM by Namir.)
Post: #6
 Namir Senior Member Posts: 656 Joined: Dec 2013
RE: Free42 LSTO REGS
The technique of of using local REGS is wonderful! I wrote a short test where I stored values in regular registers, called a subroutine, created a local copy of REGS, and accessed the copies. This method allows you to pass values not only in the stack, but also though numbered registers to a subroutines. The called subroutine can return the result(s) in the stack OR in gobal named variables. Using local REGS allows the subroutine to use any numbered register, that does not supply it with input values, to store whatever intermediate results needed.

Thanks Thomas for making the feature of local REGS available!

Here is my short test program:

Code:
01▸LBL "AA" 02 100 03 STO 00 04 200 05 STO 01 06 XEQ "BB" 07 "X=" 08 ARCL 00 09 PROMPT 10 RTN 11▸LBL "BB" 12 RCL "REGS" 13 LSTO "REGS" 14 1 15 STO 00 16 "XS=" 17 ARCL 00 18 PROMPT 19 "YS=" 20 ARCL 01 21 PROMPT

Namir
10-05-2019, 08:46 AM
Post: #7
 Paul Dale Senior Member Posts: 1,491 Joined: Dec 2013
RE: Free42 LSTO REGS
The 34S introduced local variables that were allocated per return stack frame (thanks Marcus). These were initially used by some of the internal keystroke programmes (XROM). They are not at the same level of sophistication that Free42 now has. I suspect that there might be some middle ground between the two but why would anyone compromise?

The most important benefit is that the two major HP calculator projects have been learning from each other,

Pauli
 « Next Oldest | Next Newest »

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