title: MASM bubble sort in descending order
body: <p>I'm trying to sort a list in descending order, using a bubble sort but I'm having two problems.  The first is that the following code is inserting a 0 as the first element for a reason I don't understand (I thought maybe it was the array's fault, but it doesn't exist when this sort isn't used, so I don't know where its coming from.  The second problem is that this implementation sorts in ascending order, and I cannot figure out how to fix it to do the oppossite.  If I can figure out the zero thing a simple swap could be done, I suppose.  I have the dual problem of not being great with MASM and not being good at implementing sorts in a language I don't understand very well.</p>
  
  <p>Code:</p>
  
  <p>call from main:</p>
  
  <pre><code>push count ; size of the array
  push OFFSET list ; the array
  call sortList
  </code></pre>
  
  <p>procedure:</p>
  
  <pre><code>sortList Proc
  push ebp
  mov ebp, esp
  mov ecx,[ebp+12]
  mov edx,[ebp+8]
  bs_o:
  xor ebp,ebp
  bs_i:
  mov eax,DWORD PTR [edx+ebp*4+4]
  cmp DWORD PTR [edx+ebp*4],eax
  jb @F
  xchg eax,DWORD PTR [edx+ebp*4]
  mov DWORD PTR [edx+ebp*4+4],eax
  @@:
  add ebp,1
  cmp ebp,ecx
  jb bs_i
  loop bs_o
  pop ebp
  retn 8
  </code></pre>
  
  <p>any help is greatly appreciated.</p>