title: How to calculate negative number in MIPS assembly?
body: <p>I am trying to compile following assembly source code, First here is code :</p>
  <pre><code>#include &lt;xc.h&gt;
  
  .global main
  .text
  
  .set noreorder
  
  .ent main 
  
  main:
      
  nop /* &quot;no operation&quot;... replace this. */
  nop /* &quot;no operation&quot;... replace this. */
  nop /* &quot;no operation&quot;... replace this. */
      
  addiu $s1, $zero, 22
  addiu $s2, $zero, 59
  sub   $t2, $s1,   $s2  
  
  .end main 
  </code></pre>
  <p>And here is my problem:</p>
  <p>As you see,  <code>$s1 = 22</code> and <code>$2 = 59</code>. So, <code>22 - 59 = -37</code></p>
  <p>But when I watch <code>$t2</code> variable it has <code>4294967259</code> (in decimal).
  I don't understand why... it should be <code>-37</code>...</p>
  <p>Here is output photo:
  <a href="https://i.stack.imgur.com/KmnwZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KmnwZ.png" alt="click here to see my incorrect output" /></a></p>
  <h3>Question 1.</h3>
  <p>How to fix above problem?</p>
  <h3>Question 2.</h3>
  <p>How to calculate negative number?</p>
  <p>for example, <code>-22 - 33 = - 55</code></p>
  <p>and source code for this:</p>
  <pre><code>add $s1, $zero, -22
  add $s2, $zero, -10
  sub $t2, $s1,   $s2   
  </code></pre>
  <p>But it also doesn't work. <code>$s1</code> has like <code>4294967274</code> in decimal.. and <code>$s2</code> same..</p>
  <p>Thank you very much if you can help me this problem.
  (I run compiler called MPLAB X IDE)</p>