title: Break down the logic for a C for-loop into something I can implement in MIPS? (count number occurrences in an array)
body: <p>Hi all i am converting my C code to MIPS but problem is here i couldn't make correct logic for this</p>
  <pre class="lang-c prettyprint-override"><code>for (int i=0;i&lt;count;i++)
    {
          h[a[i]]++;
    }
  </code></pre>
  <p>as far i make my own logic that is wrong</p>
  <p>Assume That</p>
  <p><code>a[]=$t1</code>
  <code>b[]=$t2</code></p>
  <pre><code>li $s1,0
  
  for:
  bgt $s1,[size of array],end
  
  lw $t3,($t1)
  la $t1,4($t3)
  lw $t4,($t2)
  la $t2,4($t2)
  sw $t3,0($t4)
  
  add $s1,$s1,1
  j for
  </code></pre>
  <p>i know this is wrong .. but in MIPS it gives me bad address error and exception 7 and 4 error</p>
  <hr />
  <p>Also, how to get the array length into a MIPS register, like how C can calculate the number of elements for you without having to hard-code it?</p>
  <pre><code>int arr[]={1,3,5,7,9};
  int n=sizeof(arr)/sizeof(arr[0]);
  </code></pre>