SHARE
TWEET

Untitled

a guest Jun 18th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .globl selection_sort
  2. selection_sort:
  3.    pushl %ebx
  4.    pushl %esi
  5.    pushl %edi
  6.    subl $8,%esp
  7.    movl 24(%esp),%ebx         #short *ebx=v;
  8.    xorl %edi,%edi             #int edi=0;//i
  9.    movl $1,%esi               #int esi=1;//j
  10.                               #int eax;//min
  11.    movl 28(%esp),%ecx
  12.    decl %ecx
  13. OUTERFOR:
  14.    cmpl %edi,%ecx             #if(edi>=n-1)
  15.    jle E                      #   goto E;
  16.    movl %edi,%eax             #eax=edi;
  17.    movl %edi,%esi             #esi=edi;
  18.    incl %esi                  #edi++;
  19. INNERFOR:
  20.    incl %ecx
  21.    cmpl %esi,%ecx             #if(esi>=n)
  22.    jle SWP                    #   goto SWP;
  23.    decl %ecx
  24.    movw (%ebx,%eax,2),%dx
  25.    cmpw (%ebx,%esi,2),%dx     #if(*(ebx+esi)<*(ebx+eax))
  26.    cmovgl %esi,%eax           #   eax=esi;//min=j
  27.    incl %esi                  #esi++;
  28.    jmp INNERFOR               #goto INNERFOR;
  29. SWP:
  30.    decl %ecx
  31.    leal (%ebx,%edi,2),%edx
  32.    movl %edx,(%esp)
  33.    leal (%ebx,%eax,2),%edx
  34.    movl %edx,4(%esp)
  35.    call swap                  #swap(ebx+edi,ebx+eax);
  36.    incl %edi                  #edi++;
  37.    jmp OUTERFOR               #goto OUTERFOR;
  38. E:
  39.    addl $8,%esp
  40.    popl %edi
  41.    popl %esi
  42.    popl %ebx
  43.    ret                        #return;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top