Easy68K help, assembler - thank you. Using a for loop 10 times. Write a program
ID: 3854419 • Letter: E
Question
Easy68K help, assembler - thank you. Using a for loop 10 times.
Write a program in Easy68K to fulfill the following functions:
Repeat the following steps 10 times using a loop
Read a number from the input.
Add the number to the accumulator (Hint: the initial value for the accumulator should be 0).
Show the accumulator value (i.e. total sum) in the output.
The output cab be like this:
Please input a number: 7
Please input a number: 3
Please input a number: 2
Please input a number: 0
Please input a number: 1
Please input a number: 2
Please input a number: 5
Please input a number: 4
Please input a number: 6
Please input a number: 8
Total sum is: 38
Explanation / Answer
*--------------------------------------------------------------------------------------------------------------------------------------------------------
Program :
Written by :
Date :
Description : Repeat the following steps 10 times using a loop, "Read a number from the input." Add the number to the accumulator. Show the accumulator value (i.e. total sum) in the output.
*--------------------------------------------------------------------------------------------------------------------------------------------------------
.LC0:
.string "Please input a number: "
.LC1:
.string "Total sum is: "
main:
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-4], 0
mov DWORD PTR [rbp-8], 0
.L3:
cmp DWORD PTR [rbp-8], 9
jg .L2
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: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> >&))
lea rax, [rbp-12]
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-12]
add DWORD PTR [rbp-4], eax
add DWORD PTR [rbp-8], 1
jmp .L3
.L2:
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 rdx, rax
mov eax, DWORD PTR [rbp-4]
mov esi, eax
mov rdi, rdx
call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
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 .L7
cmp DWORD PTR [rbp-8], 65535
jne .L7
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
.L7:
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
Output :-
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.