Start with populate an array by reading numbers from the keyboard. With the arra
ID: 3596474 • Letter: S
Question
Start with populate an array by reading numbers from the keyboard. With the array populated you print each element of the array then print the sum of the odd index element.
Start by calling the irvine “Clrscr” subroutine, then
Write a message asking for the number of number to add. Irvine “Writestring” to display a message. Use the Irvine ReadInt function read a number and WriteInt to display a number. As you read in numbers store them in an array of fixed number of 100 32 bit numbers.
Once all the numbers are read into the array print them from the array. Use an internal procedure to read the numbers into the array and an internal procedure to print the numbers.
Write a procedure to add the odd indexed numbers using the array and store the result in a memory variable named “result”
Write a message indicating the sum of the odd indexed values is: xxxxx.
Sample output:
How many numbers would you like to add: 5
Enter a number: 10
Enter a number: 25
Enter a number: 10
Enter a number: 25
Enter a number: 50
The numbers printed from the array are: 10, 25, 10, 25, 50
The sum of the numbers stored in odd indexes is: 70
Explanation / Answer
.LC0:
.string "How many numbers would you like to add: "
.LC1:
.string " "
.LC2:
.string "Enter a number: "
.LC3:
.string "The numbers printed from the array are: "
.LC4:
.string " "
.LC5:
.string "The sum of the number stored in the odd indexes is: "
main:
push rbp
mov rbp, rsp
push r14
push r13
push r12
push rbx
sub rsp, 48
mov rax, rsp
mov r12, rax
mov DWORD PTR [rbp-40], 0
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-60]
mov rsi, rax
mov edi, OFFSET FLAT:std::cin
call std::basic_istream<char, std::char_traits<char> >::operator>>(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*)
mov eax, DWORD PTR [rbp-60]
cdqe
sub rax, 1
mov QWORD PTR [rbp-48], rax
mov rdx, rax
add rdx, 1
mov QWORD PTR [rbp-80], rdx
mov QWORD PTR [rbp-72], 0
mov rdx, rax
add rdx, 1
mov r13, rdx
mov r14d, 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-56], rax
mov DWORD PTR [rbp-36], 0
.L3:
mov eax, DWORD PTR [rbp-60]
cmp DWORD PTR [rbp-36], eax
jge .L2
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 eax, DWORD PTR [rbp-36]
cdqe
lea rdx, [0+rax*4]
mov rax, QWORD PTR [rbp-56]
add rax, rdx
mov rsi, rax
mov edi, OFFSET FLAT:std::cin
call std::basic_istream<char, std::char_traits<char> >::operator>>(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*)
add DWORD PTR [rbp-36], 1
jmp .L3
.L2:
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-36], 0
.L5:
mov eax, DWORD PTR [rbp-60]
cmp DWORD PTR [rbp-36], eax
jge .L4
mov rax, QWORD PTR [rbp-56]
mov edx, DWORD PTR [rbp-36]
movsx rdx, edx
mov ebx, DWORD PTR [rax+rdx*4]
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 esi, ebx
mov rdi, rax
call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
add DWORD PTR [rbp-36], 1
jmp .L5
.L4:
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-36], 0
.L8:
mov eax, DWORD PTR [rbp-60]
cmp DWORD PTR [rbp-36], eax
jge .L6
mov eax, DWORD PTR [rbp-36]
cdq
shr edx, 31
add eax, edx
and eax, 1
sub eax, edx
cmp eax, 1
je .L7
mov rax, QWORD PTR [rbp-56]
mov edx, DWORD PTR [rbp-36]
movsx rdx, edx
mov eax, DWORD PTR [rax+rdx*4]
add DWORD PTR [rbp-40], eax
.L7:
add DWORD PTR [rbp-36], 1
jmp .L8
.L6:
mov esi, OFFSET FLAT:.LC5
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-40]
mov esi, eax
mov rdi, rdx
call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
mov eax, 0
mov rsp, r12
lea rsp, [rbp-32]
pop rbx
pop r12
pop r13
pop r14
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_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.