3
我是mips的新手,我想打印出8個元素數組的最大值和最小值。我看到一個類似於我的問題,但它是通過調用一個函數readArray來完成的,我希望沒有這樣做。這是迄今爲止我所擁有的。我只想知道我現在擁有的是否正確以及如何結束循環。像我寫什麼打印正確的值如何在Mips中打印出數組的最大值和最小值
.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中。打印至最小和最大畫面。 感謝您的幫助!
感謝您如何結束循環的幫助。現在有什麼語法錯誤或任何東西。我只是想知道你的想法,或者如果你看到代碼有問題。 – JX30
好吧,一切都很好,如果你想得到你想要的結果,那麼你只需要在最後刪除兩個'addi'。你不需要它們。 – Segmentation