In: Computer Science
Write a complete MiniMIPS program that accepts a seqeunce of
integers at input and after the receipt of each new input value,
displays the largest and smallest integers thus far.
An input of 0 indicates the end of input values and is not an input
value itself.
Note that you do not need to keep all integers in memory.
Program:
.data
stmt: .asciiz "\nEnter a number: "
stmt1: .asciiz "maximum number: "
stmt2: .asciiz "\nminimum number: "
newline: .asciiz "\n"
.text
.globl main
main:
li $s0,0 #max = 0
li $s1,9999999 #initialize min
li $t0,1 #number
loop: la $a0, stmt # load address of stmt for syscall
li $v0, 4 # specify Print String service
syscall
li $v0,5 #read integer
syscall
move $t0,$v0
beqz $t0,end
bge $t0,$s0,updateMax
ble $t0,$s1,updateMin
j printVal
updateMax: move $s0,$t0
ble $t0,$s1,updateMin
j printVal
updateMin: move $s1,$t0
j printVal
printVal: la $a0, stmt1 # load address of stmt for syscall
li $v0, 4 # specify Print String service
syscall
move $a0,$s0
li $v0,1
syscall
la $a0, stmt2 # load address of stmt for syscall
li $v0, 4 # specify Print String service
syscall
move $a0,$s1
li $v0,1
syscall
la $a0, newline # load address of stmt for syscall
li $v0, 4 # specify Print String service
syscall
j loop
end: li $v0,10
syscall
Output: