Question

Objective Create a MIPS program in Mars to perform a sorting algorithm. Specification: 1) Download the...

Objective

Create a MIPS program in Mars to perform a sorting algorithm.

Specification:

1) Download the file Assign2.asm. Read it and make sure it can be compiled and executed in Mars.
2) Write code to finish all the tasks listed in Assign2.asm. In Assign2.asm, an array‘a’ of ‘n’=11 integers are given at the beginning (make sure do not change these integers):

43, -5, 11, 12, 64, -7, 14, 71, 70, 13, -27

The finished Assign2.asm should be filled with your MIPS code in the specified space to implement the given C code for Selection Sort:

for (int i=0; i<n-1; i++){ for(int j=i+1; j<n; j++){

if a[i] > a[j]{
int temp = a[i]; a[i] = a[j];
a[j] = temp;

} }

}

Here is an example output: -------------------------------------------- -27
-7
-5
11
12
13
14
43
64
70
71 ---------------------------------------------

Some code has been provided in Assign2.asm. All the needed strings have been defined at the beginning of Assign2.asm. Please read the comments carefully before you work on this project.

Please submit your completed Assign2.asm with the added code via Blackboard. Make sure the submitted MIPS code is fully tested in Mars and can be compiled and run. The instructor might change numbers in the array a to test your submitted code.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the code below:::

.data
Array: .word 43, -5, 11, 12, 64, -7, 14, 71, 70, 13, -27
string: .asciiz "\n"

# Tranfer the C code of selection sort to MIPS code. Do not modify the existing code and structure!

.text
main:
la $t0, Array
li $t1, 0
li $t7,11 # array length n=11
mul $t7, $t7, 4 # 4*n
subi $t8, $t7, 4 # 4*(n-1)

OuterLoop:
# write your code here for Selection Sort
addi $t2,$t1,4 #initialize j to i+1
InnerLoop:

add $s0,$t0,$t1 #load address of a[i]
add $s1,$t0,$t2 #load address of a[j]
lw $s2,($s0)# load a[i]
lw $s3,($s1)# load a[j]
bgt $s2,$s3,swap
j exit
swap:
sw $s2,($s1)# load a[i]
sw $s3,($s0)# load a[j]

exit:


  
add $t2, $t2, 4 # i is in $t1 and j is in $t2
blt $t2,$t7,InnerLoop
  
add $t1, $t1, 4 # i is in $t1 and j is in $t2
blt $t1,$t8,OuterLoop
# write your code here to print the sorted array/result

li $t1,0 #initialize j to 1
printLoop:
add $s0,$t0,$t1 #load address of a[i]
lw $s0,($s0)
li $v0,1
move $a0,$s0
syscall

li   $a0, '\n'       # Print of str3
li   $v0, 11
syscall


add $t1, $t1, 4
ble $t1,$t8,printLoop
# exit
addi $v0, $zero, 10
syscall

Add a comment
Know the answer?
Add Answer to:
Objective Create a MIPS program in Mars to perform a sorting algorithm. Specification: 1) Download the...
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
  • Transfer C code of selection sort to MIPS code and print the sorted array/results

    Transfer C code of selection sort to MIPS code and print the sorted array/results data Array: word 43, -5, 11, 12, 64, -7, 14, 71, 70, 13, -27 string: asciz"In" # Trantec the C code of selection sort to MIPS code. Do not modify the existing code and structure! text main la ŞtO, Array li $t1, 0 li $t7,11 mul $17, $17, 4 subi $t8,$t7, 4 # array length n-11 # 4*n #4*(n-1) # lis in $t1 and j is...

  • Transfer C code of selection sort to MIPS code and print the sorted array/results data Array:...

    Transfer C code of selection sort to MIPS code and print the sorted array/results data Array: word 43, -5, 11, 12, 64, -7, 14, 71, 70, 13, -27 string: asciz"In" # Trantec the C code of selection sort to MIPS code. Do not modify the existing code and structure! text main la ŞtO, Array li $t1, 0 li $t7,11 mul $17, $17, 4 subi $t8,$t7, 4 # array length n-11 # 4*n #4*(n-1) # lis in $t1 and j is...

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

  • Selection sort is often the first sorting algorithm covered in introductory computer science courses. Java code...

    Selection sort is often the first sorting algorithm covered in introductory computer science courses. Java code that uses selection sort to place the elements of an integer array into non-decreasing order is shown here: public void swapNumbers(int i, int j) { ​int temp = numbers[i];​ /* put numbers[i] somewhere to keep it safe */ ​numbers[i] = numbers[j]; /* put numbers[j] at index i */ ​numbers[j] = temp;​ /* put numbers[i] at index j */ } public void selectionSort(int[] numbers) {...

  • How can I convert the following C code to MIPS Assembly? +++++++++++++++++++++++++++++++++ MIPS main program ++++++++++++++++++++++++++++++++...

    How can I convert the following C code to MIPS Assembly? +++++++++++++++++++++++++++++++++ MIPS main program ++++++++++++++++++++++++++++++++ .data # Defines variable section of an assembly routine. array: .word x, x, x, x, x, x, x, x, x, x # Define a variable named array as a word (integer) array # with 10 unsorted integer numbers of your own. # After your program has run, the integers in this array # should be sorted. .text # Defines the start of the code...

  • Hello, I need help with my code. The code needs to display random number from 1...

    Hello, I need help with my code. The code needs to display random number from 1 to 50 every time the program runs but the program displays the same random numbers every time. Thanks #include #include using namespace std; void dynAlloc(int size, int *&arr); void displayArray(int *arr, int n); void insertionSort(int *arr, int n, int *temp); void linear_search(int *arr, int n, int key); void binary_search(int *arr, int n, int key); int main() {   const int n = 50; int *arr,...

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

  • Consider the following attempt at a selection sort algorithm implementation in Java: 1 public static void...

    Consider the following attempt at a selection sort algorithm implementation in Java: 1 public static void selectionSort(int[] a) { 2 int n = a.length; 3 for (int i = 0; i < n - 1; i++) { 4 int smallest = i; 5 for (int j = 1; j < n; j++) { 6 if (j < smallest) { 7 smallest = j; 8 } 9 } 10 if (i != smallest) { 11 int temp = a[smallest]; 12 a[smallest]...

  • Objective: GUI Layout manager Download one of the sample GUI layout program. Use any GUI layout...

    Objective: GUI Layout manager Download one of the sample GUI layout program. Use any GUI layout to add buttons to start each sort and display the System.nanoTime in common TextArea panel. The question is a bit confusing so i will try to simplify it. Using the GUI ( I made a unclick able one so you have to make it clickable), allow a user to sort the text file based on what they click on. example: if i click merge...

  • ASSEMBLY LANGUAGE (Mars MIPS) Starting code: Factorial: #Factorial Recursive function subu $sp, $sp, 4 sw $ra,...

    ASSEMBLY LANGUAGE (Mars MIPS) Starting code: Factorial: #Factorial Recursive function subu $sp, $sp, 4 sw $ra, 4($sp) # save the return address on stack beqz $a0, terminate # test for termination subu $sp, $sp, 4 # do not terminate yet sw $a0, 4($sp) # save the parameter sub $a0, $a0, 1 # will call with a smaller argument jal Factorial # after the termination condition is reached these lines # will be executed lw $t0, 4($sp) # the argument I...

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