That's pretty close to perfect. You could also try this... movf X,W subwf Y,W skpc sublw 0x00 ;If it is negative, make it positive. subwf DIFF,W skpnc goto LESS... Not much of an improvement, but maybe a little cleaner :) ---------- > From: Jennifer Wilson > To: PICLIST@MITVMA.MIT.EDU > Subject: Absolute Difference Algorithm > Date: Tuesday, January 13, 1998 9:49 AM > > Happy New Year, > I was just wondering if anyone has an elegant method for determining > whether two numbers are within an absolute difference, in the 12 bit PIC > universe. > > For example... the two numbers, X & Y, are in registers which must > remain unchanged are to be tested to determine whether they are within > DIFF of each other. > > My first try this year is: > > MOVF X,W ;Try it this way > SUBWF Y,W > > SKPNC ; Positive? > GOTO POS ; Yes > > MOVF Y,W ; No, then do it the other way > SUBWF X,W > > POS SUBWF DIFF,W ; Compare against the limit > > SKPNC ; The carry knows... > GOTO LESS > > > Thanks in advance, > Jen :-)