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

Hi this is Assembly Language MASM x86 program. Please write it in the language and please...
Hi this is Assembly Language MASM x86 program. Please write it in the language and please explain it with comments thank you Please answer it I really need help this question was refunded before so please answer. Thank you so much also these are two separate programs thank you. 1) Write a procedure to read in decimal or hex number (byte-sized) Then write a procedure using shifts and ANDS to convert the string to a binary number (if is backward,...
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...
Convert this C++ program exactly as you see it into x86 assembly language: // Use the...
Convert this C++ program exactly as you see it into x86 assembly language: // Use the Irvine library for the print function #include <iostream> // The string that needs to be printed char word[] = "Golf\0"; // Pointer to a specific character in the string char * character = word; //NOTE: This main() function is not portable outside of Visual Studio void main() { // Set up a LOOP - See the while loop's conditional expression below int ecx =...
in assembly language x86 Masm, Write a program that calculate the first seven values of the...
in assembly language x86 Masm, Write a program that calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(0) = 0, Fib(1) = 1, Fib(2) = Fib(0)+ Fib(1), Fib(n) = Fib(n-1) + Fib(n-2). You NEED to calculate each value in the series "using registers and the ADD operation" You can also use variables, Have your program print out "The first seven numbers is" Use WriteInt for the printing, Place each value in the EAX...
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.
Please write in x86 Assembly language on Visual Studio. IRVINE32 Write a program to copy one...
Please write in x86 Assembly language on Visual Studio. IRVINE32 Write a program to copy one array of size 24 to another array of size 24 using string instructions. Write 3 versions of this code. One code must copy byte at a time. One code must copy word at a time and one code must copy double word at a time. Cut and paste the array in memory to show your code is working.
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
Explain the differences between an assembly language source code file, the listing file produced by 'nasm',...
Explain the differences between an assembly language source code file, the listing file produced by 'nasm', the object file (.o) and the final executable program.
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT