![]() |
WP-34S: Subroutines, local registers and hotkeys - Printable Version +- HP Forums (https://archived.hpcalc.org/museumforum) +-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html) +--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html) +--- Thread: WP-34S: Subroutines, local registers and hotkeys (/thread-248695.html) |
WP-34S: Subroutines, local registers and hotkeys - Marcel Samek - 08-23-2013 The following code snippet (taken from a context where it makes sense) works as expected when VTL is executed.
LBL'VTL' However, if it is changed that the call to subroutine A happens with a hotkey like this:
LBL'VTL'
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 - Didier Lachieze - 08-23-2013 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 - Marcel Samek - 08-23-2013 Where did you find that? I still don't see that in the manual.
Re: WP-34S: Subroutines, local registers and hotkeys - Didier Lachieze - 08-23-2013 Appendix B, section "Subroutine calls".
Re: WP-34S: Subroutines, local registers and hotkeys - Marcel Samek - 08-23-2013 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 - Marcus von Cube, Germany - 08-23-2013 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 - David Hayden - 08-23-2013 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
Re: WP-34S: Subroutines, local registers and hotkeys - Marcel Samek - 08-23-2013 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.
|