Post Reply 
HP 41-XEQ/GTO and RTN
07-03-2017, 08:17 AM
Post: #1
HP 41-XEQ/GTO and RTN
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:
Code:
129 XEQ 33
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:
Code:
176 GTO 33

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?
Find all posts by this user
Quote this message in a reply
07-03-2017, 10:50 AM (This post was last modified: 07-03-2017 10:54 AM by Dieter.)
Post: #2
RE: HP 41-XEQ/GTO and RTN
(07-03-2017 08:17 AM)Jotne Wrote:  But In the Caves there are several calls to same subroutine using GTO like this:
Code:
176 GTO 33

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
Find all posts by this user
Quote this message in a reply
07-03-2017, 02:30 PM (This post was last modified: 07-03-2017 02:30 PM by Jotne.)
Post: #3
RE: HP 41-XEQ/GTO and RTN
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 Smile
Find all posts by this user
Quote this message in a reply
07-22-2017, 06:58 AM
Post: #4
RE: HP 41-XEQ/GTO and RTN
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?
Find all posts by this user
Quote this message in a reply
07-22-2017, 07:34 AM
Post: #5
RE: HP 41-XEQ/GTO and RTN
Yes, they'll work. They just can't cache the destination and will be slower.


Pauli
Find all posts by this user
Quote this message in a reply
07-22-2017, 12:26 PM (This post was last modified: 07-22-2017 12:27 PM by SlideRule.)
Post: #6
RE: HP 41-XEQ/GTO and RTN
(07-03-2017 02:30 PM)Jotne Wrote:  ... detailed explanation ... a Visio of the whole Caves program...

Is your VISIO® available?

BEST!
SlideRule
Find all posts by this user
Quote this message in a reply
07-22-2017, 04:07 PM
Post: #7
RE: HP 41-XEQ/GTO and RTN
(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
Find all posts by this user
Quote this message in a reply
07-22-2017, 07:45 PM
Post: #8
RE: HP 41-XEQ/GTO and RTN
(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 Smile

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..


Attached File(s) Thumbnail(s)
   
Find all posts by this user
Quote this message in a reply
Post Reply 




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