assembly 提取地址未与MIPS中的字边界对齐

soat7uwm  于 2022-11-30  发布在  其他
关注(0)|答案(1)|浏览(143)
.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

很抱歉这里有这么多的代码,我得到的错误是在行l.s $f1,0($s0)我收到一个超出字边界的提取地址,在代码中,我将s0递增a2和a1的差值(按照每次分配的指示),然后将该值引用到f1中。我不明白为什么我会收到此行的错误,因为引用点位于0($s0)所以我认为它不会超出边界。感谢您提供的任何帮助。

2skhul33

2skhul331#

当我执行你的代码时,$a3的值为-1(0xffffffff),并且此值与$s0相加,导致$s0的值为0x 1000 ffff,该值不在字边界中。地址以mips为单位为4字节,如果您试图加载到不能被4整除的地址,则会出现边界错误。我没有看你完整的代码分配,但是,如果你试图使用地址,确保他们是递增和递减的数字,可被4整除。

相关问题