Introduction to Computer Architecture. FOLLOW ALL DIRECTIONS AND USE THE TEMPLAT
ID: 3816181 • Letter: I
Question
Introduction to Computer Architecture. FOLLOW ALL DIRECTIONS AND USE THE TEMPLATE PROVIDED FROM THE FILE. DO NOT COPY AND PASTE FROM OTHER ANSWERS.
In this project, you are asked to write MIPS code to finish the tasks listed in project4.asm. In project4.asm, 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 Project4.asm.
A sample result:
--------------------------------------------
Input a Float-Point #:(0 indicates the end)
1.0
Input a Float-Point #:(0 indicates the end)
-1.0
Input a Float-Point #:(0 indicates the end)
2.0
Input a Float-Point #:(0 indicates the end)
-2.0
Input a Float-Point #:(0 indicates the end)
3.0
Input a Float-Point #:(0 indicates the end)
-3.0
Input a Float-Point #:(0 indicates the end)
0
MAX:3.0
MIN:-3.0
SUM:0.0
-- program is finished running --
---------------------------------------------
For project submission, please submit your completed project4.asm and make sure it can be compiled and executed in Mars.
project4.asm reads as:
.data
FPNum: .word 0x0, 0xff800000, 0x7f800000 # Float-point numbers 0, -Infty and Infty
string1: .asciiz "Input a Float-Point #:(0 indicates the end) "
string2: .asciiz " MAX:"
string3: .asciiz " MIN:"
string4: .asciiz " SUM:"
.text
main:
la $t0, FPNum
lwc1 $f10, ($t0) # $f10=0.0
lwc1 $f4, ($t0) # SUM =0
lwc1 $f5, 4($t0) # MAX=-InftY
lwc1 $f6, 8($t0) # MIN=Infty
addi $s1, $zero, 0 # FP number counts in array
# Input a number
InputLoop: addi $v0, $zero, 4 # code for printing string is 4
la $a0, string1 # load address of string to be printed into $a0
syscall # call operating system
addi $v0, $zero, 6 # code for reading FP number is 6
syscall # call operating system
add.s $f1, $f0, $f10 # move input fp number to $f1
# Tasks:
# 1) Add MIPS code to decide whether the input number is 0.0,
# which indicates the end of input FP numbers and jump out of the InputLoop
#(Currently there is no code to exit the loop)
# 2) Write MIPS code here to update SUM ($f4), MAX ($f5) and MIN ($f6)
addi $s1, $s1, 1
j InputLoop
# Print out the values of MAX, MIN, and SUM
Exit: addi $v0, $zero, 4 # code for printing string is 4
la $a0, string2 # load address of string to be printed into $a0
syscall # call operating system
addi $v0, $zero, 2 # code for printing FP number is 2
add.s $f12, $f5, $f10
syscall # call operating system
addi $v0, $zero, 4 # code for printing string is 4
la $a0, string3 # load address of string to be printed into $a0
syscall # call operating system
addi $v0, $zero, 2 # code for printing FP number is 2
add.s $f12, $f6, $f10
syscall # call operating system
addi $v0, $zero, 4 # code for printing string is 4
la $a0, string4 # load address of string to be printed into $a0
syscall # call operating system
addi $v0, $zero, 2 # code for printing FP number is 2
add.s $f12, $f4, $f10
syscall # call operating system
addi $v0, $zero, 10
syscall
Explanation / Answer
.data FPNum: .word 0x0, 0xff800000, 0x7f800000 # Float-point numbers 0, -Infinity and Infinity string1: .asciiz "Input a Float-Point #:(0.0 indicates the end) " string2: .asciiz " MAX:" string3: .asciiz " MIN:" string4: .asciiz " SUM:" .text main: la $t0, FPNum # load address of FPNUM to $t0 lwc1 $f10, ($t0) # load FP 0x0 to $f10 lwc1 $f4, ($t0) # load FP 0x0 to $f4 (SUM) lwc1 $f5, 4($t0) # load FP 0xff800000 to $f5 (MAX) lwc1 $f6, 8($t0) # load FP 0x7f800000 to $f6 (MIN) addi $s1, $zero, 0 # counter at $s1 is 0 # Input a number InputLoop: addi $v0, $zero, 4 # code for printing strings (4) la $a0, string1 # load address of string printed to $a0 syscall # call operating system addi $v0, $zero, 6 # code for reading FP numbers (6) syscall # Task #1 add.s $f1, $f0, $f10 # move input fp number to $f1 c.eq.s $f1, $f2 # compare if $f1 == $f2 (0) bc1t ExitLoop # if $f1 == $f2, ExitLoop # End Task #1 # Task #2 c.lt.s $f1, $f6 # compare if $f1 < $f6 (MIN) bc1t ChangeMin c.lt.s $f5, $f1 # compare if $f5 (MAX) < $f1 bc1t ChangeMax ChangeMax: add.s $f5, $f10, $f1 # $f5 (MAX) == $f1 add.s $f4, $f4, $f1 # $f4 (SUM) += $f1 addi $s1, $s1, 1 # counter += 1 j InputLoop ChangeMin: add.s $f6, $f10, $f1 # $f6 (MIN) == $f1 add.s $f4, $f4, $f1 # $f4 (SUM) += $f1 addi $s1, $s1, 1 j InputLoop # End Task #2 # Print out the values of MAX, MIN, and SUM ExitLoop: addi $v0, $zero, 4 la $a0, string2 syscall addi $v0, $zero, 2 # code for printing FP numbers (2) add.s $f12, $f5, $f10 syscall addi $v0, $zero, 4 la $a0, string3 syscall addi $v0, $zero, 2 add.s $f12, $f6, $f10 syscall addi $v0, $zero, 4 la $a0, string4 syscall addi $v0, $zero, 2 add.s $f12, $f4, $f10 syscall addi $v0, $zero, 10 syscallRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.