main:
#prolog
push $ra
la $a0, array #v0 = sumOf(array,0,9);
li $a1, 0
li $a2, 9
jal sumOf
move $a0, $v0 #printf("%d",v0);
li $v0, 1
syscall
li $v0, 0
#epilog
pop $ra
jr $ra
#int sumOf(int a[], int lo, int hi)
#{
# if (lo > hi)
# return 0;
#
# else
# return a[lo] + sumOf(a,lo+1,hi);
#}
sumOf:
#prolog
push $ra
push $s0
push $s1
push $s2
ble $a1, $a2 else #if (lo <= hi) goto else
li $v0, 0
j end
else:
move $s0, $a0
move $s1, $a1
move $s2, $a2
addi $a1, $a1, 1 #a1 = lo+1
jal sumOf
li $t0, 4
mul $t0, $t0, $s1 #offset = lo * 4
add $t0, $t0, $s0 #offset = offset + a
lw $t1, ($t0) #a[lo]
add $v0, $v0, $t1 #returnValue = returnValue + a[lo]
end:
#epilog
pop $s2
pop $s1
pop $s0
pop $ra
jr $ra
.data
array:
.word 5, 4, 7, 6, 8, 9, 1, 2, 3, 0
C Function with No Parameters or Return Value