Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Do it Assignment Description: index Write a MIPS assembly language program that prompts for a user to enter a series of floating point numbers and

Do it

Assignment Description: index Write a MIPS assembly language program that prompts for a user to enter a series of floating point numbers and calls read float to read in numbers and store them in an array, then read in two indexes, and sort only floating numbers between these two indexes. Then the program should display the array content on the console window. Consult the green sheet and the chapter 3 for assembly instructions for floating point numbers. Here is one instruction that you might use: c.lt.s $f2, $f4 bc1t Label1 Here if the value in the register $f2 is less than the value in $f4, it jumps to the Label1. If it should jump when the value in the register $f2 is NOT less than the value in $f4, then it should be: c.ls.s $f2, $f4 bc1f Label1 To load a single precision floating point number (instead of lw for an integer), you might use: l.s $f12, 0($t0) To store a single precision floating point number (instead of sw for an integer), you might use: s.s $f12, 0($t0) To assign a constant floating point number (instead of li for an integer), you might use: li.s $f12, 123.45 To copy a floating point number from one register to another (instead of move for an integer), you might use: mov.s $f10, $f12 The following shows the syscall numbers needed for this assignment. System Call System Call System Call Number Operation Description 2 print_float $v0 = 2, $f12 = float number to be printed 4 print_string $v0 = 4, $a0 = address of beginning of ASCIIZ string 6 read_float $v0 = 6; user types a float number at keyboard; value is store in $f0 8 read_string $v0 = 8; user types string at keybd; addr of beginning of string is store in $a0; len in $a1 ------------------------------------------ C program will ask a user to enter numbers and store them in an array. It will also ask two indexes and it will sort numbers between two indexes. Then it prints out the result array content. You need to write MIPS assembly code based on the following C code. ------------------------------------------- void main( ) { int arraysize = 8; float array[arraysize]; int i, j, k, min, max; float num, num1, num2, temp; //The following loop reads in 8 floating point numbers //and stores them into the array i = 0; while (i < arraysize) { printf("Enter a number: "); //read an integer from a user input and store it in num1 scanf("%f", &num); array[i] = num; i++; } //Print out each number in the array printf("The original array contains the following: "); i = 0; while (i < arraysize) { printf("%f ", array[i]); i++; } //Read in two integers (indexes) printf("Please enter an index: "); scanf("%f", &num1); printf("Please enter another index: "); scanf("%f", &num2); //Deternine which integer is larger if (num1 < num2) { min = num1; max = num2; } else { min = num2; max = num1; } //If the smaller index is less than 0, //set the small index to be 0 if (min < 0) min = 0; //If the smaller index is larger than the last index of the array //set it to be the last index of the array if (min >= arraysize) min = arraysize-1; //If the larger index is less than 0, //set the larger index to be 0 if (max < 0) max = 0; //If the larger index is larger than the last index of the array //set it to be the last index of the array if (max >= arraysize) max = arraysize-1; //Sort only the floating point numbers between the indexes //min and max with the array. //The location of other elements in the array should not be changed. int minIndex; for (j = min; j <= max-1; j++) { minIndex = j; for (k = j+1; k <= max; k++) { if (array[k] < array[minIndex]) minIndex = k; } temp = array[minIndex]; array[minIndex] = array[j]; array[j] = temp; } //Print out the changed array elements printf("The result array contains the following: "); i = 0; while (i < arraysize) { printf("%f ", array[i]); i++; } return; } Here are sample outputs (user input is in bold): -- note that you might get some rounding errors. In that following example, only the number between the indexes 1 through 5 are sorted in their increasing order. Enter a number: 9.9 Enter a number: 8.8 Enter a number: 7.7 Enter a number: 6.6 Enter a number: 5.5 Enter a number: 4.4 Enter a number: 3.3 Enter a number: 2.2 The original array contains the following: 9.900000 8.800000 7.700000 6.600000 5.500000 4.400000 3.300000 2.200000 Please enter an index: 5 Please enter another index: 1 The result array contains the following: 9.900000 4.400000 5.500000 6.600000 7.700000 8.800000 3.300000 2.200000 -------------------------------------------- In that following example, since the indexes are from -12 to 4, it sorts number between 0 to 4 indexes with the array index. -------------------------------------------- Enter a number: -5.23 Enter a number: 3.5 Enter a number: 6.76 Enter a number: -6.54 Enter a number: -5.23 Enter a number: 6.1 Enter a number: 4.2 Enter a number: 6.1 The original array contains the following: -5.230000 3.500000 6.760000 -6.540000 -5.230000 6.100000 4.200000 6.100000 Please enter an index: -12 Please enter another index: 4 The result array contains the following: -6.540000 -5.230000 -5.230000 3.500000 6.760000 6.100000 4.200000 6.100000 ------------

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