Hello,
I was looking for a possible method of jumping or calling HL, without SMC. You can modify the RAM, but that's it.
SirCmpwn wrote:
Hello,
I was looking for a possible method of jumping or calling HL, without SMC. You can modify the RAM, but that's it.
General method to jump to (hl):
Code:
push hl
ret
However, you'll note that the z80 also has these three instructions: jp (hl), jp (ix), jp (iy).
Just make sure you aren't using the sp register for something else, otherwise, you would have to use those undocumented instructions Kerm mentioned.
Jumping to HL is as simple as jp (hl) [somewhat confusingly, this is the same as ld pc,hl - not ld pc,(hl)].

Calling HL can be done like this:


Code:
    call call_hl


call_hl:
    jp (hl)
So, I can jump to hl easily, I thought of push hl \ ret moments after posing XD. However, I had no idea how to call HL. Looks like i can do this:

call CallHL
...
CallHL:
push hl
ret

and to jump:
push hl
ret

Thanks guys! Total brainfart.
There's a somewhat less awkward way of doing call hl:


Code:
    ...code...
    ld de,ReturnLbl
    push de
    jp (hl)
ReturnLbl:


That way, when the routine you jp (hl) to your routine, when it rets, it'll return to ReturnLbl.
Okay, thanks, however, I need to jump to the value in HL, not the value it points to.
SirCmpwn wrote:
Okay, thanks, however, I need to jump to the value in HL, not the value it points to.

benryves wrote:
Jumping to HL is as simple as jp (hl) [somewhat confusingly, this is the same as ld pc,hl - not ld pc,(hl)].
Sorry, I made a typo. I meant that I need to call the value in HL. In which case KermM was right.
elfprince13 wrote:
SirCmpwn wrote:
Okay, thanks, however, I need to jump to the value in HL, not the value it points to.

benryves wrote:
Jumping to HL is as simple as jp (hl) [somewhat confusingly, this is the same as ld pc,hl - not ld pc,(hl)].
To elaborate on this, this is a way to avoid confusion in case you had a label called hl (which would of course be a bad idea in the first place).

[quote="SirCmpwn"Sorry, I made a typo. I meant that I need to call the value in HL.[/quote] Say you have $9ddc in HL (ie, H=$9D and L=$DC). "jp (hl)" would start executing at $9DDC. Is that what you want to do? Or do you want to load the contents of memory at $9DDC and $9DDD and then jump to that address?
Well, I want to be able to execute code at 9DDC and then have it "ret" back to where it was. Perhaps push returnLocation \ push hl \ ret \ returnLocation:
KermMartian wrote:
There's a somewhat less awkward way of doing call hl:


Code:
    ...code...
    ld de,ReturnLbl
    push de
    jp (hl)
ReturnLbl:


That way, when the routine you jp (hl) to your routine, when it rets, it'll return to ReturnLbl.
This. again. Or substitute push hl \ ret if you don't want to use jp (hl) for some reason.
Okay, thanks. I'll get on top of it and let you guys know how it works out.
KermMartian wrote:
There's a somewhat less awkward way of doing call hl:


Code:
    ...code...
    ld de,ReturnLbl
    push de
    jp (hl)
ReturnLbl:


That way, when the routine you jp (hl) to your routine, when it rets, it'll return to ReturnLbl.

Though that may be "less awkward" to you, BenRyves' method is more optimized with regards to both speed and size and doesn't destroy the DE register.

Also, jp (hl) is always a better solution than push hl\ret.
Is it considered undocumented? Specifically, is the Nspire emulator able to run this command?
Which undocumented instruction? Not jp (hl)/jp (ix)/jp (iy), surely? See pages 270-272.
quigibo wrote:
Is it considered undocumented? Specifically, is the Nspire emulator able to run this command?

I think there is no problem with jp (hl).
Now about jp (ix)/(iy), if it the opcode starts with the ix/iy prefix ($FF or $FD?), maybe does not work.
Galandros wrote:
quigibo wrote:
Is it considered undocumented? Specifically, is the Nspire emulator able to run this command?

I think there is no problem with jp (hl).
Now about jp (ix)/(iy), if it the opcode starts with the ix/iy prefix ($FF or $FD?), maybe does not work.
They do indeed start with that prefix, although I don't know what that means in terms of verifying that the ops don't work on the Nspire:


Code:
JP (HL)       4     1   E9
JP (IX)       8     2   DD E9
JP (IY)       8     2   FD E9
They work. What doesn't work is anything that touches IXH/IXL or IYH/IYL.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement