>> movf AD_LOW,w >> subwf REF_LOW,w ; C set if REF_LO >= AD_LO >> movf AD_HIGH,w >> btfss C >> incf AD_HIGH,w >> subwf REF_HIGH,w ; C set if REF_HIGH >= AD_HIGH... >> ; ...and REF_LOW >= AD_LO, or... >> ; ...if REF_HIGH >= (AD_HIGH+1) >> bcf STAT,2 >> btfss C >> bsf STAT,2 >> >> Note that the above routine is 9 cycles isochronous (slightly better than >> HiTech's) but that it will not work if AD >= 65280. Given that the >> problem stipulated that AD < 4096, this should not pose a problem. >Hello John. >To overcome H'FFxx' "barrier" i offer slightly modified variant of your >code: > movf AD_LOW,w > subwf REF_LOW,w > movf AD_HIGH,w > btfss C > incfz AD_HIGH,w ;this point was modified > subwf REF_HIGH,w > bcf STAT,2 > btfss C > bsf STAT,2 >This code has no limitation. >WBR Dmitry. Since I'm the one that initiated this "challenge", I'll be the one that ends it. Thanks to all that contributed. John's and Dmitry's solutions are equally good, since the AD-value will be less than 4096. But as a general 16-bit compare Dmitry's solution is the best. It's nice to see that hand-optimized code still beats what a compiler produces. (But the Hi-Tech code impressed me....) -Oyvind