MIPS中读取地址与字边界不对齐


.data
vector_A: .float 5.2, 7.1, 2.0      
vector_B: .float 15.4, 3.5, 11.5

result: .float 0.0, 0.0, 0.0
.text
li $t0, 0   #initialize i
la $s2, result  #equivalent to *s0=&result[0]; in C

##################################################################################
#write code to load each element from array vector_B, scale by Co-factor= 0.8,   #
# and then store back at the corresponding original memory adresses of vector_B  #
##################################################################################


##########################################################################
loop:
###################################################
la $s0 vector_A  #load starting address of array vector_A into s0 #
la $s1, vector_B    #load starting address of array vector_B into s1 #
###################################################  
bge $t0, 3, print
#STEP 1:
#implement if statements
#recommended method as follows:
#set $t_ equal to 1 if $t0=1 else set to 0 #hint:may use seq
seq $t1, $t0, 1
#set $t_ equal to 1 if $t0=2 else set to 0
seq $t1, $t0, 2
#set $t_ equal to 1 if $t0=3 else set to 0
seq $t1, $t0, 3
beqz $t1, skip1
#set j and k
skip1:
li $a1, 1
li $a2, 2
beq $t0, 1 skip2
skip2:
li $a1, 0
li $a2, 2
beq $t0, 2 skip3
skip3:
li $a1, 0
li $a2, 1
################################################################
#Similarly set the if, else conditions for the other two       #
#conditions of j, k as in the C code using different labels    #
################################################################

#STEP 2:
#load the two numbers from arrays vector_A and vector_B into coprocessors (i.e. floating point registers)
sub $a3, $a1, $a2 #use this as k index
add $s0, $s0, $a1
l.s $f0, 0($s0)
add $s0, $s0, $a3
l.s $f1, 0($s0)
#do previous 4 instructions again but for $s1 (array_B)
add $s1, $s1, $a1
l.s $f2, 0($s1)
add $s1, $s1, $a3
l.s $f3, 0($s1)

#STEP 3:
#perform the math
mul.s $f10, $f0, $f3
mul.s $f11, $f1, $f2
sub.s $f15, $f10, $f11

#FINAL STEP:
#store the results into the results array
s.s $f15, result 
addi $s2, $s2, 4 #increment results register to the next index

对不起,这里有多少代码,我得到的错误是在行$ 1, 0($ 50)我接收到一个取地址超出字界,在代码中,我通过a2和a1的差值增加了50(按照每次赋值的指示),然后将该值引用到f1中。我不明白为什么我收到这一行的错误,因为参考点是0($ 50),所以我认为它不能超出边界。您能提供的任何帮助我都很感激,谢谢。

当我执行你的代码时,$a3的值为-1 (0xffffffff),这个值与$ 50一起增加,导致$ 50的值为0x1000ffff,不在字边界内。地址在MIPS中是4个字节,如果你试图加载一个不能被4整除的地址,你会得到边界错误。我没有看你完整的代码分配,但是如果你试图使用地址,请确保它们是由能被4整除的数字递增和递减的。

最新更新