我是第一次使用MIPS MARS用户并且不断收到此错误:
Error line 19: Runtime exception at 0x00400024: store address not aligned on word boundary 0x00000002
这是我正在使用的代码:
.data
str: .ascii "abcdefgh"
array: .space 20
.text
main:
li $s0, 1 # a = 1
li $s2, 1 # b = 1
loop:
la $t1, array
slti $t0, $s0, 3 # t0<- 1 if a < 3
beq $t0, $zero, exit
sll $t0, $s0, 2 # t1<- 4*a
add $t1, $t1, $t0 # new base addr
add $t2, $s2, $s0 # t2<- a+b
sw $t1, 0($t2) # D[a]=a+b
addi $s0, $s0, 1 # a = a +1
j loop # goes to loop: label
exit:
li $v0, 10 # v0<- (exit)
syscall
有人可以解释为什么会一直这样吗?
更新代码:
.data
str: .ascii "abcdefgh"
array: .space 20
.text
main:
li $s0, 1 # a = 1
li $s2, 1 # b = 1
loop:
la $t1, array
slti $t0, $s0, 3 # t0<- 1 if a < 3
beq $t0, $zero, exit
sll $t0, $s0, 2 # t1<- 4*a
add $t1, $t1, $t0 # new base addr
add $t2, $s2, $s0 # t2<- a+b
sw $t1, 2($t2) # D[a]=a+b
addi $s0, $s0, 1 # a = a +1
j loop # goes to loop: label
exit:
li $v0, 10 # v0<- (exit)
syscall
但现在我收到了这个错误:
line 19: Runtime exception at 0x00400024: address out of range 0x00000004
我该如何解决这个问题?
答案 0 :(得分:2)
单词必须位于4的倍数的地址;你正在使用一个(0x00000002
),而不是。{/ p>