SumMain($a0: &X, $a1: N, $v0: Sum) Write a function to find the sum of the main diagonal elements in a two dimensional N by N array of 32-bit words. The address of the array and the size N are passed to the procedure in registers $a0 and $a1 respectively. The result is returned in $v0. The values in registers $a0 and $a1 should not be modified by this procedure. Calculate the number of clock cycles required to execute your algorithm, assuming N=4.
Solution
Screenshot

code
.text
summain:
lw $v0,
0($a0) # first element is 0
move $t1, $a0
addi $t3, $a1, 1 #
computing the offset
sll $t3, $t3, 2 #
multiply the value by 4
addi $t0, $a1, -1 #
initializing loop count
blez $t0, return
loop: add $t1, $t1, $t3 #
calculating the next address
lw $t2, 0($t1) # t2
equal to Mem(t1)
add $v0, $v0,
$t2 # adding the value to sum
addi $t0, $t0, -1 #
decrementing the loop count
bgtz $t0, loop
return: jr $ra
---
all the best
SumMain($a0: &X, $a1: N, $v0: Sum) Write a function to find the sum of the main...