WP-34S: Subroutines, local registers and hotkeys



#9

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?


#10

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.


#11

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


#12

Appendix B, section "Subroutine calls".


#13

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.


#14

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.


#15

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.

#16

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  [WP-34S] Unfortunate key damage with update to V3 :( svisvanatha 5 3,255 12-10-2013, 11:37 PM
Last Post: Les Bell
  WP-34S (Emulator Program Load/Save) Barry Mead 1 1,833 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,570 12-04-2013, 11:14 AM
Last Post: Barry Mead
  Tutorials #5 (STARTAPP, RGB) and #6 (Subroutines) Are Up Eddie W. Shore 0 1,010 11-17-2013, 04:23 PM
Last Post: Eddie W. Shore
  HP Prime - local variables retain their initial type BruceH 4 1,919 11-10-2013, 12:42 PM
Last Post: Michael de Estrada
  WP 34S/43 ?'s Richard Berler 3 2,099 11-10-2013, 02:27 AM
Last Post: Walter B
  My FrankenCulator (wp-34s) FORTIN Pascal 4 2,224 11-09-2013, 06:18 PM
Last Post: FORTIN Pascal
  WP 34S Owner's Handbook Walter B 5 2,722 11-09-2013, 05:34 PM
Last Post: Harald
  wp 34s overlay and programming. FORTIN Pascal 6 2,956 11-08-2013, 01:28 PM
Last Post: Nick_S
  m.dy in display of WP-34S Harold A Climer 3 1,980 11-05-2013, 11:28 AM
Last Post: Andrew Nikitin

Forum Jump: