In this project, an InputLoop is provided to read in a sequence of single-precis
ID: 3688365 • Letter: I
Question
In this project, an InputLoop is provided to read in a sequence of single-precision float-point numbers and you are required to add MIPS code to compute the SUM, MIN and MAX of these float-point numbers. The finished project4.asm should be filled with your MIPS code in the specified space, labels as Tasks in the comments: Task 1): Add MIPS code to decide whether the input number is 0.0, which indicates the end of the input numbers. In another words, if 0.0 is input, you need to jump out of the input loop. Note that 0.0 is not counted as an input number. Task 2): Write MIPS code in the loop to update SUM ($f4), MAX ($f5) and MIN ($f6) based on each new input. Sum is the summation, MIN is the minimum and MAX is the maximum. Note that the current code does not contain instructions to exit the loop. The code for printing out the SUM, MIN and MAX has been provided at the end of this project.
Explanation / Answer
.data
max: .word 3
min: .word 2
temp: .word 1
sum: .word 4
num: .space 96
input1: .asciiz "Enter a number with single-precision like 2.5,5.6: " #prints the statement
output1: .asciiz "Max number is "
output2: .asciiz " Min number is "
output3: .asciiz "sum is "
output4: .asciiz "The array contains the following: "
.text
.globl main
main:
lw $t1, temp # loop counter
lw $t2, max # upper bound
la $t0, num # address of array
la $s2, num # p = num
addi $s3, $s2, 24 # past_last = p + 6
lw $s0, ($s2) # sum = *p
lw $s1, num
while:
addi $s2, $s2, 4 # p++
beq $s2, $s3, endwhile # if (p == past_last) goto L2
lw $t0, ($s2) # $t0 = *p
lw $t1, -4($s2) # $t1 = *(p--)
slt $t2, $t1, $t0 # $t2 = 1 if (*p < *(p--)) else $t2 = 0
bne $t2, $zero, minimum # if ($t2 != 0) goto minimum
add $s0, $s0, $t0 # sum += $t0
j while
minimum:
move $s1, $t1 # min = $t1
j while
endwhile:
Loop:
# print input prompt
la $a0, input1
li $v0, 4
syscall
# get value from the user
li $v0, 6
syscall
# move user provided value from $f0 to array
s.s $f0, 0($t0)
# move to the next position in the array, increment loop counter
addi $t0, $t0, 4
addi $t1, $t1, 1
ble $t1, $t2, Loop
# restore loop counter, and array address for printing
lw $t1, temp
la $t0, num
# print output prompt
la $a0, output4
li $v0, 4
la $a0, output1
li $t2
la $a0, output2
li $s1
la $a0, output3
li $s0
syscall
print_loop:
# print number from the array
l.s $f12, 0($t0)
li $v0, 2
syscall
# print space
la $a0, 32
li $v0, 11
syscall
# increment loop counter and move to next value
addi $t1, $t1, 1
addi $t0, $t0, 4
ble $t1, $t2, print_loop
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.