0
我能夠獲得用戶輸入,如我的代碼所示,但我絕望地無法獲得最小的數字。 非常感謝...如何在不使用循環的情況下確定MIPS中三個整數的最小值
下面是對此的說明。
「編寫一個彙編程序,從用戶讀取三個32位有符號整數,確定這三個數中最小的一個並顯示此結果,不要使用循環,提示用戶輸入每個整數。
.data
Msg1: .asciiz "Enter the first integer: "
Msg2: .asciiz "Enter the second integer: "
Msg3: .asciiz "Enter the third integer: "
Msg4: .asciiz "the the smallest numberis: "
.text
# Print the first message
li $v0, 4
la $a0, Msg1
syscall
# Prompt the user to enter the first integer
li $v0, 5
syscall
# Store the first integer in $t0
move $t0, $v0
# Print the second message
li $v0, 4
la $a0, Msg2
syscall
# Prompt the user to enter the second integer
li $v0, 5
syscall
# Store the first integer in $t1
move $t1, $v0
# Print the third message
li $v0, 4
la $a0, Msg3
syscall
# Prompt the user to enter the third interger
li $v0, 5
syscall
# Store the first integer in $t0
move $t2, $v0
# Determine the smallest Number
slt $s0, $t1, $t0
beq $s0, $zero, L1
你還允許分支嗎?如果是這樣,有條件地跳過移動指令以獲得前兩個的最大值,然後再重新執行它是相當簡單的。否則,查找無分支最小/最大序列。 (如果MIPS具有'cmov',或者如果必須將其構建出SUB/SRA/AND,則爲IDK)。 –
你可以做兩個數字嗎?然後在你從兩個最小值開始,而不是打印結果再次從兩個最小值(從前一個結果到第三個值的最小值),而你從三個中的最小值。這只是幾行代碼。 – Ped7g
min(a,b,c)= min(min(a,b),c) – Tommylee2k