Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Make a bubble sort in MIPS using the following requirements 1.The array to be sorted will be stored in memory (hardcoded) using an assembler directive.

Make a bubble sort in MIPS using the following requirements

1.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

2.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 (see Hint 4 below) 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).

3.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.

4.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 registers (v0-v1). 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.

(Optional) Your program may print out the list at the end of each iteration so that the user can see the array as it is being sorted. If you make a subroutine to display the array (you need this for #6 anyway) it will make this simple.

Test your program using the following arrays:

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

Marketing Database Analytics

Authors: Andrew D. Banasiewicz

1st Edition

0415657881, 978-0415657884

More Books

Students also viewed these Databases questions

Question

Connect with your audience

Answered: 1 week ago