调用 sw 过程时地址超出范围

address out of range when calling sw procedure

我才刚刚开始学习 mip。我正在尝试编写一个将 3 个数字相加的简单程序。该程序应提示 3 次输入数字,然后输出总和。这是我写的

.data 
  instructions: .asciiz "Please enter a number : "
.text
  main: 
   li $t0, 0x00 # i = false
   li $t1, 0x00 #sum = 0

   while: # while(i < 3 )
     bgt $t0, 0x02, exit
     b prompt

   prompt:
     li $v0, 0x04 # set IO to output string
     la $a0, instructions #load the address of instructions into $a0 for IO
     syscall # print
     li $v0, 0x05
     syscall
     sw $v0, 0x0($t3) #address out of range 0x000000
     add $t1,$t1,$t2
     b while

   exit:
     li $v0,0x01
     move $a0, $t1
     syscall

错误发生在sw过程中。调试器告诉我 $t3 的值是我期望的 0,但我需要从 $v0 读取值并将其存储在 $t3 中。我确定这是我对 mips 不了解的地方。

sw 指令 ,不是程序。

不管怎样,sw的目的就是把一个寄存器的内容存入内存。在我看来你只是想将一个寄存器的内容复制到另一个寄存器,所以你应该使用的指令是 move:

move $t3,$v0    # $t3 = $v0

同样的事情可以通过其他几种方式实现,例如:

or $t3,$v0,$zero

但是如果您刚开始使用 MIPS 汇编,我建议您只使用 move