Post Reply 
41C ROMs: LBL linkages
09-05-2019, 04:32 PM (This post was last modified: 09-05-2019 04:33 PM by hth.)
Post: #10
RE: 41C ROMs: LBL linkages
(09-05-2019 07:50 AM)Ángel Martin Wrote:  
(09-04-2019 09:45 PM)hth Wrote:  Take a look at the COPY routine in mainframe (HP-41 firmware) and how it works. It uses the old .END. to become a new local (plain ordinary) END. Then program bytes are copied into registers. The two extra words serve two purposes, to tell how many registers are needed (for PACKING - TRY AGAIN) and to tell how many NOPs go into the first register to fill up registers evenly. No new .END. is created by the COPY code, it is the END if the RPN program in ROM that becomes the new permanent .END..

We're in agreement that the program length needs to be included in ROM as well, otherwise COPY won't work. But that's not the same as the CHAIN information, right? There's no need for a pointer to the following global LBL or END instruction in ROM, I always assumed that those were written (in RAM) by COPY as part of the action...

I would also have assumed that, but after studying the source of COPY carefully, I cannot see any other explanation that the first global link must be the value that makes it line up with the END (previously right aligned .END.), in the previous register.

A clever thing here is that we for sure know the position of the preceding END and that it must exist by design, it is a beautiful trick. COPY does not need to bother about the global chain at all (apart from flipping a bit and updating one of the pointers in the 'c' register). The only downside is that it potentially leaves a trail of ENDs in CAT 1, to annoy the innocent (GTO .. pressing) user who likes to copy a lot of programs from ROMs.

I now took a look at my STOPRG which moves a RAM program into MLDL RAM. This one has never been published, and has a known bug, it will not clean up if it runs out of space. It was quite a throw back, I am amazed that I even recompile short GTO into long ones, which invalidates the global chain (in ROM), and it later goes into rebuilding the global chain again (in ROM), and has these two snippets:
Code:

STP21 C=C+1 M
 C=C+1 M
 C=C+1 M
 C=0 S&X
 WRIT Q


[..]

;NOW ENTER ALL GLOBAL LABELS
;INTO FAT...
;SINCE WE MAY HAVE BLOWN THE GLOBAL
;CHAIN DUE TO PROGRAM LENGTH CHANGE,
;WE MUST RECALCULATE THE GLOBAL
;CHAIN COMPLETELY!
 READ Q ;GET START ADDRESS
 A=C M ;FIX GHOST CHAIN TO NEXT END
 C=C-1 M ;(THIS WILL BE THE .END.
 FETCH ;WHICH EXISTS BEFORE WE
 RCR 1 ;PERFORM A COPY!!!!!)

That old code does not seem to change global XEQ to XROMs though, so it has a few short-comings.

So at least I also did it 35 years ago. I am not sure about how other ROM loaders are written.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
41C ROMs: LBL linkages - RobertM - 08-28-2019, 12:21 AM
RE: 41C ROMs: LBL linkages - Ángel Martin - 08-28-2019, 04:56 AM
RE: 41C ROMs: LBL linkages - RobertM - 08-28-2019, 01:57 PM
RE: 41C ROMs: LBL linkages - hth - 09-01-2019, 04:42 AM
RE: 41C ROMs: LBL linkages - RobertM - 09-04-2019, 08:41 PM
RE: 41C ROMs: LBL linkages - hth - 09-04-2019, 09:45 PM
RE: 41C ROMs: LBL linkages - RobertM - 09-05-2019, 12:10 AM
RE: 41C ROMs: LBL linkages - hth - 09-05-2019, 01:27 AM
RE: 41C ROMs: LBL linkages - Ángel Martin - 09-05-2019, 07:50 AM
RE: 41C ROMs: LBL linkages - hth - 09-05-2019 04:32 PM



User(s) browsing this thread: