MIPS程序,错误地址越界

MIPS program, error address out of bounds

我正在尝试使用 MARS 解决一个小作业问题,但我一直收到此错误。是不是我做错了什么?

我在第 11 行收到错误:lw $t0, 0

下面是我的程序代码。

.data

SOURCE: .word 0x0100
DEST: .word 0x0110




.text

lw $t0, 0
lw $t4 , -1 
lw $t5 , 0
lw $t6, 20
lw $t7, 32

VERY_START:

beq $t6,$zero,EXIT
addi $t6,$t6,-1
lw $t7,32

 la $t1,SOURCE
li $t2,1
li $s1,2


START:

and $t3, $t2 , $t1

beq $t4,-1,FIRST_LOOP


bne $t4,$t3,STORE
#bne is branch if not equal to.

add $t5 , $t5 , 1


addi $t7, $t7 , -1

beq $t7, $zero, VERY_START

# So we jump to the very start if we have 32 bits done.



sll  $t2, $t2 , 1

j START

STORE:



sb $t5,DEST($t2)
#dest needs to be defined (It is implicit according to the question)
# after storing , we need to increment $t0 so that we can store the next element a byte away from this one. so 
add $t0 , $t0 , 2



lw $t5,1

addi $t7, $t7 , -1

beq $t7, $zero, VERY_START

# So we jump to the very start if we have 32 bits done.



sll  $t2, $t2 , 1

j START

FIRST_LOOP:
# we populate t4 here
move $t4,$t3
j START


EXIT:
#we find the number of counts by simply dividing the current t0 with 2

div $t0, $s1
mflo $t0
# we move the quotient to t0..


move $a0,$t0
li $v0, 1
syscall

根据 this reference,您正在尝试使用 lw 将文字加载到寄存器中,这是不允许的:

RAM access only allowed with load and store instructions

您有两个选择:

选项 1

您可以从临时存储

加载到$t0
var1: .word 0       # declare storage for var1; initial value is 0

      .text

      lw $t0, var1 # load contents of RAM location into register $t0:  $t0 = var1
...

选项 2

您可以使用 li 使用文字值立即加载

      li $t0, 0    #  $t0 = 0   ("load immediate")

您的代码中有多处存在此问题。