title: converting a C for loop to MIPS
body: <p>I'm trying to make this C code translated directly to mips, without modifying any instructions, to make it run better:</p>
  
  <pre><code>for(i = 0; i != j; i += 2)
      b[i] = a[i] - a[i + 1]
  </code></pre>
  
  <p>I'm not really going to be coding in mips, I'm just trying to understand some things. Here's what I have so far (not much):</p>
  
  <pre><code>#t5 = i
  $t6 = j
  #t1 = a
  #t2 = b
  #t3 = c
  #t10, t11, t12 = free
  
  add $t5, $zero, $zero # initialize i = 0 
  
  loop:
      bne $t5, $t6        # check if i is not equal to j
      addi $t5, $t5, 2    # i += 2
      add $t10, $t5, $t11 # temp reg $t10 = address of b[i]
      lw $t2, 0($t10)     # temp reg $t2 = b[i]
      add $t10, $t5, $t12 # temp reg $t10 = address of a[i]
      lw $t1, 0($t10)     # temp reg $t1 = a[i]
  </code></pre>
  
  <p>Not sure if the <code>bne</code> is right, since I didn't specify anywhere to branch to. I've read up on arrays in mips but it confuses me. I know I need to use the proper offset for byte addressing when putting the arrays in the registers. Would it be the same with a variable instead of a number in the array? Any direction or tips would be nice. Thank you!</p>