Question
question : Use comments to explain every single line of the following C++ and assembly code. #include stdio.h #include int main (void) { printf( Lab_No_01_Getting_Stated_into_x86_Assembly_from_a_C++_program
question : Use comments to explain every single line of the following C++ and assembly code.
#include "stdio.h" #include
int main (void) {
printf(" Lab_No_01_Getting_Stated_into_x86_Assembly_from_a_C++_program "); // Lab number and title here printf(" Module A: C++ Programming approach "); // Lab module and title here printf(" Mahfuz Adil, ID#23486522 "); // Student's name here printf(" CET3510-E205 "); // Student's Class here printf(" Submission date: February 6, 2019 "); // Date of the Student's program when submitted here printf(" Due date: February 6, 2019 "); // Date of the Student's program due date printf(" Example 1.1 SimpleMath.cpp "); // Student's file name for the program here printf(" file name: SimpleMath.cpp "); // Student's file name for the program here printf("----------------------------------------- ");
int x, y, sum, sub; printf("Hello ");
//A. Find the sum of two integers (sum = x + y) printf("Enter two integers from a keyboard to add "); scanf_s("%d %d", &x,&y); sum = x + y; printf("Addition result = %d ", 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 "); scanf_s("%d %d", &x,&y); sub = x - y; printf("Subtraction result = %d ", sub); getchar(); // Hold the consule for result system ("pause"); }
printf("Hello "); printf("Using EAX, EBX, and ECX 32-bits Registers "); int x, y, sum, diff;
//A. Find the sum of two integers (sum = x + y) printf("Enter two integers from a keynoard to add "); 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 ", sum); getchar(); // Hold the consult for result
printf("******************************************************************************* ");
//B. Find the difference of two integers (sub = x - y) printf("Enter two integers from a keynoard to minus "); 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 ", 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 "); // Lab number and title here printf(" Module C: Embedding an in-line asssembly language module in a C progrmming "); printf(" Mahfuz Adil, ID#23486522 "); // Student's name here printf(" CET3510-E205 "); // Student's Class here printf(" Submission date:February 6, 2019 "); // Date of the Student's program when submitted here printf(" Due date: February 8, 2019 "); // Date of the Student's program due date printf(" Example 1.2 SimpleMathASM.cpp "); // Student's file name for the program here printf(" file name: SimpleMathASM.cpp "); // Student's file name for the program here printf("----------------------------------------- ");
printf("Hello "); printf("Using AX, BX, and CX 16-bits registers replacing the 32-bit registers "); 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 "); scanf_s("%d%d", &x, &y); _asm { MOV AX, 0; // To initilized register in zeros MOV BX, 0; // To initilized register in zeros MOV CX, 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; ADD CX, BX; //Add BX to CX MOV sum, CX;
// sum = x + y this operation is substituted using 32-bit registers; } printf("Addition result = %d ", sum); getchar(); // Hold the consult for result
printf("******************************************************************************* ");
//B. Find the difference of two integers (sub = x - y) printf("Enter two integers from a keynoard to minus "); scanf_s("%d%d", &x, &y); _asm { MOV AX, 0; // To initilized register in zeros MOV BX, 0; // To initilized register in zeros MOV CX, 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 ", diff);
system ("pause"); // Hold the consult for result return(0); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started