- Code: Select all
; 16 bit compare by Y with X
; subtraction X to Y, X should be the greatest
; if X=Y then now Z=1
; if Y<X then now C=0
; if X<=Y then now C=1
cmp16 macro Y,X,FAR
local NEAR
clrc
movf high X,W
subwf high Y,W
bnc FAR
bnz NEAR
movf X,W
subwf Y,W
bnc FAR
NEAR
endm
; Same as above but compare a file with a constant
cmpi16 macro Y,CONST,FAR
local NEAR
clrc
movf high Y,W
sublw high (CONST)
bnc FAR
bnz NEAR
movf Y,W
sublw low (CONST)
bc FAR
NEAR
endm
; Same as above but compare a constant with a file
cmpc16 macro CONST,Y,FAR
local NEAR
clrc
movlw high (CONST)
subwf high Y,W
bnc FAR
bnz NEAR
movlw low (CONST)
subwf Y,W
bc FAR
NEAR
endm
Honestly I haven't yet tested on the hardware , but during a test with Proteus VSM, they don't behave as expected.
I'd expect that if the second term is less than the first it will branch to FAR.