LD HL,256 ; Two-byte number
LD DE,257 ; Another two-byte number
OR A ; Reset carry flag
SBC HL,DE ; Subtraction with carry
JR C,Carried ; This will get executed because HL-DE is less than zero
CPDEBC:
push de
ex de, hl
or a
sbc hl, bc
ex de, hl
pop de
ret
Preserves all registers, etc, and sets flags just like CP.
oh yeah can you explain what's "or a" or "xor a" is? i dont know where to learn about them.Those involve Bitwise Arithmetic. It modifies numbers based on their binary values.
11110101 (A)
and 10011011 (B)
------------------
10010001
11110101 (A)
or 10011011 (B)
------------------
11111111
11110101 (A)
xor 10011011 (B)
------------------
01101110
or a ;reset carry flag
sbc hl, de
add hl, de
This one is small enough that it doesn't need it's own call, so just put it inline like you would CP A. And just like SirCmpwn said, this messes with the flags in the exact same way that CP A does.
And just like SirCmpwn said, this messes with the flags in the exact same way that CP A does.
;we will subtract big num 1 from big num 2
ld hl, (bigNum2) ;hl = $0201
ld de, (bigNum1) ;DE = $0605
or a ;this time we don't want the carry flag
sbc hl, de
ld (result), hl ;DE was bigger than HL, so the carry flag is set
ld hl, (bigNum2+2)
ld de, (bigNum1+2)
sbc hl, de ;since the last operation carried, (remember 2nd grade math)
ld (result+2), hl ;we had to subtract an extra 1 from this result
bigNum1:
.db 5, 6, 2, 3
bigNum2:
.db 1, 2, 8, 9
result:
.db 0, 0, 0, 0