【发布时间】:2016-04-24 21:04:35
【问题描述】:
我是 mips 新手,我想打印出 8 元素数组的最大值和最小值。我看到了一个类似于我的问题,但它是通过调用函数 readArray 完成的,我想不这样做。这是我到目前为止所拥有的。我只想知道我现在所拥有的是否正确以及如何结束循环。比如我写什么来打印正确的值
.data
X: .word 1, 2, 3, 4, 5, 6, 7, 8
globl main
.text
main:
la $t0, X
lw $s0, 0($t0) #Sets Max to first value in array
move $s1, $s0 #Sets Min to first value in array
addi $t1, $0, 0 #Sets the counter to 0
li $t1, 0 #Index for the array
loop:
bge $t0, 8 EndLoop
bgt X($t1), $s0, SetMax
blt X($t1), $s1, SetMin
addi $t1, $t1, 4 #Increases the index for the array
addi $t0, $t0, 1 #Increments the counter
SetMax:
move $s0, X($t1)
j loop
SetMin:
move $s0, X($t1)
j loop
EndLoop:
li $v0, 1
addi $s0, $s0, 0
addi $si, $s1, 0
syscall
我是不是做错了什么。这是原始问题: 编写 MIPS 代码以搜索数组 X[8] 字以找到最小值和最大值。将最大值存储在寄存器 $s0 中,将最小值存储在 $s1 中。打印到屏幕最小值和最大值。 感谢您的帮助!
【问题讨论】: