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 ;...
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...
program has to be written in X86 processor assy language. Write a program that find the...
program has to be written in X86 processor assy language. Write a program that find the minimum number of coins that can represent an amount of money under $1. The amount of money is a random number between 0 and 99 (cents). The randomRange procedure is used to get a random number. Review the sample code in lab4.asm and run it to see how randomRange works. Each time randomRange is called, it creates a random number between 0 and the...
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...
Use MARS to write and simulate a MIPS assembly language program to swap two of the...
Use MARS to write and simulate a MIPS assembly language program to swap two of the integers in an integer array. The program should include the Swap function to swap the integers and the main function to call the Swap function. Download the template file “P4_template.asm” provided on Blackboard. Add your code to this file. Do not modify any of the code provided in the file. The main function should: • Pass the starting address of the array in $a0....
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...
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++    } }
Use MIPS assembly language program to swap two of the integers in an integer array. The...
Use MIPS assembly language program to swap two of the integers in an integer array. The program should include the Swap function to swap the integers and the main function to call the Swap function. The main function should: • Pass the starting address of the array in $a0. • Pass the indices of the two elements to swap in $a1 and $a2. • Preserve (i.e. push onto the stack) any T registers that it uses. • Call the Swap...
The code is in C programming language pls convert it into python. Thanks. Program --> #include...
The code is in C programming language pls convert it into python. Thanks. Program --> #include <stdio.h> #include <stdlib.h> void main() { //declare variables FILE *fileptr; char filename[15]; char charRead; char filedata[200],searchString[50]; int i=0,j=0,countNoOfWord=0,count=0; //enter the filename to be opened printf("Enter the filename to be opened \n"); scanf("%s", filename); /* open the file for reading */ fileptr = fopen(filename, "r"); //check file exit if (fileptr == NULL) { printf("Cannot open file \n"); exit(0); } charRead = fgetc(fileptr); //read the string...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT