简体   繁体   English

我的MIPS汇编程序有什么问题?

[英]What is wrong with my MIPS assembly program?

I'm trying to create a program that loops through an array to reach the final value of 0. 我正在尝试创建一个程序,该程序循环访问数组以达到最终值0。

While going through each element in the array, I need to increment the value by 2 and store the final result in $v0. 在遍历数组中的每个元素时,我需要将值增加2并将最终结果存储在$ v0中。 (I have no idea how to do this) (我不知道该怎么做)

Here is my code so far: 到目前为止,这是我的代码:

.data  
list: .word 1, 2, 3, 4, 5, 6, 7, 8, 9, 0

.text 

li  $s0, 0x10010000          

increment:         
beq $s0, $zero, EndLoop      
lw $s1, 0($s2) 
sw $s1, 0($s2) 
la $s2, list 
la $s1, list   
lb $s2, 0($s1)           
addi $s2, $s2, 2         
sb $s2, 0($s1)           
addi $s1, $s1, 1         

j increment                

EndLoop: 

My questions are: 我的问题是:

I Keep getting an error saying runtime exception, address out of range. 我不断收到一条错误消息,指出运行时异常,地址超出范围。 Any idea why? 知道为什么吗?

Could anyone point me in the right direction about storing the final values in $v0? 有人能指出我将最终值存储在$ v0中的正确方向吗?

I Keep getting an error saying runtime exception, address out of range. 我不断收到一条错误消息,指出运行时异常,地址超出范围。 Any idea why? 知道为什么吗?

Sure, here: 当然可以,在这里:

.text 

li  $s0, 0x10010000          

increment:         
beq $s0, $zero, EndLoop      
lw $s1, 0($s2)

Problems: 问题:

  1. You don't seem to define where your program is supposed to start its execution. 您似乎没有定义程序应该在哪里开始执行。 I'd expect some label at the beginning of the code, but I'm seeing nothing. 我希望在代码的开头有一些标签,但是什么也没看到。 Is the relevant part simply not shown in the question? 问题中是否根本没有显示相关部分?

  2. Your code is attempting to read from a memory location whose address is contained in register s2 , however your code does not initialize this register. 您的代码正试图从其地址包含在寄存器s2的内存位置中进行读取,但是您的代码并未初始化该寄存器。

  3. Also, you never modify s0 , so the loop is hopelessly endless. 而且,您永远不会修改s0 ,因此循环是无穷无尽的。

Could anyone point me in the right direction about storing the final values in $v0? 有人能指出我将最终值存储在$ v0中的正确方向吗?

I see no problem with storing anything in v0 . 我认为在v0存储任何内容都没有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM