Question

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 = 4;

do

{

// Print the character

// In x86 assembly language you must use the following two lines of code:

// mov al, WHATEVER_CHARACTER_YOU_WANT_TO_PRINT

// call WriteChar

std::cout << *character;

// Increment the pointer

++character;

} while (--ecx != 0);

// In x86 assembly language you must use the following line of code:

// call CrLf

std::cout << std::endl;

// In x86 assembly language you must use the following line of code:

// call WaitMsg system("PAUSE");

}

Homework Answers

Answer #1

Here is the conversion of the C program into X86 assembly language

std::ostream::operator<<(std::ostream& (*)(std::ostream&))@plt:
 jmp    QWORD PTR [rip+0x2fd2]        # 404028 <std::ostream::operator<<(std::ostream& (*)(std::ostream&))@GLIBCXX_3.4>
 push   0x2
 jmp    401020 <.plt>
 jmp    QWORD PTR [rip+0x2fca]        # 404030 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char)@GLIBCXX_3.4>
 push   0x3
 jmp    401020 <.plt>
std::ios_base::Init::Init()@plt:
 jmp    QWORD PTR [rip+0x2fc2]        # 404038 <std::ios_base::Init::Init()@GLIBCXX_3.4>
 push   0x4
 jmp    401020 <.plt>
std::ios_base::Init::~Init()@plt:
 jmp    QWORD PTR [rip+0x2fba]        # 404040 <std::ios_base::Init::~Init()@GLIBCXX_3.4>
 push   0x5
 jmp    401020 <.plt>
main:
 push   rbp
 mov    rbp,rsp
 sub    rsp,0x10
 mov    DWORD PTR [rbp-0x4],0x4
 mov    rax,QWORD PTR [rip+0x2ed8]        # 404060 <character>
 movzx  eax,BYTE PTR [rax]
 movsx  eax,al
 mov    esi,eax
 mov    edi,0x404080
 call   401060 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char)@plt>
 mov    rax,QWORD PTR [rip+0x2ebf]        # 404060 <character>
 add    rax,0x1
 mov    QWORD PTR [rip+0x2eb4],rax        # 404060 <character>
 sub    DWORD PTR [rbp-0x4],0x1
 cmp    DWORD PTR [rbp-0x4],0x0
 setne  al
 test   al,al
 je     4011bd <main+0x4b>
 jmp    401181 <main+0xf>
 mov    esi,0x401030
 mov    edi,0x404080
 call   401050 <std::ostream::operator<<(std::ostream& (*)(std::ostream&))@plt>
 mov    eax,0x0
 leave  
 ret    
_GLOBAL__sub_I_word:
 push   rbp
 mov    rbp,rsp
 mov    esi,0xffff
 mov    edi,0x1
 call   4011d3 <__static_initialization_and_destruction_0(int, int)>
 pop    rbp
 ret    
 nop    WORD PTR cs:[rax+rax*1+0x0]

The output of the code is Golf

