Re: Re: A85: SBC HL, DE
[Prev][Next][Index][Thread]
Re: Re: A85: SBC HL, DE
On Tue, 1 Sep 1998 DorkReMi@aol.com wrote:
> the carry flag? What I need to do effectively is:
>
> LD HL, value1
> LD DE, value2
> HL=HL-DE ;point of conflict
> JR C, valu2toobig ;<--I need the carry flag to be altered if DE was greater
> than HL
> ;HL was greater than DE. Subtraction successful. HL is now the difference.
>
> What commands can I use to do this?
>
I don't think that there are commands for 16-bit subtraction, there is
only:
add hl,de
add hl,bc
add hl,hl
So you'll have to negate de then do an add hl,de like so:
ld a,d
cpl
ld d,a
ld a,e
cpl
ld e,a ;now de=-de
add hl,de ;so really it's hl=hl+(-de)
OR you can do them one register at a time like so:
ld a,l ;always start with low byte when doing multiple subs
sub e ;now carry is set
ld l,a ;save byte in l
ld a,h ;now do the high byte
sbc d ;remember to take the carry from the low byte subtration
ld h,a ;save answer in h
In both cases you will get a carry if de>hl.
I haven't taken the time to see which is fastest/smallest but if you do
this more than once you'll want to make a subroutine out of it. BUT if
you do DON'T PUSH and POP AF. This will destroy the carry flag from
your subtraction.
By the way, what are you writting?
on the side:
the way the rom function CP_HL_DE works is the same as the second routine
accept a isn't loaded back into h or l like so:
CP_DE_HL:
ld a,l
sub e
ld a,h
sbc d
ret
Only a is destroyed.
-Humberto Yeverino Jr.
"I kick ass for the Lord."
***********************************************************
Home Page:
http://www.engr.csufresno.edu/~humberto/Home.html
Ti Page:
http://www.engr.csufresno.edu/~humberto/tex.html
z80 Source Page:
http://www.engr.csufresno.edu/~humberto/z80source.html
Official Tyrant Home Page:
http://www.engr.csufresno.edu/~humberto/tyrant.html
E-mail:
humberto@engr.csufresno.edu
***********************************************************
Follow-Ups:
References: