On Fri, 2005-07-15 at 20:37 -0700, Andrew Warren wrote: > Oops, we don't need to copy REGA, so it can be done even faster: > > ; Find median of REGA, REGB, REGC. > > MOVF REGB,W ;TEMP2 = REGB. > MOVWF TEMP2 ; > MOVF REGC,W ;MEDIAN = REGC. > MOVWF MEDIAN ; > > SUBWF TEMP2,W ;TEMP2 >= MEDIAN? > BC $+3 ;If so, skip ahead. > ADDWF MEDIAN ;Otherwise, swap MEDIAN and > SUBWF TEMP2 ;TEMP2. > > MOVF REGA,W ;MEDIAN >= REGA? > SUBWF MEDIAN,W ; > SKPC ;If so, skip ahead. > SUBWF MEDIAN ;Otherwise, MEDIAN = TEMP1. > > MOVF MEDIAN,W ;TEMP2 >= MEDIAN? > SUBWF TEMP2,W ; > SKPC ;If so, skip ahead. > ADDWF MEDIAN ;Otherwise, MEDIAN = TEMP2. > > 17 words, 16 or 17 cycles. Looks good to me. There's away to make it 17-instructions and 17-cycles, but it's not too interesting. I don't know what I was thinking earlier - I guess I've been smoking too many virtual functions here lately! Scott -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist