title: Sorting in verilog with one cycle
body: <p>i was trying to sort 9 random numbers in verilog. I use bubble sort(nested for loops) algorithm but i have a challenge. I want to sort them in one clk cycle but it does not do what i want. It needs at least 9 cycle to sort them. </p>
  
  <pre><code>always @(posedge clk)
  begin
  
  if(m &gt;= 68 &amp;&amp; sort_valid == 0) begin
      pool_sort[0] &lt;= pool_buffer[66];
      pool_sort[1] &lt;= pool_buffer[65];
      pool_sort[2] &lt;= pool_buffer[64];
      pool_sort[3] &lt;= pool_buffer[34];
      pool_sort[4] &lt;= pool_buffer[33];
      pool_sort[5] &lt;= pool_buffer[32];
      pool_sort[6] &lt;= pool_buffer[2];
      pool_sort[7] &lt;= pool_buffer[1];
      pool_sort[8] &lt;= pool_buffer[0];
  
  sort_valid &lt;= 1;
  
   end
  
  if(sort_valid == 1) begin
          for(k=0;k&lt;8;k=k+1) begin
              if(pool_sort[k] &lt; pool_sort[k+1]) begin
                  pool_sort[k] &lt;= pool_sort[k+1];
                  pool_sort[k+1] &lt;= pool_sort[k];
              end
          end
      if(sort_counter == 0) begin
          sort_valid &lt;= 0;
          pool_out &lt;= pool_sort[0];
      end
  end
  end
  
  always @(posedge clk)
  begin
  
  if(sort_valid == 1) begin
  sort_counter &lt;= sort_counter - 1;
  end
  if(sort_counter == 0) begin
      sort_counter &lt;= 8;
  end
  
  end
  endmodule
  </code></pre>
  
  <p>This is my sorting algorithm so far.</p>