1
我正在嘗試使用程序集在數組中找到最大字數。我寫了以下內容,但似乎我的循環始終是分支。任何幫助表示讚賞!查找數組中的最大字(MIPS程序集)
解決方案是在評論,謝謝小丑
# find max from array
#
.data
array: .word 3, 4, 7, 6, 5
max: .word 0
.text
#
# -- register assignments --
# $2 = counter
# $3 = sum
# $6 = loop limit (20)
#
# counter = 0
and $2, $0, $0
# sum = 0
and $3, $0, $0
addi $6, $0, 20
loop:
# if array[i] < max save array[i] as max
lw $4, array($2)
ble $3, $4, incrementCount
move $3, $4
incrementCount:
# counter++
# (words are 4 bytes, so advance counter by 4)
addi $2, $2, 4
# if counter < 5, loop (really < 20)
blt $2, $6, loop
done: sw $3, max
'sw $ 3,($ 4)'應該是'move $ 3,$ 4',因爲$ 4不是地址。 – Jester
感謝您的糾正,我做了調整。它仍然看起來我的程序沒有分支 –
同樣你的分支是顛倒過來的,如果最大值小於當前值,則跳過。你如何通過調試器中的代碼? – Jester