Design write and test a program in MIPS using a procedure to
Design, write, and test a program in MIPS using a procedure to produce a sum of products. Similar to program 2, the program should request and reads the number of pairs to input. Iteratively reads each pair and place them into the appropriate array. Call the procedure which calculates the products of each pair and accumulates the result. Upon return from the procedure, the program should output the result.
Solution
procedure :
addi $sp,$sp,-8
# space on stack
sw $ra, 4($sp)
# save ret addr
sw $a1, 0($sp)
# save y
add $a1,$a0,$zero
# mult(x,x)
jal mult
# call mult
lw $a1, 0($sp)
# restore y
add $v0,$v0,$a1
# mult()+y
lw $ra, 4($sp)
# get ret addr
addi $sp,$sp,8
jr $ra //
we often use the instruction like this ...

