Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Input. txt contents: 18 9 27 5 48 16 2 53 64 98 49 82 7 17 53 38 65 71 24 31 please start

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Input. txt contents:

18 9 27 5 48 16 2 53 64 98 49 82 7 17 53 38 65 71 24 31

please start from instructions part
the input.txt is just to help
there is a sample for reference.
Thanks! :)
please use the sample output for reference
Objective: Gain more experience with MIPS programming in the context of a more complex problem. Big Picture: - read the input file "input.txt" into a buffer in memory - extract the string "numbers", convert them to integers and store in an array - print the integers to console - sort the integers in place using selection sort - print the sorted integers to console - calculate the mean, median, and standard deviation, printing results to the console Instructions The following lists and describes the functions you should write and call from the main program. 1. Write a function to read the text from the input file 'input.txt' (on Piazza) and place it in a buffer. A buffer of 80 bytes is more than enough. Before you call your function, set $a0 equal to the address of the filename and $a1 to the address of the buffer where data is stored. The function should return the number of bytes read in $v0. In the main program, print an error message and terminate the program if $v0 57 (ASCII for 9). If it is within this range, it is a digit. Subtract 48 to convert it from ASCII to int. Multiply the register you are using as an accumulator by 10, then add this new digit. When you load in a byte that is equal to 10, this is newline, so you are done with the integer you were converting; save the integer to the next array element. When you load a byte that is equal to 0 you have reached the end of the data. 3. Write a function to print the array of ints as shown in the sample output below. You will print the array before you call the sort, and after it is sorted, with appropriate text messages. 4. Write a function to sort the array by a selection sort. You can use the algorithm from any of your textbooks or Wikipedia: https://en.wikipedia.org/wiki/Selection sort In the remaining functions, before calling them, set $a0 to be the start of the array and $a1 to be the length of the array. Return integer values in $v0 and float values in one of the $f registers. 5. Write a function to calculate the mean. Use single precision for the mean. Store the mean in memory as a float. 6. Write a function to calculate the median. Write the function so that if the length is odd, it returns the middle value as an integer. If the length is even, average the two middle values and return the median as a float. Set $v1 to be a flag to indicate whether the result was int or float so that you can use the appropriate syscall in main to print the median. 7. Write a function to calculate the standard deviation using the formula below. Note that there is a sqrt.s instruction in MARS. From main, save the sd and print it. [ (1, -rang)? SD= - 1 What to turn in: Upload your.asm file to eLearning. If you use more than one .asm file, zip them together. 10 10 Grading Rubric: Points Element Function to read integers (string) from file into a buffer Function to convert string numbers to integers and store in an array Function to print array of ints 40 Function for selection sort Function to compute mean Function to compute median Function to compute standard deviation Appropriate print to console, similar to sample output below | 10 Comments, good use of whitespace 200 Total 20 30 10 Below is sample output showing the correct values for mean, median, sd. Sample output (no specific formatting of the output is required): The array before: 18 9 27 5 48 16 2 53 64 98 49 82 7 17 53 38 65 71 24 31 The array after: 25 7 9 16 17 18 24 27 31 38 48 49 53 53 64 65 71 82 98 The mean is: 38.85 The median is: 34.5 The standard deviation is: 27.686735 -- program is finished running -- Objective: Gain more experience with MIPS programming in the context of a more complex problem. Big Picture: - read the input file "input.txt" into a buffer in memory - extract the string "numbers", convert them to integers and store in an array - print the integers to console - sort the integers in place using selection sort - print the sorted integers to console - calculate the mean, median, and standard deviation, printing results to the console Instructions The following lists and describes the functions you should write and call from the main program. 1. Write a function to read the text from the input file 'input.txt' (on Piazza) and place it in a buffer. A buffer of 80 bytes is more than enough. Before you call your function, set $a0 equal to the address of the filename and $a1 to the address of the buffer where data is stored. The function should return the number of bytes read in $v0. In the main program, print an error message and terminate the program if $v0 57 (ASCII for 9). If it is within this range, it is a digit. Subtract 48 to convert it from ASCII to int. Multiply the register you are using as an accumulator by 10, then add this new digit. When you load in a byte that is equal to 10, this is newline, so you are done with the integer you were converting; save the integer to the next array element. When you load a byte that is equal to 0 you have reached the end of the data. 3. Write a function to print the array of ints as shown in the sample output below. You will print the array before you call the sort, and after it is sorted, with appropriate text messages. 4. Write a function to sort the array by a selection sort. You can use the algorithm from any of your textbooks or Wikipedia: https://en.wikipedia.org/wiki/Selection sort In the remaining functions, before calling them, set $a0 to be the start of the array and $a1 to be the length of the array. Return integer values in $v0 and float values in one of the $f registers. 5. Write a function to calculate the mean. Use single precision for the mean. Store the mean in memory as a float. 6. Write a function to calculate the median. Write the function so that if the length is odd, it returns the middle value as an integer. If the length is even, average the two middle values and return the median as a float. Set $v1 to be a flag to indicate whether the result was int or float so that you can use the appropriate syscall in main to print the median. 7. Write a function to calculate the standard deviation using the formula below. Note that there is a sqrt.s instruction in MARS. From main, save the sd and print it. [ (1, -rang)? SD= - 1 What to turn in: Upload your.asm file to eLearning. If you use more than one .asm file, zip them together. 10 10 Grading Rubric: Points Element Function to read integers (string) from file into a buffer Function to convert string numbers to integers and store in an array Function to print array of ints 40 Function for selection sort Function to compute mean Function to compute median Function to compute standard deviation Appropriate print to console, similar to sample output below | 10 Comments, good use of whitespace 200 Total 20 30 10 Below is sample output showing the correct values for mean, median, sd. Sample output (no specific formatting of the output is required): The array before: 18 9 27 5 48 16 2 53 64 98 49 82 7 17 53 38 65 71 24 31 The array after: 25 7 9 16 17 18 24 27 31 38 48 49 53 53 64 65 71 82 98 The mean is: 38.85 The median is: 34.5 The standard deviation is: 27.686735 -- program is finished running

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions