WP-34S: Subroutines, local registers and hotkeys


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

LocR 24

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

LocR 24

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?


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.


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


Appendix B, section "Subroutine calls".


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.


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.


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.


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.


Possibly Related Threads…
Thread Author Replies Views Last Post
  [WP-34S] Unfortunate key damage with update to V3 :( svisvanatha 5 3,202 12-10-2013, 11:37 PM
Last Post: Les Bell
  WP-34S (Emulator Program Load/Save) Barry Mead 1 1,807 12-09-2013, 05:29 PM
Last Post: Marcus von Cube, Germany
  DIY HP 30b WP 34s serial flash/programming cable Richard Wahl 2 2,533 12-04-2013, 11:14 AM
Last Post: Barry Mead
  Tutorials #5 (STARTAPP, RGB) and #6 (Subroutines) Are Up Eddie W. Shore 0 990 11-17-2013, 04:23 PM
Last Post: Eddie W. Shore
  HP Prime - local variables retain their initial type BruceH 4 1,869 11-10-2013, 12:42 PM
Last Post: Michael de Estrada
  WP 34S/43 ?'s Richard Berler 3 2,066 11-10-2013, 02:27 AM
Last Post: Walter B
  My FrankenCulator (wp-34s) FORTIN Pascal 4 2,164 11-09-2013, 06:18 PM
Last Post: FORTIN Pascal
  WP 34S Owner's Handbook Walter B 5 2,683 11-09-2013, 05:34 PM
Last Post: Harald
  wp 34s overlay and programming. FORTIN Pascal 6 2,909 11-08-2013, 01:28 PM
Last Post: Nick_S
  m.dy in display of WP-34S Harold A Climer 3 1,952 11-05-2013, 11:28 AM
Last Post: Andrew Nikitin

Forum Jump: