Post Reply 
HP50g: local LBL and GOTO in user or sysRPL
09-07-2016, 08:21 PM (This post was last modified: 09-07-2016 08:23 PM by 3298.)
Post: #4
RE: HP50g: local LBL and GOTO in user or sysRPL
Why wouldn't relative GOTOs in Saturn ASM work? I thought the whole point of relative jumps was that you could relocate the entire code...

Anyway, I tried the PC=A approach Han mentioned. It uses some ASM of course, and it is obviously not safe for normal UserRPL operation, so I simply used some features of the on-board SysRPL and ASM compiler (MASD).
The starting point was the existing SysRPL goto command. Yes, that's a thing already, and the ROM uses it in a few places, but because it's made for absolute jumps it's not suitable for user code unless you copy it to a fixed location.

Firstly, the compiler supplies a handy label mechanism which is practically designed for this. Syntax is "LABEL foo" according to the MASD docs.
Next: supplying the jump offset to the goto command. The easiest solution I found is to switch to ASM mode, use the apparently ASM-only G5 macro to obtain the offset, and switch back to SysRPL mode. In code this looks like: "!ASM G5 foo !RPL".
Last is the command itself. It is an ordinary code object, so you could inline it or make it a separate program, whatever you want. This is the code:
Code:
CODE
  C=DAT0.A
  AD0EX
  A+C.A
  AD0EX
  GOVLNG Loop
ENDCODE
You need to place this or a call to it directly before the offset calculation snippet.
If you know Saturn ASM you can probably see that it simply adds the next address in the runstream to the runstream pointer. There is no adjustment for the size of that taken address because the G5 macro handles that part for us (if the label is right behind the goto's offset, the G5 macro will output 5, which is the size of an address, so the address will be skipped like it should).
I did a simple test with this and it seems to work. MASD didn't like my attempts to craft a macro from this, though. Maybe someone who knows MASD better could help with that, but I'd just do it manually or add my own preprocessing step to the compilation process.

You probably know from other programming languages that it's a bad idea to jump from one code block to a different one. In RPL this can be used with care if you know how the return stack works, but I don't recommend it. It's as messy as trying to break out of a BEGIN...AGAIN, BEGIN...UNTIL, or BEGIN...WHILE...REPEAT loop early.
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 - 3298 - 09-07-2016 08:21 PM



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