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
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
ADVERTISEMENT