Question

In: Computer Science

ASSEMBLY PROGRAM!!! QtSpim Sorting Data Add the Bubble Sort to minMaxArray.asm to sort the array into...

ASSEMBLY PROGRAM!!! QtSpim

Sorting Data

Add the Bubble Sort to minMaxArray.asm to sort the array into ascending order. Use the Bubble Sort algorithm from the lecture. You can use either Base Addressing or Indexed Addressing for the arrays.

For this assignment, make sure you prompt the user for the numbers. Do not hard-code them in the data section.

NOTE: Declare the array last in the Data section.

Solutions

Expert Solution

The solution to given question:

The following program takes the following inputs:

  • the size of an array, and
  • each element of an array separately

Output:

The program prints the elements of Sorted Array.

Program to implement bubble sort (optimized solution):

======================================================

.LC0:

        .string "Sorted Array: "

.LC1:

        .string "%d "

bubbleSort:

        push    rbp

        mov     rbp, rsp

        sub     rsp, 32

        mov     QWORD PTR [rbp-24], rdi

        mov     DWORD PTR [rbp-28], esi

        mov     DWORD PTR [rbp-12], 0

        mov     DWORD PTR [rbp-4], 0

        jmp     .L2

.L8:

        mov     DWORD PTR [rbp-8], 0

        jmp     .L3

.L5:

        mov     eax, DWORD PTR [rbp-8]

        cdqe

        lea     rdx, [0+rax*4]

        mov     rax, QWORD PTR [rbp-24]

        add     rax, rdx

        mov     edx, DWORD PTR [rax]

        mov     eax, DWORD PTR [rbp-8]

        cdqe

        add     rax, 1

        lea     rcx, [0+rax*4]

        mov     rax, QWORD PTR [rbp-24]

        add     rax, rcx

        mov     eax, DWORD PTR [rax]

        cmp     edx, eax

        jle     .L4

        mov     eax, DWORD PTR [rbp-8]

        cdqe

        lea     rdx, [0+rax*4]

        mov     rax, QWORD PTR [rbp-24]

        add     rax, rdx

        mov     eax, DWORD PTR [rax]

        mov     DWORD PTR [rbp-16], eax

        mov     eax, DWORD PTR [rbp-8]

        cdqe

        add     rax, 1

        lea     rdx, [0+rax*4]

        mov     rax, QWORD PTR [rbp-24]

        add     rax, rdx

        mov     edx, DWORD PTR [rbp-8]

        movsx   rdx, edx

        lea     rcx, [0+rdx*4]

        mov     rdx, QWORD PTR [rbp-24]

        add     rdx, rcx

        mov     eax, DWORD PTR [rax]

        mov     DWORD PTR [rdx], eax

        mov     eax, DWORD PTR [rbp-8]

        cdqe

        add     rax, 1

        lea     rdx, [0+rax*4]

        mov     rax, QWORD PTR [rbp-24]

        add     rdx, rax

        mov     eax, DWORD PTR [rbp-16]

      mov     DWORD PTR [rdx], eax

        mov     DWORD PTR [rbp-12], 1

.L4:

        add     DWORD PTR [rbp-8], 1

.L3:

        mov     eax, DWORD PTR [rbp-28]

        sub     eax, DWORD PTR [rbp-4]

        sub     eax, 1

        cmp     DWORD PTR [rbp-8], eax

        jl      .L5

        cmp     DWORD PTR [rbp-12], 0

        je      .L11

        add     DWORD PTR [rbp-4], 1

.L2:

        mov     eax, DWORD PTR [rbp-4]

        cmp     eax, DWORD PTR [rbp-28]

        jl      .L8

        jmp     .L7

.L11:

        nop

.L7:

        mov     edi, OFFSET FLAT:.LC0

        mov     eax, 0

        call    printf

        mov     DWORD PTR [rbp-4], 0

        jmp     .L9

.L10:

        mov     eax, DWORD PTR [rbp-4]

        cdqe

        lea     rdx, [0+rax*4]

        mov     rax, QWORD PTR [rbp-24]

        add     rax, rdx

        mov     eax, DWORD PTR [rax]

        mov     esi, eax

        mov     edi, OFFSET FLAT:.LC1

        mov     eax, 0

        call    printf

        add     DWORD PTR [rbp-4], 1

.L9:

        mov     eax, DWORD PTR [rbp-4]

        cmp     eax, DWORD PTR [rbp-28]

        jl      .L10

        nop

        nop

        leave

        ret

.LC2:

        .string "Enter the number of elements to be sorted: "

.LC3:

        .string "%d"

.LC4:

        .string "Enter element no. %d: "

main:

        push    rbp

        mov     rbp, rsp

        sub     rsp, 432

        mov     edi, OFFSET FLAT:.LC2

        mov     eax, 0

        call    printf

        lea     rax, [rbp-420]

        mov     rsi, rax

        mov     edi, OFFSET FLAT:.LC3

        mov     eax, 0

        call    __isoc99_scanf

        mov     DWORD PTR [rbp-4], 0

        jmp     .L13

