Jameco Electronics 3000 ユーザーズマニュアル

ページ / 349
User’s Manual
41
3.4.4  Comparisons of Integers
Unsigned integers may be compared by testing the zero and carry flags after a subtract 
operation. The zero flag is set if the numbers are equal. With the 
SBC
 instruction the carry 
cleared is set if the number subtracted is less than or equal to the number it is subtracted 
from. 8-bit unsigned integers span the range 0–255. 16-bit unsigned integers span the 
range 0–65535. 
OR a  
 
; clear carry
SBC HL,DE    ; HL=A and DE=B
A>=B   !C 
A<B    C
A==B   Z
A>B    !C & !Z
A<=B   C v Z
If A is in HL and B is in DE, these operations can be performed as follows assuming that 
the object is to set HL to 1 or 0 depending on whether the compare is true or false. 
; compute HL<DE  
; unsigned integers
; EX DE,HL  ; uncomment for DE<HL
OR a        ; clear carry
SBC HL,DE 
; C set if HL<DE
SBC HL,HL 
; HL-HL-C --  -1 if carry set
BOOL HL   
; set to 1 if carry, else zero 
            ; else result == 0
;unsigned integers
; compute HL>=DE or DE>=HL - check for !C
; EX DE,HL  ; uncomment for DE<=HL
OR a        ; clear carry
SBC HL,DE   ; !C if HL>=DE
SBC HL,HL   ; HL-HL-C - zero if no carry, -1 if C
INC HL    
; 14 / 16 clocks total -if C after first SBC result 1, 
        
 ; else 0
; 0 if C , 1 if !C
;
: compute HL==DE
OR a     
; clear carry
SBC HL,DE  ; zero is equal
BOOL HL    ; force to zero, 1
DEC HL     ; invert logic
BOOL HL  
; 12 clocks total -logical not, 1 for inputs equal
;