There should be no other functions within main. You are required to define the f
ID: 3601248 • Letter: T
Question
There should be no other functions within main.
You are required to define the following at the top of your program:
(1) An input array label, Array; put this label at address 0x400. (2) The actual array values (see below for sample input)
CREATE A Y86 ASSEMBLY LANGUAGE PROGRAM THAT WILL COUNT THE NUMBER OF ELEMENTS IN AN ARRAY; FIND THE MIN ELEMENT AND THE MAX ELEMENT; THEN WRITE OUT THOSE THREE VALUES IN THE ORDER COUNT, MIN, MAX.
Mandatory filename: lab4.ys PROBLEM:
Write an assembly language program using Y86. DO NOT USE FUNCTIONS. The program should have an input array, defined at the top of the program, with an indeterminate number of values (at least 1 but no more than 25), which appear in unsorted order. The program will need a Main procedure that
counts the number of array elements, then
finds the Min value, then
finds the Max value, then
writes the three values to output.
(3) A label at the end of the input array, Done, with no data value (i.e., the label only) (4) An output label, Output; put this label at address 0x500.
(5) A stack label, Stack, at a high enough address so that the stack will not grow into the output data, the input data, or the code; put this label at address 0xF00.
Example input and memory for output and stack:
#Use appropriate .pos and .align directives here Array:
.quad 12 .quad 2 .quad 16 .quad 10 .quad 13 .quad 27 .quad 10
Done:
#Use appropriate .pos and .align directives here Output:
#Use appropriate .pos and .align directives here Stack:
INPUT:
There are no data errors that need to be checked as all the data will be assumed correct. You can assume that the values in the input array are signed integers, which may be negative, positive, or zero.
Your program should be able to handle an unknown number of array values (between 1 and 25) and still work. That is, you cannot assume that you know how many input values there will be. The grader will change the number of input values in the input array, and the values themselves, to test your program.
You must use the Done label at the end of the input to detect the end of the input array when calculating the count.
You must use the calculated count when parsing through the static array for all other reasons.
You should not change the names of the labels, but you can use any addresses you wish, as long as your program executes correctly, although the addresses given above will definitely work.
CONSTRAINTS:
• Your program must have one procedure labeled Main. There should be no other procedures
OUTPUT:
To output data in this program, you must write it to a specified area in memory that starts with the label Output. This area of memory in your program is required to be at the top of your program with the descriptive label given above associated with it.
The output is the number of values in the input Array, the minimum value in the input array, and the maximum value in the input array. For the data given in the problem section above, the output, in hexadecimal, should be:
0x00000007 0xffffffe5 0x00000010
#Number of values in Array #Minimum value #Maximum value
Obviously, the #<comment> statements in the output above will not be written in the actual output, but is only there as an aid to the understanding of what the output would look like. The actual output would be:
0x00000007 0xffffffe5 0x00000010
LAB SUBMISSION
You should submit all your lab assignments electronically using the submit command. Be sure that all
the files you are submitting are in the directory from which you run submit (you should create a lab4 directory and put all files for this lab there) Here are the submit commands for the lab4 assignment:
10:20 submit c2421ad lab4 lab4Readme lab4.ys 1:50 submit c2421aa lab4 lab4Readme lab4.ys 3:00 submit c2421ab lab4 lab4Readme lab4.ys
NOTE:
All of the files in a lab MUST be submitted using one command. If you use two submit commands, the files submitted by the second submit will erase the files from the first submission. Therefore, if you make changes to your files and decide to resubmit the lab assignment before the deadline, be sure to submit all of the required files with a single submit command. Do not press the enter key in the middle of your submit command line; let it wrap to the following line if necessary. Your programs MUST be submitted in source code form. Make sure that you submit a .ys file. Do NOT submit the object file (.yo file).
DO NOT submit a directory rather than individual files. Your score will be a zero if you do.
•It is YOUR responsibility to make sure your code can assemble and run on the CSE department server stdlinux.cse.ohiostate.edu using yas and yis as specified earlier in this lab description.
Explanation / Answer
.LC0:
.string "Enter the number of elements "
.LC1:
.string "Enter the elements in the array "
.LC2:
.string "Number of elements : "
.LC3:
.string "Maximum number : "
.LC4:
.string "Minimum number : "
main:
push rbp
mov rbp, rsp
push r15
push r14
push r13
push r12
push rbx
sub rsp, 56
mov rax, rsp
mov rbx, rax
mov DWORD PTR [rbp-52], 0
mov DWORD PTR [rbp-60], 0
.L4:
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-84]
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-84]
test eax, eax
jle .L4
mov eax, DWORD PTR [rbp-84]
cmp eax, 25
jle .L3
jmp .L4
.L3:
mov eax, DWORD PTR [rbp-84]
cdqe
sub rax, 1
mov QWORD PTR [rbp-72], 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-80], 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-56], 0
.L6:
mov eax, DWORD PTR [rbp-84]
cmp DWORD PTR [rbp-56], eax
jge .L5
mov eax, DWORD PTR [rbp-56]
cdqe
lea rdx, [0+rax*4]
mov rax, QWORD PTR [rbp-80]
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-56], 1
jmp .L6
.L5:
mov rax, QWORD PTR [rbp-80]
mov eax, DWORD PTR [rax]
mov DWORD PTR [rbp-60], eax
mov DWORD PTR [rbp-56], 0
.L9:
mov eax, DWORD PTR [rbp-84]
cmp DWORD PTR [rbp-56], eax
jge .L7
mov rax, QWORD PTR [rbp-80]
mov edx, DWORD PTR [rbp-56]
movsx rdx, edx
mov eax, DWORD PTR [rax+rdx*4]
cmp DWORD PTR [rbp-52], eax
jge .L8
mov rax, QWORD PTR [rbp-80]
mov edx, DWORD PTR [rbp-56]
movsx rdx, edx
mov eax, DWORD PTR [rax+rdx*4]
mov DWORD PTR [rbp-52], eax
.L8:
add DWORD PTR [rbp-56], 1
jmp .L9
.L7:
mov DWORD PTR [rbp-56], 0
.L12:
mov eax, DWORD PTR [rbp-84]
cmp DWORD PTR [rbp-56], eax
jge .L10
mov rax, QWORD PTR [rbp-80]
mov edx, DWORD PTR [rbp-56]
movsx rdx, edx
mov eax, DWORD PTR [rax+rdx*4]
cmp DWORD PTR [rbp-60], eax
jle .L11
mov rax, QWORD PTR [rbp-80]
mov edx, DWORD PTR [rbp-56]
movsx rdx, edx
mov eax, DWORD PTR [rax+rdx*4]
mov DWORD PTR [rbp-60], eax
.L11:
add DWORD PTR [rbp-56], 1
jmp .L12
.L10:
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-84]
mov esi, eax
mov rdi, rdx
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> >&))
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 rdx, rax
mov eax, DWORD PTR [rbp-52]
mov esi, eax
mov rdi, rdx
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> >&))
mov esi, OFFSET FLAT:.LC4
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-60]
mov esi, eax
mov rdi, rdx
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> >&))
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 .L16
cmp DWORD PTR [rbp-8], 65535
jne .L16
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
.L16:
nop
leave
ret
_GLOBAL__sub_I_main:
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.