.text
.globl main
main:
subi $sp, $sp, 4
sw $ra, 0($sp) # Put return address on the bottom of the stack
subi $sp, $sp, 12 # 3 elements on the stack
la $t0, 0($sp) # Part of the dope vector - address of the array
li $t1, 3 # Might as well put the array length here too
li $s0, 1 # Put in registers...
li $s1, 3
li $s2, 5
sw $s0, 0($sp) # Push on stack...
sw $s1, 4($sp)
sw $s2, 8($sp)
subi $sp, $sp, 8 # Dope vector two words:
sw $t0, 0($sp)
sw $t1, 4($sp)
jal fee
lw $a0, 0($sp)
addi $sp, $sp, 4
li $v0, 1
syscall
li $v0, 10
syscall
fee:
li $t0, 0 # i
li $t1, 0 # sum
lw $t2, 4($sp) # n
lw $t3, 0($sp) # address
addi $sp, $sp, 16
b loop
loop:
li $t4, 4 # sizeof(int)
mult $t0, $t4
mflo $t6
add $t5, $t3, $t6
lw $t7, ($t5) # element = address + i * 4
add $t1, $t1, $t7 # sum = sum + element
addi $t0, $t0, 1 # i = i + 1
bne $t0, $t2, loop
# return sum
subi $sp, $sp, 4
sw $t1, 0($sp)
jr $ra
# Start .data segment (data!)
.data