Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with this MIPS problem. Please comment all code for better understanding Programming Problem Write a program in MIPS assembly for use in the

Need help with this MIPS problem. Please comment all code for better understanding

image text in transcribed

Programming Problem Write a program in MIPS assembly for use in the SPIM simulator. You will implement a "smart" bubble sort in accordance with the following pseudocode: Consider an unsorted array X with n elements Scan X[0], X[1], X[n-1], comparing adjacent elements (XIO] to X[1], X[1] to X[2], etc.) Swap the adjacent elements if they are out of order (e.g., if X[0] > X[1]) If no exchanges took place during the scan, the list has been sorted. Otherwise, scan XI0] through XIn-2] in the same manner as before (note: after each scan, we are scanning 1 element less!). Continue until no exchanges take place during a pass OR n-1 passes have been made. Requirements: Your code must be well-commented to receive full credit. This means any non-trivial ine of code should have an accompanying comment 1. 2. The array to be sorted will be stored in memory (hardcoded) using an assembler directive. The size of the array will also be stored in memory (hardcoded) via an assembler directive. Example Xarray: .word 14, -2, 3, 5, 9 Xsize: .word 5 3. You must use a sub-routine to implement a comparison function (i.e., to compare adjacent elements to see if a swap is needed). The sub-routine should take the addresses of the two items to compare as input parameters, perform the comparison, and return the result of the comparison. A 1 should be returned if the first element is greater than the second element (i.e., a swap is needed), and a 0 should be returned otherwise (i.e., no swap needed) 4. You must use a sub-routine to implement the swap functionality. The sub-routine should take the addresses of the two items to swap as input parameters, and perform the swap. The sub-routine will return nothing Note: you may do so, but you are not required to call the swap subroutine from the other subroutine both can be called from within loops in main Whichever method you choose, you must preserve the old return address across calls. a. 5. When writing sub-routines, you must follow MIPS register conventions. This means all input parameters must be passed using the argument registers (a0-a3) and all return values via the value return registv-). In addition, any callee-saved registers ($s registers) used must be saved to the stack and restored before return Your program should print the sorted list to the screen upon completion Test your program using the following arrays: 6. 7. 15, 5, -3, 8, 5,1 425, 94, 16 20, 19, 18, 17, 16,15

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

Knowledge Discovery In Databases

Authors: Gregory Piatetsky-Shapiro, William Frawley

1st Edition

0262660709, 978-0262660709

More Books

Students also viewed these Databases questions

Question

What has been your desire for leadership in CVS Health?

Answered: 1 week ago

Question

Question 5) Let n = N and Y Answered: 1 week ago

Answered: 1 week ago