title: About negate a sign-integer in mips?
body: <p>I'm thinking about how to negate a signed-integer in mips32. My intuition is using definition of 2's complement like: (suppose <code>$s0</code> is the number to be negated)</p>
  
  <pre><code>nor $t0, $s0, $s0   ; 1's complement
  addiu $t0, $t0, 1   ; 2's = 1's + 1
  </code></pre>
  
  <p>then I realized that it can be done like:</p>
  
  <pre><code>sub $t0, $zero, $s0
  </code></pre>
  
  <p>so... what's the difference? Which is faster? IIRC sub will try to detect overflow, but would this make is slower? Finally, is there any other way to do so? </p>