title: How to check if two signed 32 bit integers cause overflow in MIPS?
body: <p>I have figured out that for two unsigned integers, I can just do this:</p>
  
  <pre><code>sll $a0, $a0, 31                          #a0 is integer 1 to be added
  
  sll $a1, $a1, 31 #a1 is integer 2
  
  add $t0, $a0, $a1 #result in $t0
  
  addi $t1, $0, 2
  
  beq $v0, $t0, $t1
  </code></pre>
  
  <p>What this does is it shifts the 32nd bit of both integers to the first bit spot and it adds them. If both of these numbers are 1, then the answer in $t1 will be 2 (01+01=10). Therefore, an overflow has occurred.</p>
  
  <p>However for signed integers, the leading one signifies negative integers. I've ruled out the possibility for an overflow is both integers are off opposite sign, but suppose they are the same sign. Then 010 + 011 (two positive integers) will give me 101, but because this is signed. This becomes a negative integer. Would I just check if the number has changed signs? And for two negative integers, I can just check as if it were unsigned?</p>