Brian Aase wrote: > > Can anyone point me towards an example of code (asm, not c) > that will sort (re-arrange) a group of 10 or so numbers stored in > consecutive RAM locations into ascending order? Or descending > order, doesn't really matter which. Hi, Try this (untested): cblock d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 tmp i endc bubble: movlw 9 movwf i addlw d1 movwf FSR loop1 movf INDF,w ;for i = 9 to 1 'd10 to d2 movwf tmp ;tmp = d[d1+i] loop2 decf FSR,f ;for FSR = (d1+i-1) to d1 movf tmp1,w ;compare subwf INDF,w skpc ;change this to skpnc to change sort order goto noswap swap movf tmp1,w xorwf INDF,f xorwf INDF,w xorwf INDF,f movwf tmp noswap movlw d1 xorwf FSR,w skpz goto loop2 movlw d1 addwf i,w movwf FSR movf tmp,w movwf INDF ;d[d1+i] = tmp decf FSR,f decfsz i,w goto loop1 return ;equivalent in C for (i=10;i>1;i--) { tmp=d[i]; for (k=i-1;i>0;k--) if (d[k]>tmp) { tmp2=tmp; tmp=d[k]; d[k]=tmp2; } d[i]=tmp; } regards, Reggie