title: Trouble with adding fractions in MIPS assembly language (Seg Fault)
body: <p>I am still very new to MIPS assembly language programming and am having some trouble. I have been tasked to create a Add function in MIPS assembly language that takes one ration number ($a0, $a1) and adds it to ($a2, $a3) using the rules of rational arithmetic. I am getting a seg fault and not sure why. This is what I currently have </p>
  
  <pre><code>rat_add:
  
  addiu $sp, $sp, -4  # create space on the stack for $sp 
  sw    $ra, ($sp)    # save $sp on the stack
  
  sw $t0, ($a1)     # Storing value in $a1(denominator of the first) into $t0
  sw $t1, ($a3)     # Storing value in $a3(denominator of the second) into $t1
  
  mul $a0, $a0, $t1 # $a0 *= $t1
  mul $a1, $a1, $t1 # $a1 *= $t1
  
  mul $a2, $a2, $t0 # $a2 *= $t0
  mul $a3, $a3, $t0 # $a3 *= $t0  
  
  add $v0, $a0, $a2 # $v0 = $a0 + $a2
  add $v1, $0, $a3  # Both denominators are the same, don't need to add them
  
  lw    $ra, ($sp)    # restore $sp from the stack 
  addiu $sp, $sp, +4  # release the stack space used for $sp
  
  jr $ra
  </code></pre>
  
  <p>I am not sure why I am getting this seg fault when I try to run the program. I am guessing it is coming from the stack pointer, but I did the samething for multiply and divide with not trouble. Any help or suggestions would be greatly appreciated. To better illustrate what I am try to do is 1/2 + 2/7 = 11/14</p>