[TI ASM] negating HL

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

Post Reply
Duck
Sir Posts-A-Lot
Posts: 231
Joined: Sat 18 Dec, 2004 3:38 am

[TI ASM] negating HL

Post by Duck »

Does anyone know a good way to negate HL? The way I'm doing it at the moment is:

ld a,h
neg
ld h,a
ld a,l
neg
ld l,a
ret

There are some undocumented instructions "XOR [HX/HY/LX/LY]" but i cant find information about them. Does anyone know what these do?

Thanks in advance.
Kalimero
Regular Member
Posts: 130
Joined: Fri 17 Dec, 2004 1:47 pm

Re: [TI ASM] negating HL

Post by Kalimero »

Duck wrote: ld a,h
neg
ld h,a
ld a,l
neg
ld l,a
ret
This doesn't always work. Try with 1 for example. You should just complement H and L with cpl and then increment HL.
There are some undocumented instructions "XOR [HX/HY/LX/LY]" but i cant find information about them. Does anyone know what these do?
I suspect these are the lower and higher bytes of ix and iy. Sometimes they are also referred to as ixh, ixl, iyh and iyl.
CoBB
MCF Legend
Posts: 1601
Joined: Mon 20 Dec, 2004 8:45 am
Location: Budapest, Absurdistan
Contact:

Post by CoBB »

I'd advise against using NEG at any time. CPL \ INC A is equivalent (both in size and time), and it opens more possibilities for optimisation.

As for the HX/LY notation, I also mention it in my guide. ;) (At the beginning, where registers are explained.)
Duck
Sir Posts-A-Lot
Posts: 231
Joined: Sat 18 Dec, 2004 3:38 am

Post by Duck »

Oh yea of course, totally forgot about our lovely CPL. It was some time ago it wrote some assembly :) If even does the job better, flipping all bits in the byte. Thanks guys!
Post Reply