> 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. 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; }
file: /Techref/microchip/sort-rb.htm, 1KB, , updated: 2009/2/13 15:03, local time: 2024/11/15 01:41,
3.144.172.9:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://massmind.ecomorder.com/Techref/microchip/sort-rb.htm"> PIC Microcontoller Sorting Method Bubble sort by Regulus Berdin</A> |
Did you find what you needed? |
Welcome to ecomorder.com! |
Welcome to massmind.ecomorder.com! |
.