.data
prompt: .asciiz "Enter in 3 integers, one per line, last one being a negative number: "
sum: .asciiz "The sum is: "
min: .asciiz "The minimum is: "
max: .asciiz "The maximum is: "
mean: .asciiz "The mean is: "
variance: .asciiz "The variance is: "
newline: .asciiz "\n"
count: .word 3
array: .space 12
.text
main:
#prints prompt msg
li $v0, 4
la $a0, prompt
syscall
#takes first integer from user and stores into $t1
li $v0, 5
syscall
move $t1, $v0
#takes second integer from user and stores into $t2
li $v0, 5
syscall
move $t2, $v0
#takes third integer from user and stores into $t3
li $v0, 5
syscall
move $t3, $v0
#min/max utilizing array
la $t0, array #initializing array at a[0]
li $t4, 0 #min
li $t5, 0 #max
li $t6, 0 #i
li $t7, 0
sw $t1, 4($t0) #user first input stored in a[1]
sw $t2, 8($t0) #user second input stored in a[2]
sw $t3, 12($t0) #user third input stored in a[3]
blt $t1, $t2, Else
ble $t1, $t3, Else2
j T1P
Else:
blt $t2, $t3, Else2
j T2P
Else2:
blt $t3, $t2, T3P
T1P:
move $a0, $t1
li $v0, 1
syscall
T2P:
move $a0, $t2
li $v0, 1
syscall
T3P:
move $a0, $t3
li $v0, 1
syscall
好的,我想做的是从三个用户输入的整数中找到最小值。
该程序将运行并允许用户输入他们的三个整数。
发生的事情是,不是打印出最小值,而是打印出所有三个值。
blt $t1, $t2, Else
ble $t1, $t3, Else2
j T1P
Else:
blt $t2, $t3, Else2
j T2P
Else2:
blt $t3, $t2, T3P
T1P:
move $a0, $t1
li $v0, 1
syscall
T2P:
move $a0, $t2
li $v0, 1
syscall
T3P:
move $a0, $t3
li $v0, 1
syscall
这是假设检查哪个值最小的代码部分,但事实并非如此。
我不明白为什么所有三个整数都打印出来。我认为我的错误检查会阻止打印所有三个整数。我在 QTSPIM 中运行这个程序。
示例:用户输入 4 、 3 和 2 作为他们的三个整数。控制台显示 4、3 和 2,而不是仅打印最小的 int。