The original question was, to find a routine for min and max of four numbers. The bubble sort is one, here is another. 19 words, no bubble sort, NO STACK USE (can inline). Uses 1 aux. register, leaves input data unchanged, output in Fmin and Fmax. Faster than Andy Warren's bubble sort ? Expands to more than 4 values to be analyzed (set LAST...). Run time: 20 + (LAST-1) * 14 -> 62T constant run time (Andy Warren's bubble sort takes a shorter, but variable time, and uses the stack - not an option in an ISR on a 14 bit core and NON option on 12 bit cores. Avg. time for his ORDER is 5.5 T. His run time is: 9.5 + 15 + 16.5 + 2 ~= 43 (+/- 3T) I think). (BEWARE UNTESTED CODE) LAST db 4 ;; find lowest and highest value from a vector of bytes between FSR and ;; FSR + LAST, sort in Fmin and Fmax, destroys Fcounter, no stack MinMax: movlw LAST movwf Fcounter clrf Fmax incf Fmax,w movwf Fmin loop: movf INDF,w subwf Fmax,w ;; Fmax - INDF < 0 ? C = 0 movf INDF,w btfss STATUS,C movwf Fmax movf Fmin,w subwf INDF,w ;; INDF - Fmin < 0 ? C = 0 movf INDF,w btfss STATUS,C movwf Fmin incf FSR,f decfsz Fcounter,f goto loop retlw 0 Peter -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.