Question
Introduction to Computer Architecture. Please follow all directions as written. Do no copy answers from other questions for they are not correct. USE FLOATING POINT
Introduction to Computer Architecture. Please follow all directions as written. Do no copy answers from other questions for they are not correct. USE FLOATING POINT INTEGERS.
Project 5 In this project, you are asked to write MIPS code to sort a set of input floating-point numbers in an ascending order. You can implement any sorting algorithm you select (or invent) only if it produces correct results. You may refer to Project 4 for reading and printing floating-point numbers. However, for this project, you need to write all the code from the beginning to the end, including the .data and .text segments. In particular, you need to allocate data space to store the input sequence of floating-point numbers and sort them. Same as in Project 4, input number 0.0 indicates the end of the input numbers and it is not counted as an input number. 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 Sorting Result -3.0, -2.0, -1.0, 1.0, 2.0, 3.0 -- program is finished running -- --------------------------------------------- For project submission, please submit your code in the name of project5.asm and make sure it can be compiled and executed in Mars.
PROJECT 4 REFERENCE:
USE THIS AS TEMPLATE. Feel free to change this code to fit the description of directions.
.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) c.eq.s $f1, $f2 #compare equal single precision if $f1 == $f2 (0) bc1t Exit # 2) Write MIPS code here to update SUM ($f4), MAX ($f5) and MIN ($f6) c.lt.s $f1, $f6 #compare less than single precision if $f1 < $f6 (min) bc1t MinChange c.lt.s $f5, $f1 #compare less than single precision if $f5 (Max) < $f1 bc1t MaxChange MaxChange: add.s $f5, $f10, $f1 #max == $s1 add.s $f4, $f4, $f1 #sum += $f1 addi $s1, $s1, 1 #counter += 1 j InputLoop
MinChange: add.s $f6, $f10, $f1 #Min == $f1 add.s $f4, $f4, $f1 #sum += $f1 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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started