;**************** 16 bit compare ****************
; Upon return, a code in w will indicate the outcome of the comparison.
; If n1 > n2 then w = 1. If n1 < n2 then w =2. If n1 = n2 then w = 0.
Comp16 bcf Flags, Z_ ; Clear aux Z bit.
movf n2L, w ; w = n2L
subwf n1L, 0 ; w = n1L-n2L <Microchip instruction>
btfsc STATUS, Z ; Copy Z bit to Z_.
bsf Flags, Z_
movf n2H, w ; If n1L-n2L underflowed,
btfsc STATUS, C ; then increment n2H (same
goto Comp16_cont
incf n2H, w ; as decrementing n1H).
btfsc STATUS, Z ; If n2H overflows, n1 must be < n2
retlw D'2' ; so return with 2 in w.
Comp16_cont subwf n1H, 0 ; w = n1H-n2H <Microchip instruction>
btfss STATUS, C ; If n1H underflows, n1<n2 retw 2 ; so return with 2 in w. jnb Z_,:cont2 ; By now we're suren1'>=n2.
btfsc STATUS, Z ; If both z and Z_ are set,
retlw D'0' ; both subtractions resulted in 0, so
Comp16_cont2 retlw D'1' ; n1=n2. Otherwise n1>n2.