On Sat, 14 Jun 2003, Mike Harrison wrote: > For such a small number of values, maybe some trickery can be done to > simplfy things, in particular it may be easier to insert new values in > the correct place in the list instead of sorting afterwards - a new > value cannot affect the order of the other 4 values. Also, it may be > easier/quicker to not move the values about, just keep a list of what > order they need to be in, as this can be held in one byte per entry, so > fewer things need to be juggled about For such low number of items, bubble sort is the best. You need an algorithm like (in pseudo C): #define try_swap(a,b) if( a > b ) { int x=a; a=b; b=x; } try_swap(a[0],a[1]); try_swap(a[0],a[2]); try_swap(a[0],a[3]); try_swap(a[0],a[4]); try_swap(a[1],a[2]); try_swap(a[1],a[3]); try_swap(a[1],a[4]); try_swap(a[2],a[3]); try_swap(a[2],a[4]); try_swap(a[3],a[4]); It's unroled, so you don't really need array access (you can sort any five variables). To write in PIC assembler, you only need the "try_swap" macro. If your variables were 8 bit, it can be done in 6 cicles, so the total is 6*10 = 60 cycles. Daniel. -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics It's very interesting, i have the same need, but i don't know how to write it in pic assembler can you help me ? Thank you Jean Karl -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu