Ahora no estoy en casa, pero juraría que con sbc se puede hacer... xor a
sbc hl, de
jp z, @@HL_IGUAL_DE
jp c, @@HL_MENOR_DE
@@HL_MAYOR_DE:
...
@@HL_IGUAL_DE:
@@HL_MAYOR_DE:
...Si estoy equivocado, por favor corregidme.He encontrado en
esta página un cheatsheet en el que viene un algoritmo de comparación de 16 bit con signo y no parece ser tan sencillo...
; BC contains 16-bit signed value X
; DE contains 16-bit signed value Y
; X < Y
LD A,B ; get MSB of value X
ADD $80 ; flip sign bit of MSB
LD L,A ; save signed MSB value for later
LD A,D ; get MSB of value Y
ADD $80 ; flip sign bit of MSB
CP L ; compare LSB of value X & value Y
JR NZ,.different ; equal? no, so test for less than
LD A,E ; get LSB of value Y
CP C ; compare LSB of value X & value Y
.different:
JP NC,.greater ; less than? no, so value X >= value Y
CALL condition_true ; X < Y, condition is true
.greater:
; X == Y
LD A,C ; get LSB of value X
CP E ; compare with LSB of value Y
JP NZ,.different ; equal? No, so test is false
LD A,B ; get MSB of value X
CP D ; compare with MSB of value Y
JP NZ,.different ; equal? no, so test is false
CALL condition_true ; X == Y, condition is true
.different:
; X <= Y
LD A,D ; get MSB of value Y
ADD $80 ; flip sign bit of MSB
LD L,A ; save signed MSB value for later
LD A,B ; get MSB of value X
ADD $80 ; flip sign bit of MSB
CP L ; compare MSB of value X & value Y
JR NZ,.different ; equal? no, so test for greater than
LD A,C ; get LSB of value X
CP E ; compare with LSB of value Y
.different:
JP C,.greater ; greater? yes, so value X > value Y
CALL condition_true ; X <= Y, condition is true
.greater: