please dont rip this site

PIC Microcontoller Sorting Method

Bubble sort by Regulus Berdin

> 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/5 08:53,
TOP NEW HELP FIND: 
44.211.34.178:LOG IN
©2024 PLEASE DON'T RIP! THIS SITE CLOSES OCT 28, 2024 SO LONG AND THANKS FOR ALL THE FISH!

 ©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?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://www.ecomorder.com/techref/microchip/sort-rb.htm"> PIC Microcontoller Sorting&nbsp;Method Bubble sort by Regulus Berdin</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to ecomorder.com!

 

Welcome to www.ecomorder.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .