title: (ASM) How to make a positive integer negative?
body: <p>I am doing some online MIPS ASM exercises, however other ASM languages will be similar.</p>
  
  <p>I am having a problem with the following question.
  It requires me to perform 13x. This is easy:</p>
  
  <pre><code>## Compute 13x
  
  ori $8,$0,1     # $8 = x
  
  sll $9,$8,2     # x*2^2 = 4x
  sll $10,$8,3        # x*2^3 = 8x
  addu $10,$9,$10     # 4x+8x = 12x
  addu $10,$10,$8     # 12x+x = 13x
  </code></pre>
  
  <p>However, it then says to calculate -13x by adding only <strong>one</strong> more instruction.</p>
  
  <p>My idea was to take the two's complement. However, that is 2 instructions:</p>
  
  <pre><code>## Calculate -13x with one additional instruction
  
  nor $11,$10,$0      # 
  addiu $11,$11,1     # flip bits and +1 to get two's comp?
  </code></pre>
  
  <p><strong>How can I compute -13x in one additional instruction?</strong></p>
  
  <p>I suppose this means my original 13x code is not good since it doesn't seem I can do this with only one instruction.</p>
  
  <p>I can think of 'dirty hacks' to do this but I don't think that is what the professor is looking for.</p>
  
  <p><strong>NOTE: I am only allowed use the following instructions:</strong></p>
  
  <pre><code>add     
  sll
  addi        
  addiu   
  addu        
  and
  andi        
  or      
  ori
  nor
  sub
  subu
  srl
  xor
  xori
  </code></pre>