Mips指令码
我试图解决在mips中在数组中添加元素的问题。Mips指令码,mips,Mips,我试图解决在mips中在数组中添加元素的问题。 我必须插入NOP或重新排列代码,使其工作,但我不能。有人能提出一些想法吗。这是一种使用循环的方法,通过该方法可以遍历数组并计算其所有元素的总和: .data newline: .asciiz "\n" array: .word 1, 3, 5, 7, 9, 12, 14, 15, 17, 19 length: .word 10 sum: .word 0 .text .globl main ma
我必须插入NOP或重新排列代码,使其工作,但我不能。有人能提出一些想法吗。这是一种使用循环的方法,通过该方法可以遍历数组并计算其所有元素的总和:
.data
newline: .asciiz "\n"
array: .word 1, 3, 5, 7, 9, 12, 14, 15, 17, 19
length: .word 10
sum: .word 0
.text
.globl main
main:
#loop through the array to calculate sum
#array's starting address
la $t0 array
#loop index, i=0 ($t1=i)
li $t1 0
#loading the length of array in register t2
lw $t2 length
#initialise sum =0
li $t3 0
sumLoop:
#get array[i]
lw $t4 ($t0)
#sum = sum+array[i]
add $t3 $t3 $t4
#updating countervariable
addi $t1 $t1 1 #i = i+1
add $t0 $t0 4 #update array address
#while i<length , traverse the loop again
#blt (branch less than) (if $t1<$t2 then go through the loop)
blt $t1 $t2 sumLoop
sw $t3 sum #save sum
#printing the sum on syscall
move $a0 $t3
li $v0 1
syscall
li $v0 10
syscall
.end main
.data
换行符:.asciiz“\n”
数组:。字1、3、5、7、9、12、14、15、17、19
长度:。字10
总和:。字0
.文本
格洛博梅因酒店
主要内容:
#循环遍历数组以计算和
#数组的起始地址
la$t0阵列
#循环索引,i=0($t1=i)
李元10元
#加载寄存器t2中的数组长度
lw$t2长度
#初始化总和=0
李:30美元
sumLoop:
#获取数组[i]
lw$t4($t0)
#总和=总和+数组[i]
加上$t3$t3$t4
#更新反变量
addi$t1$t1 1#i=i+1
添加$t0$t0 4#更新数组地址
#当你需要在问题的主体中发布你的代码,而不是图片时,你会遇到什么错误?