title: While loop through array, MIPS assembly
body: <p>I want to convert <strong>while (w[i] == x) i += j;</strong> into MIPS assembly code.
  Assuming INTEGERS i,j, and x are in $3,$4 and $5. Also assume i=0 initially before the while loop.
  w => array of integers and its base address is stored in $6. So far I have this.</p>
  
  <pre><code>Loop:
      sll $10, $3, 2    # $10 = i* 4
      add $10, $6, $10  # $10 has address of w[i]
      lw  $11, 0($10)   # $11 = w[i]
      bne $11, $5, Exit # exit from loop if w[i]!= x
      add $3,  $3, $4   # i= i+ j
      j Loop
  Exit:
  </code></pre>
  
  <p>Is it possible to optimize this code by moving the base address itself by j*4 and also get rid of the multiple branch instructions? Cause I have no clue on how to do that.</p>
  
  <p>Thanks in advance!</p>