Question

URGENT HELP NEEDED :( Convert the following C++ program into an x86 assembly language program. Comment...

URGENT HELP NEEDED :(


Convert the following C++ program into an x86 assembly language program.
Comment the start of each "code block" that performs one of the listed mathematical calculations.
Comments go to the right of the actual code, all starting on the same column.
Post ONLY your ASM file here to Blackboard when complete.

// Global variables
char a = 5;
short b = 7;
int   c = 11;
int   d = 13;

// Code
int main()
{
    a = -a;
    d = b + 17;
    b = static_cast<short>(a);
    c = static_cast<int>(b);
    a = a - 3;
    d = static_cast<int>(a);
    
    // Move a into the eax register
    // Move b into the ebx register
    // Move c into the ecx register
    // Move d into the edx register
    // Call the DumpRegs function    

    a = 19;
    b = 108;
    c = 77;
    d = 7;
    c = -(a + b + c + d) + a + b + c;
    d = a + b - c - d - a + b + c - d - a - a + b + a + d + c;

    // Move a into the eax register
    // Move b into the ebx register
// Move c into the ecx register
    // Move d into the edx register
    // Call the DumpRegs function    

    // Call the WaitMsg function
}

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

//Global variable

a:

        .byte   5

b:

        .value  7

c:

        .long   11

d:

        .long   13

//code

main:

        push    rbp

        mov     rbp, rsp

        movzx   eax, BYTE PTR a[rip]

        neg     eax

        mov     BYTE PTR a[rip], al

        movzx   eax, WORD PTR b[rip]

        cwde

        add     eax, 17

        mov     DWORD PTR d[rip], eax

        movzx   eax, BYTE PTR a[rip]

        cbw

        mov     WORD PTR b[rip], ax

        movzx   eax, WORD PTR b[rip]

        cwde

        mov     DWORD PTR c[rip], eax

        movzx   eax, BYTE PTR a[rip]

        sub     eax, 3

        mov     BYTE PTR a[rip], al

        movzx   eax, BYTE PTR a[rip]

        movsx   eax, al

        mov     DWORD PTR d[rip], eax

// Move a into the eax register
    // Move b into the ebx register
    // Move c into the ecx register
    // Move d into the edx register
    // Call the DumpRegs function    

   mov     BYTE PTR a[rip], 19

        mov     WORD PTR b[rip], 108

        mov     DWORD PTR c[rip], 77

        mov     DWORD PTR d[rip], 7

        movzx   eax, BYTE PTR a[rip]

        movsx   eax, al

        movzx   edx, BYTE PTR a[rip]

        movsx   ecx, dl

        movzx   edx, WORD PTR b[rip]

        movsx   edx, dx

        add     ecx, edx

        mov     edx, DWORD PTR c[rip]

        add     ecx, edx

        mov     edx, DWORD PTR d[rip]

        add     edx, ecx

        sub     eax, edx

        mov     edx, eax

        movzx   eax, WORD PTR b[rip]

        cwde

        add     edx, eax

        mov     eax, DWORD PTR c[rip]

        add     eax, edx

        mov     DWORD PTR c[rip], eax

        movzx   eax, BYTE PTR a[rip]

        movsx   edx, al

        movzx   eax, WORD PTR b[rip]

        cwde

        add     edx, eax

        mov     eax, DWORD PTR c[rip]

        sub     edx, eax

        mov     eax, DWORD PTR d[rip]

        sub     edx, eax

        movzx   eax, BYTE PTR a[rip]

        movsx   eax, al

        sub     edx, eax

        movzx   eax, WORD PTR b[rip]

        cwde

        add     edx, eax

        mov     eax, DWORD PTR c[rip]

        add     edx, eax

        mov     eax, DWORD PTR d[rip]

        sub     edx, eax

        movzx   eax, BYTE PTR a[rip]

        movsx   eax, al

        sub     edx, eax

        movzx   eax, BYTE PTR a[rip]

        movsx   eax, al

        sub     edx, eax

        movzx   eax, WORD PTR b[rip]

        cwde

        add     edx, eax

        movzx   eax, BYTE PTR a[rip]

        movsx   eax, al

        add     edx, eax

        mov     eax, DWORD PTR d[rip]

        add     edx, eax

        mov     eax, DWORD PTR c[rip]

        add     eax, edx

        mov     DWORD PTR d[rip], eax

// Move a into the eax register
    // Move b into the ebx register
// Move c into the ecx register
    // Move d into the edx register
    // Call the DumpRegs function    
// Call the WaitMsg function

mov     eax, 0

        pop     rbp

        ret

Hope it helps.

Add a comment
Know the answer?
Add Answer to:
URGENT HELP NEEDED :( Convert the following C++ program into an x86 assembly language program. Comment...
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
  • NOTE: explain the lines in comments for better understanding Write an assembly program (for x86 processors...

    NOTE: explain the lines in comments for better understanding Write an assembly program (for x86 processors - Irvine) that has two procedures, a main procedure and a procedure called Fib. The fib procedure is to uses a loop to calculate and printout the first N Fibonacci numbers. Fibonacci sequence is described by the following formula: Fib(1) = 1, Fib(2) = 1, Fib(n) = Fib(n – 1) + Fib(n – 2). The value of N is to be communicated to this...

  • Question#1 Write a short program demonstrating that the INC and DEC instructions do not affect the...

    Question#1 Write a short program demonstrating that the INC and DEC instructions do not affect the Carry flag. Question#2 Write a program that uses addition and subtraction to set and clear the Overflow flag. After each addition or subtraction, insert the call DumpRegs statement to display the registers and flags. Make sure to include an ADD instruction that sets both the Carry and Overflow flags. Using comments, explain how and why the Overflow flag was affected by each instruction. Question#3...

  • X86 Assembly Language Help to implement the CipherChar Procedure at the end of the given code...

    X86 Assembly Language Help to implement the CipherChar Procedure at the end of the given code INCLUDE Irvine32.inc         .data       KeyPrompt BYTE "Enter the passphrase: ",0       TextPrompt BYTE "Enter the plaintest: ",0           str1 BYTE "The passphrase has length:",0           str2 BYTE "The plaintest has length:",0       KeyIs BYTE "The passphrase: ",0       PlainTextIs BYTE "The plaintext: ",0       CipherTextIs BYTE "The ciphertext: ",0       KMAX = 64                        ; passphrase buffer maximum size       BMAX = 128                       ; test...

  • For the C code 1 int loop while(int a, int b) int result 1; while (a < b) t result (atb); return ...

    For the C code 1 int loop while(int a, int b) int result 1; while (a < b) t result (atb); return result; Gcc generates the following assembly code: %ebp+8, mov1 movl movl %ebp+12 at 8(%ebp) ,%ecx 12(%ebp) ,%ebx $1,%eax a at b 5 jge L11 leal (%ebx, %ecx), Xodx 8 L12: inull %eax , %eax addl $1,%ecx addl $1, edx cmp1 %ecx , %ebx 9 10 12 13 J8 14 ·L11: .L12 In generating this code, occ makes an...

  • Using the AddTwo program from Section 3.2 as a reference, write a program that calculates the...

    Using the AddTwo program from Section 3.2 as a reference, write a program that calculates the following expression, using registers: A = (A + B) + (C + D). Assign integer values to the EAX, EBX, ECX, and EDX registers. AddTwo program: ; AddTwo.asm - adds two 32-bit integers ; Chapter 3 example .386 .model flat,stdcall .stack 4096 ExitProcess PROTO, dwExitCode:DWORD .code main PROC mov eax,5 ; move 5 to the eax register add eax,6 ; add 6 to the...

  • Assembly Language NASM create a substring ASSIGNMENT INSTRUCTIONS: Create the Substring from the Given string, beginIndex...

    Assembly Language NASM create a substring ASSIGNMENT INSTRUCTIONS: Create the Substring from the Given string, beginIndex and endIndex The program should create a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex – 1. Thus the length of the substring is endIndex-beginIndex. In other words you can say that beginIndex is inclusive and endIndex is exclusive while getting the substring. Initialize the following values in...

  • I need help creating this code. Write an assembly program (MASM and Irvine's libraries) that calculates...

    I need help creating this code. Write an assembly program (MASM and Irvine's libraries) that calculates and prints out the first five Fibonacci numbers FO=0; F1=1; F2=1; F3=F1+F2; F4=F3+F2; F5=F4+F3 If we use 0, 1 and initial conditions the sequence would be: 0, 1, 1, 2, 3 Use the ebx, eax, and ecx registers. Note WriteHex, Writelnt, WriteDec, all use eax So use ebx for first and eax for second and ecx for temporary The calculation could go something like...

  • 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...

  • 1) Assume the registers are initialized to the indicated values: Se al A c and code...

    1) Assume the registers are initialized to the indicated values: Se al A c and code frogments MUST use 32 ぁ ar movennes (anor be "nedfra-ne ibrary function or procedural calls ino- Pe Peue c for ll codr ond code frogments only othu ey document your code with Comments unless the code size is Drow Fow Chort for any flow of control involving branches and loops Use PoCedures as modules to organize most of the code and code fragments. In...

  • Assembly Please answer the following above, compile and single step through the program, writing...

    Assembly Please answer the following above, compile and single step through the program, writing down the value of the destination for each instruction. 1. Using Visual Studio on the system, create a project using the code given below unsigned char short int int gArray 0x09, 0xFA, 0x5A, 0x18, 0x48, 0xAC, 0xD4, 0x71 ; cAr rays 1 [ ] = { 0:09, 0xfa, Ox5A, Ox18, 0x48, OxAC, OxD4, 0x71 }; gArray! [ ] = { Ox09, OxFA, Ox5A, Ox18, 0x48, OxAC,...

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