MIPS程序,错误地址超出范围

时间:2015-04-09 06:07:38

标签: mips

我正在尝试使用MARS解决一个小任务问题,但我不断收到此错误。有什么我做错了吗?

我在linenum 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

1 个答案:

答案 0 :(得分:1)

根据this reference,您尝试使用lw将文字加载到注册表中,这是不允许的:

  

RAM访问仅允许加载和存储指令

您有两种选择:

选项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")

您的代码中的多个位置都存在此问题。