title: Assembly - Bubble Sort Algorithm for Array of String Pointers
body: <p>I'm trying to perform a bubble sort operation for an array of strings for my Assembly Class. The strings are stored in an array of string pointers, which works perfectly fine now, after much frustration. Now, I'm faced with a new problem, the sorting itself... </p>
  
  <p>Done it before in my C++ class, but wow, Assembly is a beast of its own. I'm so confused.</p>
  
  <p>Anyway, here is my code:</p>
  
  <pre><code>.586
  .MODEL FLAT
  
  INCLUDE io.h            ; header file for input/output
  
  .STACK 4096
  
  .DATA
  myStrings       byte    "fabc dui.",0
                  byte    "abcdfe.",0
                  byte    "efghi.",0
                  byte    0
  
  
  
  myStrArr        dword   20 DUP (?) ;array that will point to myStrings
  strInc          dword   0       
  
  labelPrint      byte    "The output is: ",0
  stringOut       dword   ?
  
  
  .CODE
  _MainProc PROC
  
              mov     edi, offset myStrings
              mov     esi, offset myStrArr
  </code></pre>
  
  <p>;This subroutine will transfer the strings into an array for dwords</p>
  
  <p>L1:</p>
  
  <pre><code>            cmp     byte ptr [edi], 0
              jz      OL
              mov     dword ptr [esi], edi
              add     esi, 4
              inc     strInc
              xor     ecx, ecx
              not     ecx
              xor     al, al
              repne   scasb
              jmp     L1
  
              xor     ebx, ebx
  </code></pre>
  
  <p>;This shall run once transfer is done</p>
  
  <pre><code>OL:
  
              xor     edx, edx
              mov     ebx, offset myStrArr        ;ebx -&gt; myStrArr
              mov     esi, [ebx]                  ;esi -&gt; [ebx] -&gt; myStrArr[i]
              mov     edi, [ebx+4]                ;edi -&gt; [ebx+4] -&gt; myStrArr[i+1]    
              mov     ecx, strInc
              dec     ecx                         
  
                                                  ;PROF'S TIP:  mov ebx, offset myStrArr
                                                  ;             mov esi, [ebx]
                                                  ;             mov edi, [ebx+4]
  
  IL:
              cmp     edi, esi                    ;compares the first character of the two strings
              jbe                                 ;jumps to NC if there's no change
              mov     dl, 1                       ;set direction flags
              mov     edi, [ebx]                  ;swaps it around
              mov     esi, [ebx+4]                    
  
  
  NC:
  
              mov     [ebx], edi                  ;point to next value
              add     esi, 4                      ;point to next value
              loop    IL
              or      dl, dl
              jnz     OL
  
                                                  ;IN CASE OF ME GETTING SOMETHING RIGHT, ERASE COMMENTS
                                                  ; mov       ebx, dword ptr [edi]
                                                  ; output    labelPrint, dword ptr [ebx]
  
  
                                                  ; mov       esi, dword ptr [edi]
                                                  ; output  labelPrint, dword ptr [esi]
                                                  ; add       esi, 4
                                                  ; mov       esi, dword ptr [edi]
                                                  ; output  labelPrint, dword ptr [esi]   
  
              mov     eax, 0                      ; exit with return code 0
              ret
  _MainProc ENDP
  
  END                                                ; end of source code
  </code></pre>
  
  <p>It seems like I'm doing a Bubble Sort using an array of string pointers, but I think I'm way over my heard here. A little guidance on what to do with this would be much appreciated! </p>
  
  <p>Thanks to all in advance! </p>