PLEASE EXPLAIN EACH LINE OF CODE ONLY. USE COMMENTS NEXT TO EACH LINE TO EXPLAIN WHAT EACH IS CODE IS DOING THANKS. PLEASE COPY PASTE AFTER YOURE DONE NOT SCREENSHOT BECAUSE I NEED TO BE ABLE TO EDIT IT THANKS. // MODULE B: Method 2: Embedding an in-line asssembly language module in a C progrmming #include "stdafx.h" #include "stdio.h" #include<iostream> int main () { printf(" Lab_No_01_Getting_Stated_into_x86_Assembly_from_a_C++_program\n"); // Lab number and title here printf(" Module B: Embedding an in-line asssembly language module in a C progrmming \n"); printf(" James Rodriguez, ID#12345678\n"); // Student's name here printf(" CET3510-E205\n"); // Student's Class here printf(" Submission date: January 20, 2019\n"); // Date of the Student's program when submitted here printf(" Due date: January 28, 2019\n"); // Date of the Student's program due date printf(" Example 1.2 SimpleMathASM.cpp\n"); // Student's file name for the program here printf(" file name: SimpleMathASM.cpp\n"); // Student's file name for the program here printf("-----------------------------------------\n\n"); printf("Hello\n"); printf("Using EAX, EBX, and ECX 32-bits Registers\n"); int x, y, sum, diff; //A. Find the sum of two integers (sum = x + y) printf("Enter two integers from a keynoard to add\n"); scanf_s("%d%d", &x,&y); _asm { MOV EAX, 0; // To initilized register in zeros MOV EBX, 0; // To initilized register in zeros MOV ECX, 0; // To initilized register in zeros MOV EAX, x; // Load EAX with the value x MOV EBX, y; // Load EBX with the value y MOV ECX, EAX; ADD ECX, EBX; //Add EBX to ECX MOV sum, ECX; // sum = x + y this operation is substituted using 32-bit registers; } printf("Addition result = %d\n", sum); getchar(); // Hold the consult for result printf("*******************************************************************************\n"); //B. Find the difference of two integers (sub = x - y) printf("Enter two integers from a keynoard to minus\n"); scanf_s("%d%d", &x,&y); _asm { MOV EAX, 0; // To initilized register in zeros MOV EBX, 0; // To initilized register in zeros MOV ECX, 0; // To initilized register in zeros MOV EAX, x; // Load EAX with the value x MOV EBX, y; // Load EBX with the value y MOV ECX, EAX; SUB ECX, EBX; //Substract EBX from ECX MOV diff, ECX; // sub = x - y; this operation is substituted using registers; } printf("Subtraction result = %d\n", diff); system ("pause"); // Hold the consult for result return(0); }
EXPECTED ANSWER
The code is already explained with appropriate comments on each and every line.Please do refer the same.
code: #include "stdio.h"
#include
int main (void)
{
printf(" Lab_No_01_Getting_Stated_into_x86_Assembly_from_a_C++_program\n"); // Lab number and title here
printf(" Module A: C++ Programming approach \n"); // Lab module and title here
printf(" Mahfuz Adil, ID#23486522\n"); // Student's name here
printf(" CET3510-E205\n"); // Student's Class here
printf(" Submission date: February 6, 2019\n"); // Date of the Student's program when submitted here
printf(" Due date: February 6, 2019\n"); // Date of the Student's program due date
printf(" Example 1.1 SimpleMath.cpp\n"); // Student's file name for the program here
printf(" file name: SimpleMath.cpp\n"); // Student's file name for the program here
printf("-----------------------------------------\n\n");
int x, y, sum, sub;
printf("Hello\n");
//A. Find the sum of two integers (sum = x + y)
printf("Enter two integers from a keyboard to add\n");
scanf_s("%d %d", &x,&y);
sum = x + y;
printf("Addition result = %d\n", sum);
getchar(); // Hold the console for result
//B. Find the difference of two integers (sub = x - y)
printf("Enter two integers from a keyboard to minus\n");
scanf_s("%d %d", &x,&y);
sub = x - y;
printf("Subtraction result = %d\n", sub);
getchar(); // Hold the consule for result
system ("pause");
}
printf("Hello\n");
printf("Using EAX, EBX, and ECX 32-bits Registers\n");
int x, y, sum, diff;
//A. Find the sum of two integers (sum = x + y)
printf("Enter two integers from a keynoard to add\n");
scanf_s("%d%d", &x,&y);
_asm
{
MOV EAX, 0; // To initilized register in zeros
MOV EBX, 0; // To initilized register in zeros
MOV ECX, 0; // To initilized register in zeros
MOV EAX, x; // Load EAX with the value x
MOV EBX, y; // Load EBX with the value y
MOV ECX, EAX;
ADD ECX, EBX; //Add EBX to ECX
MOV sum, ECX;
// sum = x + y this operation is substituted using 32-bit registers;
}
printf("Addition result = %d\n", sum);
getchar(); // Hold the consult for result
printf("*******************************************************************************\n");
//B. Find the difference of two integers (sub = x - y)
printf("Enter two integers from a keynoard to minus\n");
scanf_s("%d%d", &x,&y);
_asm
{
MOV EAX, 0; // To initilized register in zeros
MOV EBX, 0; // To initilized register in zeros
MOV ECX, 0; // To initilized register in zeros
MOV EAX, x; // Load EAX with the value x
MOV EBX, y; // Load EBX with the value y
MOV ECX, EAX;
SUB ECX, EBX; //Substract EBX from ECX
MOV diff, ECX;
// sub = x - y; this operation is substituted using registers;
}
printf("Subtraction result = %d\n", diff);
system ("pause"); // Hold the consult for result
return(0);
}
int main ()
{
printf(" Lab_No_01_Getting_Stated_into_x86_Assembly_from_a_C++_program\n"); // Lab number and title here
printf(" Module C: Embedding an in-line asssembly language module in a C progrmming \n");
printf(" Mahfuz Adil, ID#23486522\n"); // Student's name here
printf(" CET3510-E205\n"); // Student's Class here
printf(" Submission date:February 6, 2019 \n"); // Date of the Student's program when submitted here
printf(" Due date: February 8, 2019\n"); // Date of the Student's program due date
printf(" Example 1.2 SimpleMathASM.cpp\n"); // Student's file name for the program here
printf(" file name: SimpleMathASM.cpp\n"); // Student's file name for the program here
printf("-----------------------------------------\n\n");
printf("Hello\n");
printf("Using AX, BX, and CX 16-bits registers replacing the 32-bit registers\n");
short int x, y, sum, diff;
//A. Find the sum of two integers (sum = x + y)
printf("Enter two integers from a keynoard to add\n");
scanf_s("%d%d", &x, &y);
_asm
{
MOV AX, 0; //To initilized register in zeros
MOV AX, x; // Load AX with the value x
MOV BX, y; // Load BX with the value y
MOV CX, AX;
SUB CX, BX; //Substract BX from CX
MOV diff, CX;
// sub = x - y; this operation is substituted using registers;
}
printf("Subtraction result = %d\n", diff);
system ("pause"); // Hold the consult for result
return(0);
}
Get Answers For Free
Most questions answered within 1 hours.