.data
prompt: .asciiz "Enter a number: "
newLine: .asciiz "\n"
max: .asciiz "\nYour max is: "
min: .asciiz "\nYour min is: "
theNumber: .asciiz "Entered \n"
average: .asciiz "\nThe average of max and min is: "
nums: .asciiz "\nNumbers >= than average: "
.text
main:
li $s1, 10
li $s0, 0
li $t0, -10000
li $t2, 10000
#while loop prompt for 10 numbers
while:
bgt $s0, $s1, out
li $v0, 4
la $a0, prompt
syscall
li $v0, 5
syscall
move $t1, $v0
jal compareMax
jal compareMin
addi $s0, $s0, 1
j while
#prints the max and min
out:
li $v0, 4
la $a0, max
syscall
li $v0, 1
move $a0, $t0
syscall
li $v0, 4
la $a0, min
syscall
li $v0, 1
move $a0, $t2
syscall
jal getAverage
#calculate the average
getAverage:
li $v0, 4
la $a0, average
syscall
add $t3, $t0, $t2
div $t3, $t3, 2
li $v0, 1
move $a0, $t3
syscall
#print all numbers greater or equal to average
GreaterEqualAvg:
li $v0, 4
la $v0, nums
jal compareAverage
#exit/end program
exit:
li $v0, 10
syscall
#print number
print:
li $v0, 4
la $a0, theNumber
syscall
li $v0, 1
move $a0, $t1
syscall
jr $ra
#compare and get max
compareMax:
bgt $t0, $t1, done
move $t0, $t1
#compare and get min
compareMin:
blt $t2, $t1, done
move $t2, $t1
done:
jr $ra
我已经完成了 90% 的获取 10 个数字、打印最小值和最大值、计算平均值的汇编代码。唯一缺少的是打印所有大于或等于平均值的数字。如果有人可以提供帮助,那就太好了!