Question

In: Computer Science

Write an x86 assembly language program that performs equivalently to the C++ source code file shown...

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");

}

Solutions

Expert Solution

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


Related Solutions

Using x86 assembly language, create a flowchart and write an example of code that will sort...
Using x86 assembly language, create a flowchart and write an example of code that will sort 2 arrays of unsigned doubleword integers in ascending order and output the largest element in each array. Any sorting procedure can be used, but this procedure must be called twice for each array. The first time it is called, the first array should be sorted and the second time it is called, the second array must be sorted. As well as outputting which is...
Please write in x86 Assembly language on Visual Studio Write a program to compare two strings...
Please write in x86 Assembly language on Visual Studio Write a program to compare two strings in locations str1 and str2. Initialize str1 to Computer and initialize str2 to Compater. Assume Str1 holds the correct spelling and str2 may have an incorrect spelling. Use string instructions to check if str2 is correct and if not correct the mistake in str2.
Assembly Language for x86 processors You are to write a program which should first ask for...
Assembly Language for x86 processors You are to write a program which should first ask for 4 random numbers from 0-20 (user will inpute these numbers in no preset order). Input these 5 numbers in variables called num1, num2, num3, num4, and num5. When done, your program should sort these numbers (you will use lots of conditions to check order). num1 should contain smallest number while num5 should contain the biggest. display the contents of num1 through num5 on the...
Write an X86-series assembly language program that checks whether input string is palindrome or not. A...
Write an X86-series assembly language program that checks whether input string is palindrome or not. A palindrome is a word, number, phrase or any other sequence which reads the same backward as forward e.g. madam, racecar. Sample Execution: Please enter a String: redivider The string is a palindrome Another Sample Execution: Please enter a String: abracadabra The string is not a palindrome
Please use assembly language x86 Visual Studio Write a program to add the following word size...
Please use assembly language x86 Visual Studio Write a program to add the following word size numbers:15F2, 9E89, 8342, 99FF, 7130 using adc instruction and a loop. The result must be in DX, AX. Show the result in debug window.
write a program for the microcontroller-msp430fr6989 using code composer studio not assembly language. write a code...
write a program for the microcontroller-msp430fr6989 using code composer studio not assembly language. write a code that transmits a single character and lights the red LED upon receiving that character. The board will "talk" to itself. The green LED should turn on whenever a message is sent and the LCD will display the message being received.
write a assembly language program to convert GRAY to BCD code in 8051
write a assembly language program to convert GRAY to BCD code in 8051
Develop an x86 assembly language program that properly executes an "x to the y power" function:...
Develop an x86 assembly language program that properly executes an "x to the y power" function: int power(int x, int y) Compute the integer value that is x to the y power Do not concern yourself with the possibility of overflow You may only use only a loop structure to compute the value Remember that the return value must be placed in the EAX register Make sure that any registers (not EAX) used by this function are placed back to...
Write an assembly language program code to clear and set bit 7th and 19th in a...
Write an assembly language program code to clear and set bit 7th and 19th in a 32-bit variable called N.
Please complete in MASM (x86 assembly language). Use the code below to get started. Use a...
Please complete in MASM (x86 assembly language). Use the code below to get started. Use a loop with indirect or indexed addressing to reverse the elements of an integer array in place. Do not copy the elements to any other array. Use the SIZEOF, TYPE, and LENGTHOF operators to make the program as flexible as possible if the array size and type should be changed in the future. .386 .model flat,stdcall .stack 4096 ExitProcess PROTO,dwExitCode:DWORD .data    ; define your...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT