Question

Write a program in MIPS assembly language that implements the DESCENDING bubble sort algorithm to sort a variable-sized array of signed 32-bit integers

Write a program in MIPS assembly language that implements the DESCENDING bubble sort algorithm to sort a variable-sized array of signed 32-bit integers (words)that are read from the console. Be reminded that in a descending sort, the integers are sorted from the largest to the smallest. A “special value” 99999 will beused to signify the end of the input sequence. This value is not to be considered part of the input data set. However, any value greater than 99999 that is enteredprior to 99999 is considered as a valid input. Zero and negative values are also valid. Empty input sets are also valid. Your program must ask the user if he/shewants to input and sort another array of integers after finishing one round of input and sorting. If yes, then repeat the sort algorithm for the inputs. Use thefollowing algorithm, shown in Java-like syntax:

n=0;

read in;
while in != 99999 {
vals[n]=in;
n++;
read in;
}

for (i=0;i<n-1;i++) {
for (j=0;j<n-1;j++) {
if (vals[j] < vals[j+1]) {
// swap

temp=vals[j];
vals[j]=vals[j+1];
vals[j+1]=temp;
} } }

for (i=0;i<n;i++) {
print vals[i] }
// ask user if he wants to sort another sequence.
Use the following line to set up memory to hold the input:
.data
vals: .space 4000


Important Notes:

1. Program must compile
2. Test cases: Input
i. A descending sorted list
ii. An ascending sorted list
iii. Integers greater than 99999
iv. Negative numbers
v. Mixed- negative and positive
vi. The termination character 99999 is not part of output in any of the above cases
vii. Program asks for a new round of input and sorting.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
.data
vals: .space 4000
message1: .asciiz "Enter an integer: 9999 to exit n"
message2: .asciiz "The array contains the following: n"
next_line: .asciiz "n"

.text
.globl main
main:

la $a1, vals # $a1 is the base address of the array
li $a2, 9 # $a2 = 9;

li $t0, 0 # i = 0;
li $t1,9999
loop:
# cout << message1 << endl;
la $a0, message1
li $v0, 4
syscall
li $v0, 5
syscall
beq $v0,$t1,sort
addi $t0,$t0,4
sw $v0, ($a1)
addi $a1, $a1, 4 # move the array over by 1 element
j loop

sort:

la $t4, vals #t0 is number up to outter loop
la $t1, vals #t1 is number comparing to inner loop
addi $t1,$t1,4
la $t8,vals
add $t8,$t0,$t8
la $t9,vals
add $t9,$t0,$t9
addi $t9,$t9,-4
loops: lw $t2,($t4) #get number 1 outter loop
lw $t3,($t1) #get number 2 inner loop
blt $t2,$t3,next #don't need to swap
sw $t3,($t4) #swap
sw $t2,($t1)
next: addi $t1,$t1,4
blt $t1,$t8,loops #inner loop done?
addi $t4,$t4,4 #yes-increment outter loop
move $t1,$t4
addi $t1,$t1,4
blt $t4,$t9,loops #outter loop done?

printArray:
la $a1,vals

la $a0, message2
li $v0, 4
syscall
loop1:
blez $t0, done
li $v0, 1
lw $a0, 0($a1)
syscall
la $a0, next_line
li $v0, 4
syscall
addi $a1, $a1, 4
addi $t0, $t0, -4
j loop1
done:
j done
answered by: Benn
Add a comment
Know the answer?
Add Answer to:
Write a program in MIPS assembly language that implements the DESCENDING bubble sort algorithm to sort a variable-sized array of signed 32-bit integers
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • MIPS insertion sort program......could really use some assistance

    Write a program in MIPS assembly language that implements the DESCENDING insertion sort algorithm to sort a variable-sized array of signed 32-bit integers (words)that are read from the console. Be reminded that in a descending sort, the integers are sorted from the largest to the smallest. A “special value” 99999 will beused to signify the end of the input sequence. This value is not to be considered part of the input data set. However, any value greater than 99999 that...

  • MIPS insertion sort program......could really use some assistance

    Write a program in MIPS assembly language that implements the DESCENDING insertion sort algorithm to sort a variable-sized array of signed 32-bit integers (words)that are read from the console. Be reminded that in a descending sort, the integers are sorted from the largest to the smallest. A “special value” 99999 will beused to signify the end of the input sequence. This value is not to be considered part of the input data set. However, any value greater than 99999 that...

  • MIPS MIPS MIPS PLEASE INCLUDE COMMENTS AND OUTPUT Sort array using Bubble sort algorithm. 1) First...

    MIPS MIPS MIPS PLEASE INCLUDE COMMENTS AND OUTPUT Sort array using Bubble sort algorithm. 1) First ask the user how many elements of his/her array. 2) Then, read the integer array elements as input from the User. 3) Then, print out the array before the sorting 4) Apply Bubble sort algorithm on your array 5) Print out the array after the sorting 6) Print some welcome text to th user 7) Add comments to your code to describe how is...

  • Write a MIPS assembly language for sorting an array of integers using non-recursive bottom-up merge sort...

    Write a MIPS assembly language for sorting an array of integers using non-recursive bottom-up merge sort algorithm. Your program should print the processed array after each step of the merge sort. For example, if the input array is 14 27 13 11 49 63 17 9, your program should print each sort process: Input Arra;y 14 27 13 11 49 63 17 9 Print After first Iteration 14 27 11 13 49 639 17 Print After second iteration 11 13...

  • Run-able, Corrected source code The following code will sort an array in descending order. Keep it...

    Run-able, Corrected source code The following code will sort an array in descending order. Keep it as Descending. However it has two logic bugs. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /*    The sorting algorithm is to be left as descending    There are two logical bugs, the number do not sort correctly    Fix it    Add analysis output as per requirements */ #include <stdio.h> main() { char wait; short m[]={3,5,7,2,5,1,2,2,              6,5,7,2,4,1,3,3,              7,7,3,2,5,7,1,9}; unsigned char temp, i, j; unsigned char numElements =...

  • C programing Write a program to sort numbers in either descending or ascending order. The program...

    C programing Write a program to sort numbers in either descending or ascending order. The program should ask the user to enter positive integer numbers one at a time(hiting the enter key after each one) The last number entered by the user should be -1, to indicate no further numbers will be entered. Store the numbers in an array, and then ask the user how to sort the numbers (either descending or ascending). Call a function void sortnumbers ( int...

  • Objective: 1. Understand sorting algorithm 2. Implement bubble sort in C++ Check slides for a template...

    Objective: 1. Understand sorting algorithm 2. Implement bubble sort in C++ Check slides for a template of the solution, if you need Write a program that asks users to input 10 integers into an array, write a function that takes the array as its argument, use bubble sort to sort the array and output the sorted array in increasing order. #include <iostream> using namespace std; C:IWINDOWSSystems2cmd.exe lease input 10 integers: void bubblesort(int a[10]) int help; int b[10]; for (int i...

  • Write a program that sorts the given sequence of integers values using Select Sort algorithm. Structure of the program should be as follows: "The master" is responsible for communication with the user - input and output of the program. Sorting algorithm s

    Write a program that sorts the given sequence of integers values using Select Sort algorithm. Structure of the program should be as follows: "The master" is responsible for communication with the user - input and output of the program. Sorting algorithm should be implemented as a procedure called from the main module, let’s call it “Sort”. Then all swap operations should be performed by the procedure “Swap” called from procedure “Sort”.

  • Sorting Sort the following array using the quick sort algorithm: (4 Marks) a. 12 26 8...

    Sorting Sort the following array using the quick sort algorithm: (4 Marks) a. 12 26 8 9 7 0 4 Pivot selection is defined to be the first element of each sub-list. Show the array before and after each quicksort round (when the array is partitioned after placing the pivot at its correct position). Also, clearly highlight the pivot in each partition b. Consider an unsorted array of integers of size n. Write a Java program to arrange the array...

  • MIPS CODE required to write an assembly program to find the maximum of an array of integers by...

    required to write an assembly program to find the maximum of anarray of integers by doing the following:1. Prompt user to input array size n (n <= 10)2. Prompt user to input element values of array A one by one3. Display the result on the console.This program must at least include one function. The main program will read the valuesof the array (as user inputs the element values) and stores them in the memory (datasegments section) and at the end...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT