Question

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

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

// Global variables
short a = 5;
short b = 6;
short c = 7;
short d = 8;
short e;
short f;
short g;
short h;

// Code
int main()
{
    ++d;
    --c;
    b = a + 2;
    a = d + 9;
    e = a + b - c - d;
    f = -c;
    g = f + e;
    h = -b - c + 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   

    // Move e into the eax register
    // Move f into the ebx register
    // Move g into the ecx register
    // Move h into the edx register
    // Call the DumpRegs function   
   
    --h;
    g = g + 6;
    f = 16;
    e = -g - f;
    d = 5 - e;
    c = -c;
    b = c + e - h;
    a = -b + c - d;
   
    // 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   

    // Move e into the eax register
    // Move f into the ebx register
    // Move g into the ecx register
    // Move h 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

Given the following global variables

short a = 5;
short b = 6;
short c = 7;
short d = 8;

Since all they were datatype of short , in x86 we can use [EAX] type register to store them.

Let us first declare the variables as above,

main:

MOV A,5; //ASSIGNING INTEGER 5 TO A

MOV B,6;  //ASSIGNING INTEGER 6 TO B

MOV C,7;  //ASSIGNING INTEGER 7 TO C

MOV D,8;  //ASSIGNING INTEGER 8 TO D

INC D; //++D Increments D by 1 i.e,8+1=9

DEC C; //--C Decrements C by 1 i.e, 7-1=6

MOV B,A; // perfoms B=A i.e, B=5

ADD B.2 ; //B=5+2=7

MOV A,D;   // perfoms A=D i.e, A=9

ADD A,9; // A=9+9=18

MOV AX,A;

ADD AX,B; // Register AX Stores A+B i.e,18+2=20

MOV BX,C; //BX=6

ADD BX,D; //Register BX stores C+D i.e,6+9=15

SUB AX,BX; //Performs AX-BX i.e, A+B-(C+D) that will be stored in AX i.e,20-15=5

MOV E,AX; // E=5

MOV AX,0; // Intialising AX=0

SUB AX,C; //Stores the negative value of c i.e, -6

MOV F,AX // F=-C i.e,-6

ADD G,F,E; //Adds E,F and stores the result in G i.e, G=-6+5=-1

MOV AX,B;

ADD AX,C; // Register AX Stores B+C i.e,7+6=13

MOV BX,A;

SUB BX,AX // Performs A-(B+C) since B+C stored in AX i.e,18-13=5

MOV H,BX; //H=5;

Since it was mentioned in the problem statement that move the variables into respective registers,

MOV [EAX],A; // Move a into the eax register

MOV [EBX],B;    // Move b into the ebx register
MOV [ECX],C;    // Move c into the ecx register
MOV [EDX],D;     // Move d into the edx register

Call DumpRegs ; // Usually calls the procedure to Display the current values that are present in the registers.

MOV [EAX],E; // Move a into the eax register

MOV [EBX],F;    // Move b into the ebx register
MOV [ECX],G;    // Move c into the ecx register
MOV [EDX],H;     // Move d into the edx register

Call DumpRegs ; // Usually calls the procedure to Display the current values that are present in the registers.

DEC H; //--H Decrements H by 1 i.e, 5-1=4

ADD G,6; //G=G+6 i.e,-1+6=5

MOV F,16; //F=16

MOV AX,G;

ADD AX,F; // Register AX Stores G+F i.e,5+16=21

MOV BX,0;

SUB BX,AX // Stores negative value of AX i.e,-21

MOV E,BX //E=-21 // e = -g - f;

MOV AX,5;

SUB AX,E; // 5-E i.e,5-(-21)=26

MOV D,AX //D=26; //d = 5 - e =26

MOV AX,0; // Intialising AX=0

SUB AX,C; //Stores the negative value of c i.e, -6

MOV C,AX //  c = -c i.e, C=-6

MOV AX,0;

ADD AX,C,E; //AX=C+E i.e,-6+(-21)=-27

SUB AX,H; //-27-4=-31

MOV B,AX //  b = c + e - h i.e, B=-31

MOV AX,B;

ADD AX,D; // Register AX Stores B+D i.e,-31+26=-5

MOV BX,C;

SUB BX,AX // Performs C-(B+D) since B+D stored in AX i.e,-6-(-5)=-1

MOV A,BX; //A=-1; //a = -b + c - d;

Since it was mentioned in the problem statement that move the variables into respective registers,

MOV [EAX],A; // Move a into the eax register

MOV [EBX],B;    // Move b into the ebx register
MOV [ECX],C;    // Move c into the ecx register
MOV [EDX],D;     // Move d into the edx register

Call DumpRegs ; // Usually calls the procedure to Display the current values that are present in the registers.

MOV [EAX],E; // Move a into the eax register

MOV [EBX],F;    // Move b into the ebx register
MOV [ECX],G;    // Move c into the ecx register
MOV [EDX],H;     // Move d into the edx register

Call DumpRegs ; // Usually calls the procedure to Display the current values that are present in the registers.

Call WaitMsg ; //Displays the message "Press[Enter] to continue" and pauses the program until the user presses the enter key.

   

Add a comment
Know the answer?
Add Answer to:
URGENT HELP NEEDED Convert the following C++ program into an x86 assembly language program. Comment the...
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
  • 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() {    ...

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

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

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

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

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

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

  • Assembly MASM x86 Write a complete program that sorts dword unsigned integer array in descending order....

    Assembly MASM x86 Write a complete program that sorts dword unsigned integer array in descending order. Assume that the user doesn’t enter more than 40 integers. You MUST use the template and follow all the directions there. You can’t add any more procedures to the template. The procedures can’t use any global variables (variables that are inside .data segment). The caller of any procedures sends its argument through the stack. Inside any procedures, if you need to use a register,...

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