The Museum of HP Calculators

HP Forum Archive 19

[ Return to Index | Top of Index ]

MCODE: Bright idea for executing an address instead of a GOTO ADR (h1E0)?
Message #1 Posted by Geir Isene on 4 Jan 2010, 9:18 a.m.

I need to execute an address in C[6:3] instead of simply jump to it like I would with a GOTO ADR (h1E0) instruction. Håkan, Angel or any other MCODE wiz have any idea of how to best accomplish this?

I could perhaps push the next address onto the return stack before I execute a GOTO ADR, but how do I get that address?

Edited: 4 Jan 2010, 9:23 a.m.

      
Re: MCODE: Bright idea for executing an address instead of a GOTO ADR (h1E0)?
Message #2 Posted by Monte Dalrymple on 4 Jan 2010, 11:22 a.m.,
in response to message #1 by Geir Isene

GOSUB 0097

This mainframe location (0097) contains GOTOC. So the subroutine call to this location will jump to the address in C[6:3] and the return at the end of the function will return to the instruction after the GOSUB?

Monte

Edited: 4 Jan 2010, 2:17 p.m. after one or more responses were posted

            
Re: MCODE: Bright idea for executing an address instead of a GOTO ADR (h1E0)?
Message #3 Posted by Geir Isene on 4 Jan 2010, 2:00 p.m.,
in response to message #2 by Monte Dalrymple

Yes. The hex word for GOTO ADR is 1E0, there is no GOSUB ADR.

      
Re: MCODE: Bright idea for executing an address instead of a GOTO ADR (h1E0)?
Message #4 Posted by Meindert Kuipers on 4 Jan 2010, 12:46 p.m.,
in response to message #1 by Geir Isene

Geir,

This is really simple as you thought. Just build the address and do the GOTO ADR. The create a return address, first do a ?NC XQ PCTOC [00D7]. I will leave it to you to study the VASM listings as an exercise how this works ;) Add a bit to this address you have been given, and then use PUSHADR to get this on the return stack, get the target address back and do your GOTO ADR.

Meindert

            
Re: MCODE: Bright idea for executing an address instead of a GOTO ADR (h1E0)?
Message #5 Posted by Geir Isene on 4 Jan 2010, 1:46 p.m.,
in response to message #4 by Meindert Kuipers

Excellent! Just what I needed.

                  
Re: MCODE: Bright idea for executing an address instead of a GOTO ADR (h1E0)?
Message #6 Posted by J-F Garnier on 4 Jan 2010, 2:28 p.m.,
in response to message #5 by Geir Isene

The method given by Monte in his (edited) post is much simpler. I used a similar trick on several microprocessors that do not have indirect gosub or call.

J-F

                        
Re: MCODE: Bright idea for executing an address instead of a GOTO ADR (h1E0)?
Message #7 Posted by Meindert Kuipers on 4 Jan 2010, 2:57 p.m.,
in response to message #6 by J-F Garnier

I made it too complex, I must admit that I did not read Monte's first reply in too much detail, the instruction is indeed a ?NC XQ 0097 after putting the needed address in C. The GOSUB that Monte mentioned took me off guard, as I use this mnemonic typically for a 3-byte relocatable call.

Meindert

                              
Re: MCODE: Bright idea for executing an address instead of a GOTO ADR (h1E0)?
Message #8 Posted by Geir Isene on 4 Jan 2010, 4:03 p.m.,
in response to message #7 by Meindert Kuipers

0097? That's one address before the function RSTKB... Makes little sense. Sure about the address?

                                    
Re: MCODE: Bright idea for executing an address instead of a GOTO ADR (h1E0)?
Message #9 Posted by Meindert Kuipers on 4 Jan 2010, 4:15 p.m.,
in response to message #8 by Geir Isene

The trick is that you are calling this address as a subroutine, so the return address is pushed on the stack when executing ?NC XG 0097. With the target address in C, your program jumps to the GOTO ADR function it finds at 0097, and will then immediately jump to your desired address, with the stack loaded with your return address (the line after your ?NC XQ 0097)

Meindert

                                    
Re: MCODE: Bright idea for executing an address instead of a GOTO ADR (h1E0)?
Message #10 Posted by Monte Dalrymple on 4 Jan 2010, 4:18 p.m.,
in response to message #8 by Geir Isene

The address is correct. The GOTOC at this address immediately
jumps to C[6:3], which is the entry to your subroutine. The
fact that the next in-line instruction is the first in the
RSTKB routine has nothing to do with anything. This is just
a convenient, known address that contains a GOTOC. Think of
it as a waypoint that you have to go through to get to your
final destination. Getting to the waypoint via a subroutine
call takes care of getting the return address on the stack.


Monte

                                          
Re: MCODE: Bright idea for executing an address instead of a GOTO ADR (h1E0)?
Message #11 Posted by Geir Isene on 5 Jan 2010, 1:07 a.m.,
in response to message #10 by Monte Dalrymple

Ah, get it. Cool.


[ Return to Index | Top of Index ]

Go back to the main exhibit hall