.L14:

        mov     eax, DWORD PTR [rbp-4]

        add     eax, 1

        mov     esi, eax

        mov     edi, OFFSET FLAT:.LC4

        mov     eax, 0

        call    printf

        lea     rdx, [rbp-416]

        mov     eax, DWORD PTR [rbp-4]

        cdqe

        sal     rax, 2

        add     rax, rdx

        mov     rsi, rax

        mov     edi, OFFSET FLAT:.LC3

        mov     eax, 0

        call    __isoc99_scanf

        add     DWORD PTR [rbp-4], 1

.L13:

        mov     eax, DWORD PTR [rbp-420]

        cmp     DWORD PTR [rbp-4], eax

        jl      .L14

        mov     edx, DWORD PTR [rbp-420]

        lea     rax, [rbp-416]

        mov     esi, edx

        mov     rdi, rax

        call    bubbleSort

        mov     eax, 0

        leave

        ret


Related Solutions

C++ Program (Using 2D array and bubble sort to sort data) A company pays its salespeople...
C++ Program (Using 2D array and bubble sort to sort data) A company pays its salespeople on a commission basis.  The salespeople each receive $250 per week plus 11 percent of their gross sales for the sales period.  For example, a salesperson who grosses $5000 in sales in the period receives $250 plus 11 percent of $5000, or a total of $812.21.  Write a program (using an array of counters) determines for each salesperson their total sales, their salary and additional data points.  There...
// This program uses a bubble sort to arrange an array of integers in // ascending...
// This program uses a bubble sort to arrange an array of integers in // ascending order (smallest to largest). It then display the array // before the sorting and after the sorting. Modify the program so it orders // integers in descending order (largest to smallest). Then add some code // to display the array at each step of the algorithm. You don't have to // modify anything in the main() function. All modification are inside // the bubbleSortArray()...
Import a data set (txt file) then do the sorting algorithm using bubble sort, radix sort,...
Import a data set (txt file) then do the sorting algorithm using bubble sort, radix sort, insertion sort, and merge sort, It must show how long it took and how many movements occurred. Please write codes in C++ Here's data set (should be stored in txt file) 7426 4524 4737 9436 3997 2757 6288 5414 9590 5968 6638 3199 9514 1541 9866 2144 6731 911 2171 6135 6437 912 9417 2662 6606 6349 707 2890 5386 9718 3492 5068 9674...
in MARIE simulator, write assembly language to BUBBLE SORT 30 hexadecimals store in two array.
in MARIE simulator, write assembly language to BUBBLE SORT 30 hexadecimals store in two array.
* Sort Student array descending based on GPA using MERGE sort. Sorting will be done in...
* Sort Student array descending based on GPA using MERGE sort. Sorting will be done in place. * * @param students array to be sorted, can be empty, but cannot be null */ public static void sortGPA(Student[] students) { // TODO: implement this } Student class: public class Student extends Person { private double GPA; public Student(String lastName, String firstName, double gpa) { super(lastName, firstName); this.GPA = gpa; } public double getGPA() { return GPA; } @Override public boolean equals(Object...
1.   Bubble Sort Implement a bubble sort program that will read from a file “pp2.txt” from...
1.   Bubble Sort Implement a bubble sort program that will read from a file “pp2.txt” from the current directory a list of intergers (10 numbers to be exact), and the sort them, and print them to the screen. You can use redirection to read data from a given file through standard input, as opposed to reading the data from the file with the read API (similar to Lab #1). You can assume the input data will only have 10 numbers...
It's time to write a sorting algorithm! In this lab, you'll be writing Bubble Sort. Much...
It's time to write a sorting algorithm! In this lab, you'll be writing Bubble Sort. Much like the previous lab, you will be tasked with prompting the user for a list of values until the user enters 0 (you may use the same initializeVector that you wrote in the last lab). You will then write bubblesort which sorts the vector from smallest to largest. You will then call a function displayVector which displays the vector to the screen. Keep everything...
The bubble sort described in AS 7e is inefficient when perform on a larger array. To...
The bubble sort described in AS 7e is inefficient when perform on a larger array. To improve the efficiency, we have to observe the basic mechanism of Bubble Sort. Each inner loop of the Bubble sort always move the largest item on the unsorted left side to the sorted right side. When a list is sorted, we say the list is in ascending order by convention. We can enhance the efficiency of traditional Bubble sort by making only one swapping...
Implement heap sort by using the bottom-up insertion method. Add this sort to your sorting framework....
Implement heap sort by using the bottom-up insertion method. Add this sort to your sorting framework. Evaluate its performance in terms of the numbers of comparisons and exchanges, and compare it to the performance of the two advanced sorting methods that you have previously implemented. Submit your report with detailed empirical results and a thorough explanation of these results. Which of the three advanced sorting method is the best choice for a) ordered data, b) data in reverse order, and...
Write a program and test a program that translates the following Bubble Sort algorithm to a...
Write a program and test a program that translates the following Bubble Sort algorithm to a bubblesort function. The function's prototype is, void bubblesort(int a[], int size); Bubble Sort The inner loop moves the largest element in the unsorted part of the array to the last position of the unsorted part of the array; the outer loop moves the last position of the unsorted part of the array. The Bubble sort exchanges elements with adjacent elements as it moves the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT