Write an assembly language program with five procedures using Y86. The program s
ID: 3739741 • Letter: W
Question
Write an assembly language program with five procedures using Y86. The program should have an input array, defined at the top of the program, with an indeterminate number of values (but no more than 25), which appear in unsorted order. The program will need a Main procedure, a Count procedure,to determine the number of values in the input array, a Min procedure, to find the minimum value in the array, a Max procedure, to find the maximum value in the array, and a Reverse procedure, which will write the values in the input array to output in reverse order.
You are required to define the following at the top of your program:
(1) An input array label, Array; put thislabel at address 0x300.
(2) The actual array values(see below forsample input)
(3) A label at the end of the input array, Done, with no data value (that is, the label only)
(4) A label for a second array, RArray; put this label at address 0x400
(5) An output label, Output; put thislabel at address 0x500
(6) A stack label, Stack, at a high enough addressso that the stack will not grow into the output data, the input data, or the code; put thislabel at address 0xf00.
(7) Use rdx and rdi
Please make it so I can copy and paste the code. Thank you.
Explanation / Answer
Answer:
Assembly Language Code :
findSmallestElement(int*, int):
push rbp
mov rbp, rsp
mov QWORD PTR [rbp-24], rdi
mov DWORD PTR [rbp-28], esi
mov rax, QWORD PTR [rbp-24]
mov eax, DWORD PTR [rax]
mov DWORD PTR [rbp-4], eax
mov DWORD PTR [rbp-8], 0
.L4:
mov eax, DWORD PTR [rbp-8]
cmp eax, DWORD PTR [rbp-28]
jge .L2
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]
cmp DWORD PTR [rbp-4], eax
jle .L3
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-4], eax
.L3:
add DWORD PTR [rbp-8], 1
jmp .L4
.L2:
mov eax, DWORD PTR [rbp-4]
pop rbp
ret
.LC0:
.string "Enter the size of array: "
.LC1:
.string "Enter array elements: "
.LC2:
.string "Smallest Element is: "
main:
push rbp
mov rbp, rsp
push r15
push r14
push r13
push r12
push rbx
sub rsp, 40
mov rax, rsp
mov rbx, rax
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-80]
mov rsi, rax
mov edi, OFFSET FLAT:std::cin
call std::basic_istream<char, std::char_traits<char> >::operator>>(int&)
mov eax, DWORD PTR [rbp-80]
sub eax, 1
cdqe
sub rax, 1
mov QWORD PTR [rbp-64], rax
mov rdx, rax
add rdx, 1
mov r14, rdx
mov r15d, 0
mov rdx, rax
add rdx, 1
mov r12, rdx
mov r13d, 0
add rax, 1
sal rax, 2
lea rdx, [rax+3]
mov eax, 16
sub rax, 1
add rax, rdx
mov ecx, 16
mov edx, 0
div rcx
imul rax, rax, 16
sub rsp, rax
mov rax, rsp
add rax, 3
shr rax, 2
sal rax, 2
mov QWORD PTR [rbp-72], rax
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*)
mov DWORD PTR [rbp-52], 0
.L8:
mov eax, DWORD PTR [rbp-80]
cmp DWORD PTR [rbp-52], eax
jge .L7
mov eax, DWORD PTR [rbp-52]
cdqe
lea rdx, [0+rax*4]
mov rax, QWORD PTR [rbp-72]
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-52], 1
jmp .L8
.L7:
mov edx, DWORD PTR [rbp-80]
mov rax, QWORD PTR [rbp-72]
mov esi, edx
mov rdi, rax
call findSmallestElement(int*, int)
mov DWORD PTR [rbp-76], eax
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 rdx, rax
mov eax, DWORD PTR [rbp-76]
mov esi, eax
mov rdi, rdx
call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
mov eax, 0
mov rsp, rbx
lea rsp, [rbp-40]
pop rbx
pop r12
pop r13
pop r14
pop r15
pop rbp
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 .L12
cmp DWORD PTR [rbp-8], 65535
jne .L12
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
.L12:
nop
leave
ret
_GLOBAL__sub_I__Z19findSmallestElementPii:
push rbp
mov rbp, rsp
mov esi, 65535
mov edi, 1
call __static_initialization_and_destruction_0(int, int)
pop rbp
ret
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.