Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Introduction to Computer Architecture. FOLLOW ALL DIRECTIONS AND USE THE TEMPLAT

ID: 3816183 • Letter: I

Question

Introduction to Computer Architecture. FOLLOW ALL DIRECTIONS AND USE THE TEMPLATE PROVIDED FROM THE FILE.

DO NOT COPY ANSWER FROM ANOTHER QUESTION.

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
prompt: .asciiz "Enter how many numbers: "
prompt2: .asciiz " Enter the flotaing point values: "
output: .asciiz " Floating Point Mean: "
summ: .asciiz " Floating Point Sum: "
min: .asciiz " Floating Point Min Value: "
space: .asciiz " "
newline: .asciiz " "

.text

main:
li $t0, 0 # counter for prompt


la $a0, prompt # Load address of prompt from memory into $a0
li $v0, 4 # Load Opcode: 4 (print string)
syscall # Init syscall

li $v0, 5 # Load Opcode: 5 (Read int)
syscall
move $t0, $v0 # Storing counter for number of iterations

mtc1 $t0, $f5
cvt.s.w $f5, $f5

inputLoop:
beq $t1, $t0, floatingPoint

la $a0, prompt2 # Load address of prompt from memory into $a0
li $v0, 4 # Load Opcode: 4 (print string)
syscall # Init syscall


li $v0, 5 # Load Opcode: 5 (Read int)
syscall
move $s1,$v0 # move input from $v0 to $s1

mtc1 $s1, $f1
cvt.s.w $f1, $f1
add.s $f2, $f2, $f1 # sum = sum + input


mov.s $f3, $f1 # min = input
mov.s $f4, $f1 # max = input
c.lt.s $f1, $f3
bc1t minRange
nop
  
next:

addi $t1, $t1, 1 #i++
j inputLoop

floatingPoint:

la $a0, summ # Load address of summ from memory into $a0
li $v0, 4 # Load Opcode: 4 (print string)
syscall # Init syscall
mov.s $f12, $f2
li $v0, 2
syscall

div.s $f6, $f2, $f5 # Calculate mean
  
la $a0, output # Load address of output from memory into $a0
li $v0, 4 # Load Opcode: 4 (print string)
syscall # Init syscall
mov.s $f12, $f6
li $v0, 2
syscall


la $a0, min # Load address of min from memory into $a0
li $v0, 4 # Load Opcode: 4 (print string)
syscall # Init syscall
mov.s $f12, $f3
li $v0, 2
syscall

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote