Write a Y86 program that sorts an array of data using Bubble

Write a Y86 program that sorts an array of data using Bubble Sort. Use a hardcoded input array similar to that used by asum.ys (included with the Y86 simulator source) with at least 10 entries. Sort the array in place (i.e., no need to allocate additional memory for the sorted array). Follow the register usage conventions outlined in B&O;\'H section 3.7.3. Name your source file sort.ys.

Solution

Answer:

.zero 1
.LC0:
.string \"\ ------------ BUBBLE SORT ------------ \ \ \"
.LC1:
.string \"Enter No. of Elements : \"
.LC2:
.string \"\ Enter Elements : \ \"
.LC3:
.string \"\ After Sorting : \ \"
main:
push rbp
mov rbp, rsp
sub rsp, 432
mov esi, OFFSET FLAT:.LC0
mov edi, OFFSET FLAT:std::cout
call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
mov esi, OFFSET FLAT:.LC1
mov edi, OFFSET FLAT:std::cout
call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
lea rax, [rbp-420]
mov rsi, rax
mov edi, OFFSET FLAT:std::cin
call std::basic_istream<char, std::char_traits<char> >::operator>>(int&)
mov esi, OFFSET FLAT:.LC2
mov edi, OFFSET FLAT:std::cout
call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
mov DWORD PTR [rbp-4], 1
.L3:
mov eax, DWORD PTR [rbp-420]
cmp DWORD PTR [rbp-4], eax
jg .L2
lea rax, [rbp-416]
mov edx, DWORD PTR [rbp-4]
movsx rdx, edx
sal rdx, 2
add rax, rdx
mov rsi, rax
mov edi, OFFSET FLAT:std::cin
call std::basic_istream<char, std::char_traits<char> >::operator>>(int&)
add DWORD PTR [rbp-4], 1
jmp .L3
.L2:
mov DWORD PTR [rbp-8], 1
.L8:
mov eax, DWORD PTR [rbp-420]
sub eax, 1
cmp eax, DWORD PTR [rbp-8]
jl .L4
mov DWORD PTR [rbp-12], 1
.L7:
mov eax, DWORD PTR [rbp-420]
sub eax, 1
cmp eax, DWORD PTR [rbp-12]
jl .L5
mov eax, DWORD PTR [rbp-12]
cdqe
mov edx, DWORD PTR [rbp-416+rax*4]
mov eax, DWORD PTR [rbp-12]
add eax, 1
cdqe
mov eax, DWORD PTR [rbp-416+rax*4]
cmp edx, eax
jle .L6
mov eax, DWORD PTR [rbp-12]
cdqe
mov eax, DWORD PTR [rbp-416+rax*4]
mov DWORD PTR [rbp-16], eax
mov eax, DWORD PTR [rbp-12]
add eax, 1
cdqe
mov edx, DWORD PTR [rbp-416+rax*4]
mov eax, DWORD PTR [rbp-12]
cdqe
mov DWORD PTR [rbp-416+rax*4], edx
mov eax, DWORD PTR [rbp-12]
add eax, 1
cdqe
mov edx, DWORD PTR [rbp-16]
mov DWORD PTR [rbp-416+rax*4], edx
.L6:
add DWORD PTR [rbp-12], 1
jmp .L7
.L5:
add DWORD PTR [rbp-8], 1
jmp .L8
.L4:
mov esi, OFFSET FLAT:.LC3
mov edi, OFFSET FLAT:std::cout
call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
mov DWORD PTR [rbp-4], 1
.L10:
mov eax, DWORD PTR [rbp-420]
cmp DWORD PTR [rbp-4], eax
jg .L9
mov eax, DWORD PTR [rbp-4]
cdqe
mov eax, DWORD PTR [rbp-416+rax*4]
mov esi, eax
mov edi, OFFSET FLAT:std::cout
call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
mov esi, OFFSET FLAT:std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)
mov rdi, rax
call std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))
add DWORD PTR [rbp-4], 1
jmp .L10
.L9:
mov eax, 0
leave
ret
__static_initialization_and_destruction_0(int, int):
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-4], edi
mov DWORD PTR [rbp-8], esi
cmp DWORD PTR [rbp-4], 1
jne .L14
cmp DWORD PTR [rbp-8], 65535
jne .L14
mov edi, OFFSET FLAT:std::__ioinit
call std::ios_base::Init::Init()
mov edx, OFFSET FLAT:__dso_handle
mov esi, OFFSET FLAT:std::__ioinit
mov edi, OFFSET FLAT:std::ios_base::Init::~Init()
call __cxa_atexit
.L14:
nop
leave
ret
push rbp
mov rbp, rsp
mov esi, 65535
mov edi, 1
call __static_initialization_and_destruction_0(int, int)
pop rbp
ret

 Write a Y86 program that sorts an array of data using Bubble Sort. Use a hardcoded input array similar to that used by asum.ys (included with the Y86 simulator
 Write a Y86 program that sorts an array of data using Bubble Sort. Use a hardcoded input array similar to that used by asum.ys (included with the Y86 simulator
 Write a Y86 program that sorts an array of data using Bubble Sort. Use a hardcoded input array similar to that used by asum.ys (included with the Y86 simulator

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site