我是MIPS的新手,正在学习基础知识。我已经工作了两个小时,没有运气,遇到了一个问题。我尝试在线搜索此问题,但样本非常有限。所以基本上我在写两个函数:
以下是我的代码:
##
.data
A: .word 11, 12, -10, 13, 9, 12, 14, 15, -20, 0
out_m: .asciiz "The maximum of A is : "
out_s: .asciiz "The summation of A is : "
out_n: .asciiz "\n"
.text
main:
la $a3, A
jal sumArray
li $v0, 4
la $a0, out_n
syscall
jal findMax
li $v0, 10
syscall
findMax:
add $t0, $zero, $a3
lw $t8, ($t0)
addi $t1, $zero, 0
add $t3, $zero, $a0
L1: slti $t2, $t1, 10
beq $t2, $zero, Loop2
lw $t4, 0($t3)
addi $t3, $t3, 4
slt $t2, $t0, $t4
addi $t1, $zero, 1
beq $t2, $zero, Loop3
j L1
Loop3: add $t8, $zero, $t4
j L1
Loop2: li $v0, 4
la $a0, out_m
syscall
move $t3, $v0
li $v0, 1
move $a1, $t0
syscall
jr $ra
sumArray:
addi $t0, $zero, 0
addi $t6, $zero, 0
add $t5, $zero, $zero
loop: slti $t1, $t0, 9
add $t2, $a3, $t6
beq $t1, $zero, $L
lw $t4, 0($t2)
add $t5, $t5, $t4
addi $t0, $t0, 1
addi $t6, $t6,4
j loop
$L:
li $v0, 4
la $a0, out_s
syscall
move $t5, $v0
li $v0, 1
move $a1, $t0
syscall
jr $ra
## end of file
抱歉,代码混乱,我尝试进行适当的格式化。任何帮助将不胜感激。