Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.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 调用sw过程时地址超出范围_Mips - Fatal编程技术网

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

Mips 调用sw过程时地址超出范围,mips,Mips,我才刚刚开始学习mips。我试图写一个简单的程序,将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 prom

我才刚刚开始学习mips。我试图写一个简单的程序,将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
.data
说明:.asciiz“请输入一个数字:”
.文本
主要内容:
li$t0,0x00#i=false
li$t1,0x00#总和=0
while:#while(i<3)
bgt$t0,0x02,退出
b提示
提示:
li$v0,0x04#将IO设置为输出字符串
la$a0,指令#将指令地址加载到$a0中,用于IO
系统调用#打印
li$v0,0x05
系统调用
sw$v0,0x0($t3)#地址超出范围0x000000
添加$t1、$t1、$t2
b一会儿
出口:
li$v0,0x01
移动$a0,$t1
系统调用
该错误在sw过程中发生。调试器告诉我,
$t3
有一个我期望的值0,但我需要从
$v0
读取该值并将其存储在
$t3
中。我肯定这是我对mips不了解的地方

sw
是指令,而不是过程

无论如何,
sw
的目的是将寄存器的内容存储在内存中。在我看来,您只是想将一个寄存器的内容复制到另一个寄存器,因此您应该使用的指令是
move

move $t3,$v0    # $t3 = $v0
同样的事情也可以通过其他两种方式实现,例如:

or $t3,$v0,$zero
但如果您刚开始使用MIPS assembly,我建议您使用
move