HP-41: Reusing local labels in same program. - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: General Forum (/forum-4.html) +--- Thread: HP-41: Reusing local labels in same program. (/thread-20688.html) |
HP-41: Reusing local labels in same program. - Jeff_Birt - 10-23-2023 02:00 PM @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:
Code:
Extend your HP-41 RE: HP-41: Reusing local labels in same program. - Garth Wilson - 10-23-2023 08:51 PM 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. RE: HP-41: Reusing local labels in same program. - Valentin Albillo - 10-23-2023 10:53 PM (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:
ISG 01 LBL 01
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:
ISG 01 BEEP 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):
Hope it helps. V. RE: HP-41: Reusing local labels in same program. - Jeff_Birt - 10-23-2023 11:23 PM 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! RE: HP-41: Reusing local labels in same program. - Dave Britten - 10-24-2023 12:04 PM 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. |