title: Assembly Language Bubblesort
body: <p>I have to sort an array given by ARY1, Sort it down in the SORT function, then store the sorted array into ARY1S. I chose not to include ARY2, but it would work identical. The SORT should work for both ARY1 AND ARY2. I took the bubblesort algorithm(C++) and tried my best to convert it into assembly, but I have run into errors. </p>
  
  <p>My <code>D0</code> is length of array</p>
  
  <p>My <code>D1</code> would be i</p>
  
  <p>My <code>D2</code> would be j</p>
  
  <p>and <code>D3</code> is temp</p>
  
  <p>Here is my attempt(this does not work) not only because of syntax issues:</p>
  
  <pre><code>ARY1        DC.B 7       //array size    
              DC.B 56,-5,8,23,-9,18,4 //my array
  ARY1S       DS.B 7      //storage size
  
  SORT1       MOVEA.L #ARY1, A0  //moving values into A0               
              MOVEA.L #ARY1S, A1
              MOVE.B (A0)+, D0   //Storing size (7) into D0
              BSR SORT
  
  SORT        CMP.B D0,D1
              BGE DONE
  
  LOOP        CMP.B D0,D2
              BGE INC
              CMP (A1,D2),(A1,D1) //this is not compiling/wrong syntax
              BLE NOTLESS
              MOVE.B (A1,D2),D3
              MOVE.B (A1,D1),(A1,D2)
              MOVE.B D3,(A1,D1)
  
  NOTLESS     ADDQ #1, D2
              BRA LOOP
  
  INC         ADDQ #1, D1
              MOVE.B D1,D2
              BRA SORT
  
  DONE        RTS
  </code></pre>
  
  <p>Also, if someone can help with the line of code that I commented is not working. Prompting syntax error.  </p>