> 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 16:03, local time: 2025/5/10 08:43,
18.218.131.147:LOG IN
|
©2025 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://www.piclist.com/techref/Microchip/sort-rb.htm"> PIC Microcontoller Sorting Method Bubble sort by Regulus Berdin</A> |
Did you find what you needed? |
![]() o List host: MIT, Site host massmind.org, Top posters @none found - Page Editors: James Newton, David Cary, and YOU! * Roman Black of Black Robotics donates from sales of Linistep stepper controller kits. * Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters. * Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated! * Contributors: Richard Seriani, Sr. |
The Backwoods Guide to Computer Lingo |
.