2 ms·
I noticed an error in the "Z80 IF-ELSE" section. It says that the overflow flag is the equivalent of the carry flag for signed numbers. But this is wrong. The o
by elvis70 6y ago
I noticed an error in the "Z80 IF-ELSE" section. It says that the overflow flag is the equivalent of the carry flag for signed numbers. But this is wrong. The overflow flag indicates that the result of the signed operation is wrong. In fact, it is the sign and zero flags that should be tested. In case of overflow, the sign must be reversed.
See this document about the carry and overflow flags: http://teaching.idallen.com/dat2343/11w/notes/040_overflow.txt http://teaching.idallen.com/dat2343/11w/notes/040_overflow.t...
The code for comparing HL >= DE should be:
(Replaced JP PO by JP M + inversion of the sign if overflow)
;==================================================
; IF-ELSE CODE FRAGMENT
;
LD HL,-2000 ; HL = -2000;
LD DE,-1000 ; DE = -1000;
AND A ; if (HL >= DE) {
SBC HL,DE
JP PO,NOOV
LD A,H ; INVERSE SIGN BIT IF OVERFLOW
XOR 80H ;
NOOV:
JP M,ELSE
LD A,1 ; A = 1;
JR ENDIF
ELSE: ; } else {
LD A,0 ; A = 0;
ENDIF: ; }
HALT
END