且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MIPS循环遍历数组

更新时间:2023-10-30 22:47:16

v0。哪个将保持递增的值。当程序从数组中遇到值0时程序应该停止。



数组的前9个元素将从1到9开始,第十个元素是一个0.



另一个寄存器也将用于保存所有递增值的总和。



我也不能使用任何伪代码。



这是我到目前为止的代码



。数据

数组:

.word 1

.word 2

.word 3

.word 4

.word 5

.word 6

.word 7

.word 8

.word 9

.word 0

.text

lui
v0. Which will hold the incremented value. The program should stop when it encounters a value of 0 from the array.

The first 9 elements of the array will start from 1 up to 9, with the tenth being a 0.

Another register will also be used to hold the sum of all incremented values.

I can also not make use of any pseudo code.

This is the code i have so far

.data
array:
.word 1
.word 2
.word 3
.word 4
.word 5
.word 6
.word 7
.word 8
.word 9
.word 0
.text
lui


a0,0x1001 #load地址0x1001000数组到寄存器
a0, 0x1001 #load address 0x1001000 of the array into register


a0

jal increment #call程序

增量:

lw
a0
jal increment #call the procedure
increment:
lw