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