Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mips 错误存储地址在字边界上未对齐_Mips_Mars Simulator - Fatal编程技术网

Mips 错误存储地址在字边界上未对齐

Mips 错误存储地址在字边界上未对齐,mips,mars-simulator,Mips,Mars Simulator,我是MIPS MARS的第一次用户,不断出现以下错误: line 19: Runtime exception at 0x00400024: address out of range 0x00000004 错误行19:0x00400024处的运行时异常:存储地址未在字边界0x00000002上对齐 这是我正在使用的代码: .data str: .ascii "abcdefgh" array: .space 20 .text main: li $s0, 1 # a = 1 li $s2

我是MIPS MARS的第一次用户,不断出现以下错误:

line 19: Runtime exception at 0x00400024: address out of range 0x00000004

错误行19:0x00400024处的运行时异常:存储地址未在字边界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

如何解决这个问题?

单词必须位于4的倍数地址;您正在使用一个(
0x00000002
)但它不是。

这将有助于了解错误所指的指令。第19行:0x00400024处的运行时异常:地址超出已建立的范围0x00000004;哪一行是第19行?第19行是sw$t1,2$t2)#D[a]=a+b要确保汇编程序对齐
数组
,请将其放在
str
之前
str
有8个字符[使
array
word碰巧对齐]。如果
str
有(例如)9个字符,
array
将不对齐(即
sw$zero,array
将不对齐并崩溃)。我通常将所有需要对齐的数据首先放在
.data
段中,然后是
.ascii/.asciiz
。或者,将
.align 4
放在
数组前面:
line 19: Runtime exception at 0x00400024: address out of range 0x00000004