The point of this program is to read 11 doubles, store them in an array and compute the average value. Here is the code:
.include "../../ac1_macros.h"
.eqv size, 11
.data
.align 4
array: .double 0:size
str1: .asciiz "Insert 11 numbers: "
str2: .asciiz "Average: "
.text
.globl main
main:
addiu $sp, $sp, -4
sw $ra, ($sp)
la $t0, array
print_str(str1)
li $t1, 0
fill_array:
read_double()
s.d $f0, ($t0)
addi $t1, $t1, 1
addi $t0, $t0, 8 # proceed to the next element
bne $t1, size, fill_array
jal average
lw $ra, ($sp)
addiu $sp, $sp, 4
mov.d $f12, $f0
print_str(str2)
print_double_simple
jr $ra
average:
li $t2, 0
l.d $f0, 0
sum:
l.d $f2, array($t2)
add.d $f0, $f1, $f2
addi $t2, $t2, 1
blt $t2, size, sum
l.d $f3, size
div.d $f0, $f0, $f3
jr $ra
At "l.d $f0, 0" I get Runtime exception address out of range. Can't figure out why! Thanks in advance.