title: When to use temporary and saved registers in MIPS Assembly language?
body: <p>In this question:</p>
  
  <p>x = x + y - 10 - A[20]</p>
  
  <pre><code>x - $s0
  y - $s1
  A - $s3
  </code></pre>
  
  <p>For my answer, I wrote:</p>
  
  <pre><code>add   $t0,   $s0,   $s1    # value of x ($s0) + y ($s1) gets stored in temp $t0
  addi  $t0,   $t0,  - 10    # subtracts value of $t0 from 10. $t0 now holds the new value
  lw    $t1,   80($s3)       # loads value of A[20] into new temp $t1
  sub   $s0,   $t0,  $t1     # subtracts values $t0 from $t1 and stores it in x 
                             ($s0)
  </code></pre>
  
  <p>However the model solution says:</p>
  
  <pre><code>add   $s0,   $s0,   $s1   
  addi  $s0,   $s0,  - 10    
  lw    $t0,   80($s3)   
  sub   $s0,   $s0,  $t0
  </code></pre>
  
  <p>Is my original answer correct? Doesn't it output the same result? If I am wrong, please explain why.</p>