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...
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...
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...
(code in C++ language) [Code Bubble sort, Insertion sort Create a Big array with random numbers....
(code in C++ language) [Code Bubble sort, Insertion sort Create a Big array with random numbers. Record the time. Run Bubble Check time (compute the processing time) do it 100 times (random numbers) Take the average Insertion: Compare] (some explanations please)
Write Insertion Sort and Bubble Sort Program for C# also write their algorithm and Explain their...
Write Insertion Sort and Bubble Sort Program for C# also write their algorithm and Explain their working.
LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that...
LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that sorts the array below in ascending order.  LISP is a recursive language so the program will use recursion to sort. Since there will be no loops, you will not need the variables i, j, and temp, but still use the variable name array for the array to be sorted.             Array to be sorted is 34, 56, 4, 10, 77, 51, 93, 30, 5, 52 The...
Write a program in Java to sort the given array using merge sort, quick sort, insertion...
Write a program in Java to sort the given array using merge sort, quick sort, insertion sort, selection sort and bubble sort based on the input from the user which sorting technique they wanted to use. Get the array size, array elements from the user, and also display the sorted array along with the name of the sorting technique used.
Given the following array [17, 15,21,208,16,122,212,53,119,43] Apply bubble sort algorithm and show the status of the...
Given the following array [17, 15,21,208,16,122,212,53,119,43] Apply bubble sort algorithm and show the status of the array after each pass. Also calculate how many comparisons you will be required to pass
For the given array, simulate the working operation of Bubble Sort. Show your work at each...
For the given array, simulate the working operation of Bubble Sort. Show your work at each step. Make sure to show the status of the array after every swap. [ 28, 13, 22, 7, 34, 2 ]
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT