How would I accomplish this?
*bump*
The index registers replace HL register in instructions when combined with a prefix (for example, LD A,(HL) is $7E, LD A,(IX+d) is $DD $7E and LD A,(IY+d) is $FD $7E). As such you can't use HL and IX or IY in the same instruction.

Code:
; Copy IX to DE.
    push ix
    pop de
; Subtract DE from HL
    or a ; Clear carry flag
    sbc hl,de

This destroys DE and HL, so you may wish to push them onto the stack first and pop them back to restore them afterwards.

CP is (in effect) a subtraction that doesn't write the answer back to a register. Unfortunately there is no 16-bit CP. There is not even a straight-forwards 16-bit subtraction, only a subtract-with-carry, hence the use of SBC.
Ahhh, that's what I was going to suggest (the push ix \ pop de), but I assumed that I might be able to come up with a better way, hence why this topic stayed open in a tab for my browser for two days and I didn't make a post.
If you want a faster solution that only destroys A (at the cost of a couple bytes and TI-Nspire compatibility):

Code:
  ld a,ixh
  cp h
  jr nz,_
  ld a,ixl
  cp l
_


If you don't need the Z flag output, a smaller solution (which still sacrifices TI-Nspire compatibility) is:

Code:
  ld a,ixl
  sub l
  ld a,ixh
  sbc a,h
Thanks calc84!
SirCmpwn wrote:
Thanks calc84!
Yeah, I force myself to forget about the use of ixl and ixh for the sake of Nspire compatibility. Sad a you, TI!
  
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