In: Computer Science
Write an x86 assembly language program that performs equivalently to the C++ source code file shown below.Please note that commented out behavior must be implemented in x86 assembly language. There is no standard, portable way to perform some of these actions in C++.
#include void main()
{
// Use registers for these in your x86 assembly language program
// Only use the .data segment for string (character array) variables
int eax;
int esi;
int ecx;
int edi;
// Loop the following three times
for (ecx = 3; ecx > 0; --ecx) {
// Clear the screen
// Move the cursor to row 10, column 10
std::cout << "Enter a signed integer value: ";
std::cin >> eax;
edi = eax;
// Move the cursor to row 11, column 10
std::cout << "Enter a second signed integer value: ";
std::cin >> eax;
esi = eax;
eax = edi + esi;
std::cout << "The sum is: " << eax << std::endl;
eax = edi - esi;
std::cout << "The difference is: " << eax << std::endl;
// Pause for two seconds
}
system("PAUSE");
}
LC0:
.string "Enter a signed integer value: "
.LC1:
.string "Enter a second signed integer value: "
.LC2:
.string "The sum is: "
.LC3:
.string "The difference is: "
.LC4:
.string "PAUSE"
main:
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-4], 3
.L3:
cmp DWORD PTR [rbp-4], 0
jle .L2
mov esi, OFFSET FLAT:.LC0
mov edi, OFFSET FLAT:_ZSt4cout
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-16]
mov rsi, rax
mov edi, OFFSET FLAT:_ZSt3cin
call std::basic_istream<char, std::char_traits<char> >::operator>>(int&)
mov eax, DWORD PTR [rbp-16]
mov DWORD PTR [rbp-8], eax
mov esi, OFFSET FLAT:.LC1
mov edi, OFFSET FLAT:_ZSt4cout
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-16]
mov rsi, rax
mov edi, OFFSET FLAT:_ZSt3cin
call std::basic_istream<char, std::char_traits<char> >::operator>>(int&)
mov eax, DWORD PTR [rbp-16]
mov DWORD PTR [rbp-12], eax
mov edx, DWORD PTR [rbp-8]
mov eax, DWORD PTR [rbp-12]
add eax, edx
mov DWORD PTR [rbp-16], eax
mov esi, OFFSET FLAT:.LC2
mov edi, OFFSET FLAT:_ZSt4cout
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-16]
mov esi, eax
mov rdi, rdx
call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
mov esi, OFFSET FLAT:ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6
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, DWORD PTR [rbp-8]
sub eax, DWORD PTR [rbp-12]
mov DWORD PTR [rbp-16], eax
mov esi, OFFSET FLAT:.LC3
mov edi, OFFSET FLAT:_ZSt4cout
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-16]
mov esi, eax
mov rdi, rdx
call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
mov esi, OFFSET FLAT:ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6
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> >&))
sub DWORD PTR [rbp-4], 1
jmp .L3
.L2:
mov edi, OFFSET FLAT:.LC4
call system
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:ZStL8_ioinit
call std::ios_base::Init::Init() [complete object constructor]
mov edx, OFFSET FLAT:__dso_handle
mov esi, OFFSET FLAT:ZStL8_ioinit
mov edi, OFFSET FLAT:_ZNSt8ios_base4InitD1Ev
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
That's all