title: Sum of two numbers in MIPS
body: <p>I'm trying to practice my coding skill in MIPS (this is my first time ever learning an assembly language).  I wrote this code below to sum up two user's inputs, and it is correct. However, the code is quite long..so, is there any way to optimize this code so it will be shorter? i need some suggestions. Thanks</p>
  
  <pre><code>.data
      n1: .asciiz "enter your first number: "
      n2: .asciiz "enter your second number: "
      result: .asciiz "result is "
  
  .text
      #getting first input.
      la $a0, n1
      li $v0, 4
      syscall
      li $v0, 5
      syscall
      move $t0, $v0
  
      #getting second input.
      la $a0, n2
      li $v0, 4
      syscall
      li $v0, 5
      syscall
      move $t1, $v0
  
      #calculate and print out the result.
      la $a0, result
      li $v0, 4
      syscall
      add $t3, $t0, $t1
      move $a0, $t3
      li $v0, 1
      syscall
  
      #end program.
      li $v0, 10
      syscall
  </code></pre>
  
  <p>I also have wrote a program to calculate a factorial number.  There are better ways to do this?</p>
  
  <pre><code>.data
   str: .asciiz "Enter a number: "
   result: .asciiz "The result is: "
  
  .text
   la $a0, str
   li $v0, 4
   syscall
   li $v0, 5
   syscall
   move $s0, $v0 # move N into s0     
   li $s2, 1 # c = 1
   li $s1, 1 # fact = 1
  
   LOOP:
   blt $s0, $s2, PRINT # if (n &lt; c ) print the result
   mul $s1, $s1, $s2 # fact = fact * c
   add $s2, $s2, 1 # c = c + 1
   j LOOP
  
   PRINT:
   la $a0, result
   li $v0, 4
   syscall
   add $a0, $s1, $zero
   li $v0, 1
   syscall
   li $v0, 10
   syscall
  </code></pre>