Question

Convert this C++ program to x86 assembly language using the Irvine library: #include <iostream> unsigned int...

Convert this C++ program to x86 assembly language using the Irvine library:

#include <iostream>

unsigned int x;
unsigned int c;
unsigned int result;

// f(x) = 8x + c
// Make sure to push and pop all necessary registers to the stack to
// ensure only the EAX register is modified upon return from the function
unsigned int Equation(unsigned int x, unsigned int c)
{
// You CANNOT use the mul or imul operations to perform the multiplication
return (8 * x) + c;
}

void main()
{
std::cout << "Enter a value for x: ";
std::cin >> x;
std::cout << "Enter a value for c: ";
std::cin >> c;
result = Equation(x, c);
std::cout << "f(x) = " << result << std::endl;
system("PAUSE");
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

x:

        .zero   4

c:

        .zero   4

result:

        .zero   4

Equation(unsigned int, unsigned int):

        push    rbp

        mov     rbp, rsp

        mov     DWORD PTR [rbp-4], edi

        mov     DWORD PTR [rbp-8], esi

        mov     eax, DWORD PTR [rbp-4]

        lea     edx, [0+rax*8]

        mov     eax, DWORD PTR [rbp-8]

        add     eax, edx

        pop     rbp

        ret

.LC0:

        .string "Enter a value for x: "

.LC1:

        .string "Enter a value for c: "

.LC2:

        .string "f(x) = "

.LC3:

        .string "PAUSE"

main:

        push    rbp

        mov     rbp, rsp

        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*)

        mov     esi, OFFSET FLAT:x

        mov     edi, OFFSET FLAT:_ZSt3cin

        call    std::basic_istream<char, std::char_traits<char> >::operator>>(unsigned int&)

        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*)

        mov     esi, OFFSET FLAT:c

        mov     edi, OFFSET FLAT:_ZSt3cin

        call    std::basic_istream<char, std::char_traits<char> >::operator>>(unsigned int&)

        mov     edx, DWORD PTR c[rip]

        mov     eax, DWORD PTR x[rip]

        mov     esi, edx

        mov     edi, eax

        call    Equation(unsigned int, unsigned int)

        mov     DWORD PTR result[rip], 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 result[rip]

        mov     esi, eax

        mov     rdi, rdx

        call    std::basic_ostream<char, std::char_traits<char> >::operator<<(unsigned 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     edi, OFFSET FLAT:.LC3

        call    system

        mov     eax, 0

        pop     rbp

        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_x:

        push    rbp

        mov     rbp, rsp

        mov     esi, 65535

        mov     edi, 1

        call    __static_initialization_and_destruction_0(int, int)

        pop     rbp

        ret

Add a comment
Know the answer?
Add Answer to:
Convert this C++ program to x86 assembly language using the Irvine library: #include <iostream> unsigned int...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Convert following code to implement linked list C++ language #include<iostream> using namespace std; int top =...

    Convert following code to implement linked list C++ language #include<iostream> using namespace std; int top = -1; //globally defining the value of top, as the stack is empty void push(int stack[], int x, int n) { if (top == -1) //if top position is the last of posiition of stack,means stack is full { cout << "Stack is full Overflow condition"; } else { top = top + 1; //incrementing top position stack[top] = x; //inserting element on incremented position...

  • Add comments on this Fibonacci C++ program in detail. #include <iostream> using namespace std; int fib(int...

    Add comments on this Fibonacci C++ program in detail. #include <iostream> using namespace std; int fib(int n){ int a = 0,b = 1,c; if(n == 0 || n == 1){ return n; } while(n>2){ c = b + a; a = b; b = c; n--; } return c; } int main(){ int n; cout<<"Enter n: "; cin>>n; int result = fib(n); cout<<"Fib("<<n<<") = "<<result<<endl; return 0; }

  • Convert to use functions where possible #include<iostream> #include<string> using namespace std; int main() {    string...

    Convert to use functions where possible #include<iostream> #include<string> using namespace std; int main() {    string first, last, job;    double hours, wages, net, gross, tax, taxrate = .40;    double oPay, oHours;    int deductions;    // input section    cout << "Enter First Name: ";    cin >> first;    cout << "Enter Last Name: ";    cin >> last;    cin.ignore();    cout << "Enter Job Title: ";    getline(cin, job);    cout << "Enter Hours Worked:...

  • #include <iostream> #include <chrono> using namespace std; double improvedPow(double x, int y) { // To be...

    #include <iostream> #include <chrono> using namespace std; double improvedPow(double x, int y) { // To be implemented by you } int main() { cout << "To calculate x^y ..." << endl; double x; int y; cout << "Please enter x: "; cin >> x; cout << "Please enter y: "; cin >> y; if(x == 0) { if (y > 0) cout << 0 << endl; else cout << "x^y is not defined" <<endl; } else { cout << improvedPow(x,y)...

  • Find two syntax errors in the following program: #include <iostream> using namespace std; int area(int length,...

    Find two syntax errors in the following program: #include <iostream> using namespace std; int area(int length, int width = 0); int main() { int length, width; // for rectangle use both arguments cout << "Enter length and width of a rectangle" << endl; cin >> length >> width; cout << "The area is " << area(length, width) << endl; // for square, only need first argument cout << "Enter side of a square" << endl; cin >> length; cout <<...

  • #include <iostream> #include <stack> #include <queue> using namespace std; void printFromStack(string expr){ stack<char> myStack; for(int i=0;...

    #include <iostream> #include <stack> #include <queue> using namespace std; void printFromStack(string expr){ stack<char> myStack; for(int i=0; i<expr.length(); i++){ //Insert code here to push each character onto the stack } cout << "My stack is popped in this order" << endl; while(!myStack.empty()){ //Insert code here to cout the top of the stack one by one //Pop each one after it’s printed out } cout << endl; } void printFromQueue(string expr){ queue<char> myQueue; //Insert code here to push each character onto the...

  • #include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int...

    #include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int num1, num2, result; while(ch == 'Y'){ cout << "Enter first number: "; cin >> num1; while(1){//for handling invalid inputs if(cin.fail()){ cin.clear();//reseting the buffer cin.ignore(numeric_limits<streamsize>::max(),'\n');//empty the buffer cout<<"You have entered wrong input"<<endl; cout << "Enter first number: "; cin >> num1; } if(!cin.fail()) break; } cout << "Enter second number: "; cin >> num2; while(1){ if(cin.fail()){ cin.clear(); cin.ignore(numeric_limits<streamsize>::max(),'\n'); cout<<"You have entered wrong input"<<endl; cout <<...

  • 1.Write an assembly language program that corresponds to the following C++ program: #include <iostream> using namespace...

    1.Write an assembly language program that corresponds to the following C++ program: #include <iostream> using namespace std; const int amount = 20000; int num; int sum; int main () { cin >> num; sum = numb + amount; cout << "sum = " ,<< sum << endl; return 0; } 2. Test the program in the previous question twice. The first time, enter a value for num to make the sum within the allowed range for the Pep/8 computer. The...

  • Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout...

    Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout << "Enter an integer cin >> number; if (number > B) cout << You entered a positive integer: " << number << endl; else if (number (8) cout<<"You entered a negative integer: " << number << endl; cout << "You entered e." << endl; cout << "This line is always printed." return 0;

  • Who could write the array.cpp file ?   //main.cpp #include "array.hpp" #include <iostream> int main() { int...

    Who could write the array.cpp file ?   //main.cpp #include "array.hpp" #include <iostream> int main() { int n; std::cin >> n; array a(n); for (int i = 0; i < n; i++) { std::cin >> a.data()[i]; } std::cout << "array size:" << a.max_size() << std::endl; std::cout << "array front:" << a.front() << std::endl; std::cout << "array back:" << a.back() << std::endl; int* data = a.data(); std::cout << "array elements using data:" << std::endl; for (int i = 0; i < n;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT