Post Reply 
HP-41: Reusing local labels in same program.
10-23-2023, 02:00 PM
Post: #1
HP-41: Reusing local labels in same program.
@Valentin made the suggestion the other day where a local label was reused in such a way as to be effectively a NOP. After learning a bit more on how labels are parsed, I made up program "//Double label trouble 1" to demonstrate how a duplicate label may never be seen.

Yesterday I came across the part in the HP-41CX manual where it talks about 'compiling', i.e. the offset from GTO to label being remembered after first use. This got me wondering if one set up a program to try and make it possible that a local label could be reached if it would be. I write the program, "//Double label trouble 2" this morning to demonstrate this idea. To my surprise both 'LBL 01' instances are used. The offset recorded must me attached to each GTO. More reading on my part needed.

Someone else suggested the book "Extend Your HP-41", link below, which shows some other interesting uses of labels in section 6.4. These sorts of tricks are interesting to me but could lead to programs that are hard to understand and modify, particularly for a newbie.

Code:

//Double label trouble 1
LBL "EA"        ; First entry point
10              ; Entry marker
GTO 02          ; 
LBL 01          ; 1st LBL 01
11              ; Exit marker
RTN
LBL "EB"        ; Second entry point
20              ; Entry marker
GTO 02
LBL 01          ; 2nd LBL 01
22              ; Exit marker
RTN
LBL 02
GTO 01          ; Which LBL 01 will it goto?[/font]

Code:

//Double label trouble 2
LBL "E1"        ; First entry point
10              ; Entry marker
GTO 01          ; 
00              ; Line never hit
LBL 01          ; 1st LBL 01
11              ; Exit marker
LBL "E2"        ; Second entry point
20              ; Entry marker
GTO 01
00              ; Line never hit
LBL 01          ; 2nd LBL 01
22              ; Exit marker
RTN

Extend your HP-41
Find all posts by this user
Quote this message in a reply
10-23-2023, 08:51 PM
Post: #2
RE: HP-41: Reusing local labels in same program.
The search will start where the program pointer is pointing and go forward.  If the searched-for label is not found by the time the search reaches the end of the program, the search will continue at the beginning of the same program.  When a match if found, the offset is stored at the GTO so that after that, it will try that location first, and unless you've edited the program, it will be found quickly.  If it does not find it there, (because you've edited the program), the search process starts over.  I could be slightly off in a detail or two, but this is the effect.  Obviously if you do a GTO INDirect, it will have to search every time, since the contents of the register you're specifying as a label selector will keep changing.

http://WilsonMinesCo.com  (Lots of HP-41 links at the bottom of the links page, at http://wilsonminesco.com/links.html#hp41 )
Visit this user's website Find all posts by this user
Quote this message in a reply
10-23-2023, 10:53 PM (This post was last modified: 10-23-2023 10:54 PM by Valentin Albillo.)
Post: #3
RE: HP-41: Reusing local labels in same program.
(10-23-2023 02:00 PM)Jeff_Birt Wrote:  @Valentin made the suggestion the other day where a local label was reused in such a way as to be effectively a NOP.

This refers to my suggestion here:
    LBL 01
    ISG 01
    LBL 01
which I further explained here:
    "Re-using LBL 01 is ideal, as it's a 1-byte instruction which here it's just a never-executed placeholder and it can't be reached from anywhere in the program, whether directly or indirectly."
Among the great number of placeholder instructions of all sizes which I could have chosen to illustrate the point I regrettably chose reusing LBL 01 purely on aesthetic grounds, as I liked the incrementing instruction ISG "sandwiched" (so to say) between both LBL 01 instructions, it looked nice.

However, I now realize that it turned out to be a mistake on my part as attention was drawn to the second LBL 01, which, I repeat once more, is but a placeholder as it's never executed and can't be reached by any GTO or XEQ anywhere in the program. It can be replaced by any other instruction, say SIN or CLRG or "PEPE" or XEQ "DKJFHK", as it won't be executed ever. If in doubt, try BEEP, like this:
    LBL 01
    ISG 01
    BEEP
and notice that you won't ever hear it.

Quote:Yesterday I came across the part in the HP-41CX manual where it talks about 'compiling', i.e. the offset from GTO to label being remembered after first use [...] To my surprise both 'LBL 01' instances are used. The offset recorded must me attached to each GTO. More reading on my part needed.

Correct, the offset to the label is compiled inside 2-byte GTOs (short offset, <=112 bytes) or 3-byte GTOs and XEQs (long offset, >112 bytes). This is very clearly explained in this truly excellent book (which also deals with synthetics and even microcode): specifically in pages 55-57. Have a look at the detailed examples given there.

Hope it helps.
V.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
10-23-2023, 11:23 PM
Post: #4
RE: HP-41: Reusing local labels in same program.
Thanks Garth and Valentin. Valentin I'm glad you used the LBL 01 as a place holder as it caused me to think about 'why' it would work and explore and learn in more detail how labels work. For example, I was surprised by the way my second test program behaved but it led me to believe that the offset must be stored in the GTO. I have not had a chance to do more reading on that, but you and Garth have confirmed that, and you provided a link to more reading material as well.

Thanks!
Find all posts by this user
Quote this message in a reply
10-24-2023, 12:04 PM
Post: #5
RE: HP-41: Reusing local labels in same program.
As an aside, I wish the Voyagers and the 20S/21S/32S/32SII had adopted the "search forward from current program pointer" methodology that was in use from the 65 to the 41. Instead they always search from the top of program memory, meaning you can't reuse labels.
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




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