For any queries please comment

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In assembly masm use the code below! Write a program that reverse a string using indirect...
In assembly masm use the code below! Write a program that reverse a string using indirect addressing (may not use the stack - push/pop). The string will be given by the user and be up to 64 characters long INCLUDE Irvine32.inc INCLUDE macros.inc MAX = 64 .data source BYTE MAX DUP('#'),0 destination BYTE LENGTHOF source DUP('*'),0 actual_length DWORD ? ask BYTE "Enter a String: ",0 .code main proc ; ask user for input mov edx, OFFSET ask call WriteString ;...
Strings The example program below, with a few notes following, shows how strings work in C++....
Strings The example program below, with a few notes following, shows how strings work in C++. Example 1: #include <iostream> using namespace std; int main() { string s="eggplant"; string t="okra"; cout<<s[2]<<endl; cout<< s.length()<<endl; ​//prints 8 cout<<s.substr(1,4)<<endl; ​//prints ggpl...kind of like a slice, but the second num is the length of the piece cout<<s+t<<endl; //concatenates: prints eggplantokra cout<<s+"a"<<endl; cout<<s.append("a")<<endl; ​//prints eggplanta: see Note 1 below //cout<<s.append(t[1])<<endl; ​//an error; see Note 1 cout<<s.append(t.substr(1,1))<<endl; ​//prints eggplantak; see Note 1 cout<<s.find("gg")<<endl; if (s.find("gg")!=-1) cout<<"found...
Take the following program and translate it into PEP/9 assembly language: #include <iostream> using namespace std;...
Take the following program and translate it into PEP/9 assembly language: #include <iostream> using namespace std; int fib(int n) { int temp; if (n <= 0)    return 0; else if (n <= 2)    return 1; else {    temp = fib(n – 1);    return temp + fib(n-2); } } int main() {    int num;    cout << "Which fibonacci number? ";    cin >> num;    cout << fib(num) << endl;    return 0; } You...
Take the following program and translate it into PEP/9 assembly language: #include using namespace std; int...
Take the following program and translate it into PEP/9 assembly language: #include using namespace std; int fib(int n) { int temp; if (n <= 0)    return 0; else if (n <= 2)    return 1; else {    temp = fib(n – 1);    return temp + fib(n-2); } } int main() {    int num;    cout << "Which fibonacci number? ";    cin >> num;    cout << fib(num) << endl;    return 0; } You must...
Please complete in MASM (x86 assembly language). Use the code below to get started. Write a...
Please complete in MASM (x86 assembly language). Use the code below to get started. Write a program that uses a loop to calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(1) = 1, Fib(2) = 1, Fib(n) = Fib(n – 1) + Fib(n – 2). .386 .model flat,stdcall .stack 4096 ExitProcess PROTO,dwExitCode:DWORD .data    ; define your variables here .code main PROC    ; write your assembly code here    INVOKE ExitProcess,0 main...
Please provide answer in the format that I provided, thank you Write a program that prompts...
Please provide answer in the format that I provided, thank you Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must...
Take the following program and translate it into PEP/9 assembly language: #include <iostream> using namespace std;...
Take the following program and translate it into PEP/9 assembly language: #include <iostream> using namespace std; int theArray[] = { 5, 11, -29, 45, 9, -1}; void sumPos(int ary[], int len, int &sum) {    sum = 0;    for (int i = 0; i < len; i++)            if (ary[i] > 0)                sum = sum + ary[i]; } int main() {    int total;    sumPos(theArray, 6, total);    for (int k=0; k < 6; k++)      cout...
c++ Language Fix this code to have it concatenate two strings st1 and st2 and put...
c++ Language Fix this code to have it concatenate two strings st1 and st2 and put the result in st3 with a space separator. it has to be done using array representation of strings #include <iostream> using namespace std; #include <string> int main() { string st1,st2, st3; int c = 0, i =0;    cout << "Enter a string: "; cin >> st1; cout << "Enter another string: "; cin >> st2;    while (st1[c] != '\0'){ st3[c] = st1[c];...
C++ See the provided specification files. Complete the implementation for each as a separate file. void...
C++ See the provided specification files. Complete the implementation for each as a separate file. void seen(std::string); If there is already a Word object in the Words list, then the number of occurrences for this word is incremented. If there is no Word object for this word already, create a new word object with occurrence =1, and insert this object into the list of Word objects. std::string getNextWord(); Returns the next word of the list and sets the currentItem pointer...
How do you write x86 assembly code for the above main procedure and Addarrays function? Main()...
How do you write x86 assembly code for the above main procedure and Addarrays function? Main() {      int A[100];      int   B[100];      // initialization etc.      length = 100;      Call Addarrays(A, B, length) } Addarrays(int[] X, int[] Y, count) {    i = 0;    while (i < count) {        X[i] = X[i] + Y[i];         I++    } }