该程序的目的是读取11个双打,将它们存储在一个数组中并计算平均值。这是代码:
.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
在“l.d $ f0,0”处,我得到运行时异常地址超出范围。想不通为什么!提前谢谢。
答案 0 :(得分:1)
l.d FRdest,地址
您传递0
作为地址......
尝试做:
li.d $f0, 0