Peter L. Peres wrote: > 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). Peter: Geez... Suddenly, I feel like Jimmy Ringo, Gregory Peck's character in "The Gunfighter". I have no isea what you mean by "uses the stack - not an option in an ISR on a 14 bit core and NON option on 12 bit cores". The bubble- sort routine I posted will work perfectly well in either of those situations. In any case, here's a routine that does exactly what yours does, except that it's smaller and much faster: MINMAX: MOVF INDF,W ;GRAB THE FIRST VALUE. MOVWF MAX ;ASSUME IT'LL BE THE MAX. MOVWF MIN ;ASSUME IT'LL BE THE MIN, TOO. MOVLW LAST ;SETUP TO LOOP "LAST" TIMES (NOTE MOVWF COUNT ;THAT LAST = 3 FOR A 4-BYTE ARRAY). LOOP: INCF FSR ;POINT AT THE NEXT VALUE. MOVF MIN,W ;W = INDF-MIN. SUBWF INDF,W ; SKPC ;IF INDF >= MIN, SKIP AHEAD. ADDWF MIN ;OTHERWISE, MIN = INDF. MOVF MAX ;W = INDF - MAX. SUBWF INDF,W ; SKPNC ;IF MAX > INDF, SKIP AHEAD. ADDWF MAX ;OTHERWISE, MAX = INDF. DECFSZ COUNT ;IF WE'VE DONE THEM ALL, SKIP AHEAD. GOTO LOOP ;OTHERWISE, LOOP BACK. Size: 16 Words Run Time: 5 + 12*LAST - 1 = 40 cycles for a 4-byte array. Thanks for playing. -Andy === Andrew Warren - fastfwd@ix.netcom.com === Fast Forward Engineering - San Diego, California === http://www.geocities.com/SiliconValley/2499 -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.