On Wed, 14 Jan 1998 12:02:07 GMT Lynn Richardson writes: >Not elegant but seven instructions and free: > movf X,W ; get first number. > subwf Y,W ; sub second number. > bc AA ; result positive? - Yes, go to AA. > xorlw h'FF' ; convert from two's compliment > addlw 1 ; negative to positive. >AA subwf DIFF,w ; sub difference from DIFF. > bc LESS ; result + or 0? - Yes, goto LESS. > I think that will assemble to 9 instructions when the psuedo-ops are expanded, equal to the original... >-> >-> 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 On Wed, 14 Jan 1998 10:22:48 -0700 Justin Crooks writes: >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 :) > Correct me if wrong but, I don't believe that "SUBLW" is part of the 12 bit PIC world... Andy Warren, who reputation exceeds himself in this venue, sent me a version using the same logic employing a file register either conveniently or purposefully cleared to 0. ******************************** Perhaps, I should expand a bit on the conditions... If it helps, DIFF can be a constant instead of a file register. X & Y are in the range of 0 to 32 DIFF ranges between 4 & 9 It would be nice to optimize this, as there are several similar operations in the application. Still more thanks in advance! Jen :-)