The Museum of HP Calculators

HP Forum Archive 21

[ Return to Index | Top of Index ]

WP-34S: Subroutines, local registers and hotkeys
Message #1 Posted by Marcel Samek on 23 Aug 2013, 9:55 a.m.

The following code snippet (taken from a context where it makes sense) works as expected when VTL is executed.

LBL'VTL'
	LocR 24
	XEQ A
	STOP			
LBL A				
	112.21115
	R-COPY
	RTN

However, if it is changed that the call to subroutine A happens with a hotkey like this:

LBL'VTL'
	LocR 24
	PROMPT
	STOP	
LBL A				
	112.21115
	R-COPY
	RTN

then when the program VTL is run and the hotkey A is pressed, the R-COPY instruction generates an "Out of range" error. It appears that the local registers have been deleted, or hidden from A.

Should subroutine calls made with hotkeys behave the same way as regular subroutine calls, or are there differences that I am not understanding?

      
Re: WP-34S: Subroutines, local registers and hotkeys
Message #2 Posted by Didier Lachieze on 23 Aug 2013, 10:35 a.m.,
in response to message #1 by Marcel Samek

It seems that subroutine calls made with hotkeys are handled the same way as "manually [...] starting a new program with XEQ" which according to the manual "will clear the SRS and remove all local registers and flags by clearing the pointer."

Edited: 23 Aug 2013, 10:37 a.m.

            
Re: WP-34S: Subroutines, local registers and hotkeys
Message #3 Posted by Marcel Samek on 23 Aug 2013, 10:43 a.m.,
in response to message #2 by Didier Lachieze

Where did you find that? I still don't see that in the manual.

                  
Re: WP-34S: Subroutines, local registers and hotkeys
Message #4 Posted by Didier Lachieze on 23 Aug 2013, 10:45 a.m.,
in response to message #3 by Marcel Samek

Appendix B, section "Subroutine calls".

                        
Re: WP-34S: Subroutines, local registers and hotkeys
Message #5 Posted by Marcel Samek on 23 Aug 2013, 10:55 a.m.,
in response to message #4 by Didier Lachieze

Well, I think I see what you are talking about, but it doesn't actually explicitly say that a subroutine call with a hotkey is the same thing as starting a new program

It isn't really the same, because the SRS hasn't been cleared as far as the return address. The subroutines called with a hotkey can return to where it was invoked from and execution can continue...

Edited: 23 Aug 2013, 10:56 a.m.

                              
Re: WP-34S: Subroutines, local registers and hotkeys
Message #6 Posted by Marcus von Cube, Germany on 23 Aug 2013, 11:15 a.m.,
in response to message #5 by Marcel Samek

Marcel, hitting A is executed as XEQ A. Press and hold the key and you will see.

The behavior you noticed is intentional. If you want to keep the return stack, and with it the local registers, intact use R/S instead. The reasoning is that manually starting a subroutine with XEQ or a hotkey should establish the same execution context each time (except for the contents of the stack or global registers, of course). We decided to clear the subroutine stack when the user starts a routine to assure this.

As a result, a program of interactive nature that uses XEQ or hotkeys to accomplish user tasks can and should always resort to global registers to hold the context and data entered by the user. Local registers are meant for intermediate storage within a subroutine. If you need more then 100 permanent registers you're out of luck with our WP 34S.

                                    
Re: WP-34S: Subroutines, local registers and hotkeys
Message #7 Posted by Marcel Samek on 23 Aug 2013, 12:27 p.m.,
in response to message #6 by Marcus von Cube, Germany

I think that because the hotkey is tied to a subroutine called from a a program that was manually invoked and had not ended, I have been thinking of hotkeys as invoking a subroutine call within the context of that program.

I now see that that is a mistake. Using a hotkey is always equivalent invoking a new program.

                              
Re: WP-34S: Subroutines, local registers and hotkeys
Message #8 Posted by David Hayden on 23 Aug 2013, 12:08 p.m.,
in response to message #5 by Marcel Samek

In addition to what Marcus said, another advantage is that it helps ensure that you don't accidentally build up a huge set of unused local registers. E.g., XEQ VTL, press the 'A' hotkey, go have lunch, XEQ VTL again, answer the phone, XEQ VTL, etc. You really want to clear the local registers each time somehow.

An alternative would have been to clear the local registers when you return control to the keyboard, but that would make debugging them impossible.

Dave


[ Return to Index | Top of Index ]

Go back to the main exhibit hall