I need to make a Selection sort program using sicxe assemble
I need to make a Selection sort program using sic/xe assembler.. (.asm file)
Could you make it??
Solution
Answer:
Assembly Language Program :
.zero 1
.LC0:
.string \"Array initially : \"
.LC1:
.string \"Array after selection sort : \"
main:
push rbp
mov rbp, rsp
sub rsp, 48
mov DWORD PTR [rbp-48], 10
mov DWORD PTR [rbp-44], 2
mov DWORD PTR [rbp-40], 45
mov DWORD PTR [rbp-36], 18
mov DWORD PTR [rbp-32], 16
mov DWORD PTR [rbp-28], 30
mov DWORD PTR [rbp-24], 29
mov DWORD PTR [rbp-20], 1
mov DWORD PTR [rbp-16], 1
mov DWORD PTR [rbp-12], 100
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*)
lea rax, [rbp-48]
mov esi, 10
mov rdi, rax
call print(int*, int)
lea rax, [rbp-48]
mov esi, 10
mov rdi, rax
call selection_sort(int*, int)
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-48]
mov esi, 10
mov rdi, rax
call print(int*, int)
mov eax, 0
leave
ret
selection_sort(int*, int):
push rbp
mov rbp, rsp
sub rsp, 32
mov QWORD PTR [rbp-24], rdi
mov DWORD PTR [rbp-28], esi
mov DWORD PTR [rbp-8], 0
.L8:
cmp DWORD PTR [rbp-8], 8
jg .L9
mov eax, DWORD PTR [rbp-8]
mov DWORD PTR [rbp-4], eax
mov eax, DWORD PTR [rbp-8]
add eax, 1
mov DWORD PTR [rbp-12], eax
.L7:
cmp DWORD PTR [rbp-12], 9
jg .L5
mov eax, DWORD PTR [rbp-12]
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-4]
cdqe
lea rcx, [0+rax*4]
mov rax, QWORD PTR [rbp-24]
add rax, rcx
mov eax, DWORD PTR [rax]
cmp edx, eax
jge .L6
mov eax, DWORD PTR [rbp-12]
mov DWORD PTR [rbp-4], eax
.L6:
add DWORD PTR [rbp-12], 1
jmp .L7
.L5:
mov eax, DWORD PTR [rbp-4]
cdqe
lea rdx, [0+rax*4]
mov rax, QWORD PTR [rbp-24]
add rdx, rax
mov eax, DWORD PTR [rbp-8]
cdqe
lea rcx, [0+rax*4]
mov rax, QWORD PTR [rbp-24]
add rax, rcx
mov rsi, rdx
mov rdi, rax
call std::enable_if<std::__and_<std::is_move_constructible<int>, std::is_move_assignable<int> >::value, void>::type std::swap<int>(int&, int&)
add DWORD PTR [rbp-8], 1
jmp .L8
.L9:
nop
leave
ret
.LC2:
.string \" \"
print(int*, int):
push rbp
mov rbp, rsp
sub rsp, 32
mov QWORD PTR [rbp-24], rdi
mov DWORD PTR [rbp-28], esi
mov DWORD PTR [rbp-4], 0
.L12:
mov eax, DWORD PTR [rbp-4]
cmp eax, DWORD PTR [rbp-28]
jge .L11
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:std::cout
call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
mov esi, OFFSET FLAT:.LC2
mov rdi, rax
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*)
add DWORD PTR [rbp-4], 1
jmp .L12
.L11:
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 edi, OFFSET FLAT:std::cout
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> >&))
nop
leave
ret
std::remove_reference<int&>::type&& std::move<int&>(int&):
push rbp
mov rbp, rsp
mov QWORD PTR [rbp-8], rdi
mov rax, QWORD PTR [rbp-8]
pop rbp
ret
std::enable_if<std::__and_<std::is_move_constructible<int>, std::is_move_assignable<int> >::value, void>::type std::swap<int>(int&, int&):
push rbp
mov rbp, rsp
sub rsp, 32
mov QWORD PTR [rbp-24], rdi
mov QWORD PTR [rbp-32], rsi
mov rax, QWORD PTR [rbp-24]
mov rdi, rax
call std::remove_reference<int&>::type&& std::move<int&>(int&)
mov eax, DWORD PTR [rax]
mov DWORD PTR [rbp-4], eax
mov rax, QWORD PTR [rbp-32]
mov rdi, rax
call std::remove_reference<int&>::type&& std::move<int&>(int&)
mov edx, DWORD PTR [rax]
mov rax, QWORD PTR [rbp-24]
mov DWORD PTR [rax], edx
lea rax, [rbp-4]
mov rdi, rax
call std::remove_reference<int&>::type&& std::move<int&>(int&)
mov edx, DWORD PTR [rax]
mov rax, QWORD PTR [rbp-32]
mov DWORD PTR [rax], edx
nop
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 .L18
cmp DWORD PTR [rbp-8], 65535
jne .L18
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
.L18:
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



