title: MIPS function inside a function
body: <p>I am trying to have the function vbsme call another function called sad... is the following procedure correct about saving the registers and return address?? the caller is supposed to save register $t0-$t7, but where and how should I do that?   </p>
  
  <pre><code>vbsme: li $v0, 0   # reset $v0 
       li $v1, 0   # reset $v1
       li  $t0, 1   # i(row) = 1 
       li  $t1, 1   # j(col) = 1
       lw  $t2, 0($a0)  # row size
       lw  $t3, 4($a0)  # col size
       mul  $t4, $t2, $t3  # row * col
       li  $t5, 0   # element = 0
      loop:   bgeq  $t5, $t4, exit  # if element &gt;= row * col then exit
  
       addi $sp, $sp, -16  # create space on the stack pointer
       sw $ra, -12($sp)  # save return address
       sw $s6, -8($sp)  # save return address
       sw $s7, -4($sp)  # save return address
       subi $s7, $t0, 1  # 1st parameter: i-1
       subi $s6, $t1, 1  # 2nd parameter: j-1
       jal  sad   # calculate the sum of absolute difference using the frame starting from row a0 and col a1
       lw $ra, -12($sp)  # restore return address
       lw $s6, -8($sp)  
       lw $s7, -4($sp)
       addi $sp, $sp, 16  # restore stack pointer
       jr $ra
  </code></pre>