Post Reply 
HP50g: local LBL and GOTO in user or sysRPL
09-09-2016, 02:34 AM (This post was last modified: 09-12-2016 04:24 PM by DavidM.)
Post: #10
RE: HP50g: local LBL and GOTO in user or sysRPL
My curiosity got the better of me and I spent a little more time on this trying a few things. Cyrille's post provided a big clue that took me a while to understand due to the multiple interpretations of the "RPL" statement in his sample code. While I initially thought that it was a compiler directive indicating to switch compilation modes (which didn't make sense to me), I ultimately realized it was the shortcut for the standard "LOOP" phrase that triggers the next RPL object execution:
Code:
   A=DAT0 A
   D0=D0+ 5
   PC=(A)

At that point things fell into place nicely and it became clear how to proceed. Reminder: everything below is source code applicable to Debug4x; if you use the on-board compiler, the syntax would be different (though similar).

To make things slightly more readable, I cooked up this macro to assist with the GOTO step:
Code:
ASSEMBLE
MyGOTO MACRO
   CON(5) =DOCODE
   REL(5) LBL_END_$0
   A=PC
jmp$0
   LC(5) ($1)-(jmp$0)
   A+C A
   D0=A
   GOVLNG =Loop
LBL_END_$0
MyGOTO ENDM
RPL

This removes some of the clutter in the final code segment. The macro call still has to be bracketed by "ASSEMBLE" and "RPL" tokens, and unfortunately they need to be on separate lines. Hence the 3-line invocation for each GOTO.

With that, I present (in all its spaghetti-code glory) a working example of a code segment that jumps around to arbitrary labels:
Code:
::
   ASSEMBLE
      MyGOTO lbl_A
   RPL

LABEL lbl_EXIT
   "all done!"
[;]

LABEL lbl_B
   "second line"

   ASSEMBLE
      MyGOTO lbl_C
   RPL

   "skip this"

LABEL lbl_C
   "third line"

   ASSEMBLE
      MyGOTO lbl_EXIT
   RPL

LABEL lbl_A
   "first line"

   ASSEMBLE
      MyGOTO lbl_B
   RPL

   "skip this, too!"
;

The above code object leaves this on the stack at exit:
Code:
"first line"
"second line"
"third line"
"all done!"

Hope this helps.

EDIT: changed the "exit" SEMI to "[;]", which is a better way to generate the appropriate code without RPLCOMP ditching the rest of the program due to its tracking of code blocks. Also shortened the Saturn code by jumping to Loop instead of executing directly.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: HP50g: local LBL and GOTO in user or sysRPL - DavidM - 09-09-2016 02:34 AM



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