I was looking at the
Caves game for HP-41, there I see some I do not understand fully.
http://www.hpmuseum.org/software/41td/caves.htm
These lines:
Code:
318 LBL 33
319 AVIEW
320 PSE
321 RTN
are used multiple times.
I do understand how to works when you call it using
XEQ commands like this:
it will return and run
130 RCL 73 after its run the subroutine.
But In the
Caves there are several calls to same subroutine using
GTO like this:
When I test this, it seem that the program stops at the
RTN when
GTO is used.
Does the program continue with
322 LBL 13 when this happens?
Is this wrong within the program? Or do I miss something?
(07-03-2017 08:17 AM)Jotne Wrote: [ -> ]But In the Caves there are several calls to same subroutine using GTO like this:
When I test this, it seem that the program stops at the RTN when GTO is used.
Right. But this is not a call of subroutine 33, it's a jump to that label.
(07-03-2017 08:17 AM)Jotne Wrote: [ -> ]Does the program continue with 322 LBL 13 when this happens?
Is this wrong within the program? Or do I miss something?
It's quite simple. If a RTN is encountered
and there is a pending subroutine call the program returns to the line following that (XEQ-)call. If there is no pending subroutine, RTN simply stops., just like a R/S.
Code:
"ONE"
XEQ 33
"TWO"
XEQ 33
"THREE"
GTO 33
...
more code
....
LBL 33
AVIEW
PSE
RTN
...
even more code
...
If you run this, "ONE", "TWO" and "THREE" will be displayed, then the program stops at the RTN. The following "even more code" will not be executed until you press R/S to continue.
Of course it is possible that a GTO 33 occurs within a pending subroutine that has been called by an XEQ before. In this case the RTN makes the program return to the line after
that subroutine call. ;-)
Dieter
Thanks allot for the detailed explanation. I am some rusty in the 41cx programming.
Just for fun I made a Visio of the whole
Caves program.
What a big mess of routines and calls in the program

Some more question about the
Caves program.
From what I read in the
Extend you HP-41 book, page 137 regarding
LBL 00 to
LBL 14:
Quote:For now, its best to remember that these short-form labels 00 to 14 and their GTO's saves spacce but should only be used it the are less than about 40 lines apart.
Taken from the
Caves program
Code:
135 LBL 00
180 GTO 00
192 GTO 00
387 GTO 00
526 GTO 00
etc
Will these works correctly, many of them are more than 40 lines apart?
Yes, they'll work. They just can't cache the destination and will be slower.
Pauli
(07-22-2017 06:58 AM)Jotne Wrote: [ -> ]Will these works correctly, many of them are more than 40 lines apart?
The actual limit is not 40 lines but 112 bytes. If a jump to LBL 00...14 has no greater distance the jump target (the position of the LBL in memory) can be stored within the GTO command as the first jump is performed, so that afterwards no label search is required. This can speed up the program significantly. Of course the GTO will also work if the corresponding LBL is more than 112 bytes away, but it may require more time since the label has to be searched each time the program reaches the GTO.
That's why you should use LBL 15 and up for long distance jumps. The corresponding GTOs do not have this 112-byte-limit so that, once the label has been found, all subsequent jumps can be done without a label search. So in the Caves program it would have been a good idea to replace LBL 00 all all corresponding GTOs with, say, LBL 88. Just as it was done with the random number generator at LBL 99 which can be accessed quickly from any point in the program.
Dieter
(07-22-2017 12:26 PM)SlideRule Wrote: [ -> ]Is your VISIO® available?
I will post it when it looks some complete.
Just now it covers 12 A4 page.
Here is a teaser
PS I see that I am limited to only post files of 200K, that is some small.
I may need to post a link.
PS thanks Dieter and Paul for explaining the jumps..