Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assembly language for x86 processors using in c++ Computer Science 240 Project N

ID: 3748284 • Letter: A

Question

Assembly language for x86 processors using in c++

Computer Science 240 Project No. 3 (division, multiplication, and making decisions) Write assembly programs with the following vo I 7-11 Convenient Store Drinks Soda(S). Water (W).. Sandwiches 12 inches.. .S5 Second run: How many drinks? 3 How many drinks? 2 How many Sandwiches? 3 Your total billxx What kind of drink(S-Soda, W Water)? S What kind of drink(S Soda, W-Water)? W How many Sandwiches?3 What size of sandwich (10/12 inches)? 10 What size of sandwich (10/12 inches)? 12 Your total bill xx 2. Let's compute your score's average: Enter your score (-1) to stop: 70 Enter your score (-1) to stop: 88 Enter your score (-1) to stop: 90 Enter your score (-1) to stop: 77 Enter your score (-1) to stop: -1 Your average is XX 3. Read a person's name, age, and gender (m for male, f for female, case sensitive). Determine whether the person is a female teenager or not Enter your name: Pamela Pamela, how old are you? 16 Pamela, what is your gender (m/f)? Second run Enter your name:John John, how old are you? 16 John, what is your gender (m/f)? m Hi Pamela, you are a female teenager Hi John, you are not a female teenager 4. We want to solve a system of two equations with two unknowns X and Y using Cramer's rule a"f-c"d a"e-b*d Write an assembly program to ask for the values of a,b,c and d.e,f (all short type). Compute and print the values of X and Y (both short type) Enter the values of a,b, and c:3 11 Enter the values of d,e, and f: 1 -25 This program solves the system

Explanation / Answer

Part1.cpp

#include<iostream>


using namespace std;

short drinkNum = 0;
short drinkType = (short)'W';
short sandwichNum;
short sandwichSize = 10;
short total = 0;

void menu() {
   char myDrinkType;
   cout << "---------------7-11 Convenient Store ---------------" << endl;
   cout << "Drinks" << endl;
   cout << " Soda(S)..............................$2" << endl;
   cout << " Water(W).............................$1" << endl;
   cout << "Sandwiches" << endl;
   cout << " 10 inches............................$3" << endl;
   cout << " 12 inches............................$5" << endl;
   //This is how many drinks...
   cout << "How many drinks? ";
   cin >> drinkNum;


   //This is what type of drink
   cout << " What kind of drink (S=Soda, W=Water)? ";
   cin >> myDrinkType;
   //This is how many sandwiches;

   cout << "How many sandwiches?";
   cin >> sandwichNum;
   cout << endl << " What size of sandwich (10/12 inches)? ";
   cin >> sandwichSize;
   myDrinkType = toupper(myDrinkType);
   //cout << "Get ready" << endl;
   drinkType = (short)myDrinkType;
}
void thankYou()
{
   cout << "Your total bill is " << total << endl;
   system("Pause");
}


int main() {


   __asm {
       call menu;
       mov ax, drinkNum;       //ax = num of drinks
       mov bx, sandwichNum;   //bx = num of sandwiches
       mov cx, drinkType;       //cx = types of drinks      
       cmp cx, 'W';
       je true1;
   false1:
       cmp cx, 'S'; //Check if soda
       jmp true2;
   true1:
       //Drinks multiplied by 1      
       mov total, ax; //total = 1*drinks
       jmp testSandwich;
   true2:
       mov bx, 2; //bx = 2
       cwd; //Ready multiplication.
       imul ax, bx; //ax = 2*soda
       mov total, ax; //total = 2*soda
   testSandwich:
       mov ax, sandwichNum; //Num of sandwiches
                           //Get sandwich type.
       mov cx, sandwichSize; //Get the size
                              //See if it is 10 inches
       cmp cx, 10;
       je sandTen;
   sandTwelve:
       mov ax, sandwichNum; //Num of Sandwiches
       cwd; //prepare 12 inches * 5
       imul ax, 5; //sand*12
       add total, ax; //Gets total.
       jmp finish;
   sandTen:
       mov ax, sandwichNum; //Num of Sandwiches
       cwd; //prepare 12 inches * 5
       imul ax, 3; //sand*3
       add total, ax; //Gets total.
       jmp finish;
   finish:
       call thankYou;

   }


}


Part2.cpp


#include "stdafx.h"
#include <iostream>

using namespace std;

int intergerInput = 0;
int negitiveOne = -1;
int average = 0;
int counter = 0;
int> int emptyInt = 0;
int decPlace = 0;

void mainMessage() {
   cout << "Let's compute your score's average:" << endl;
}

void loopMessage()
{
   cout << "Enter your score(-1 to stop): ";
   cin >> intergerInput;
}
void endMessage()
{
   cout << endl << "Your Average is " << average << endl;
   cin >> average;// just to pause the program for user input before closing so results can be seen.
}

int main() {
   __asm {
       call mainMessage;
       mov ebx, negitiveOne;// place the -1 value in the ebx reg
   LoopBack:
       call loopMessage;
       mov eax, intergerInput;
       cmp negitiveOne, eax;// Flag EAX and the Negitive ONe value for INput
       je True;// Test if the User input equals -1
   False://If input does not equal -1
       add average, eax;
       mov ecx, counter;
       add ecx, 1;
       mov counter, ecx;
       jmp LoopBack;

   True://If input equals -1
       mov eax, average;
       mov ecx, counter;
       cdq;
       idiv ecx;
       mov average, eax;//Moving averge calc from EAX to average Int Var for cout later
       call endMessage;
   }
   return 0;
}


Part3.cpp

#include<iostream>
#include<cstdio>

using namespace std;
short adultMalePrice = 100;
short teenMalePrice = 75;
short adultFemPrice = 80;
short teenFemPrice = 85;
short age = 0;
char gender = 'M';
short total = 0;
char male = 'M';
char female = 'F';

void menu()
{
   cout << "--------------------ACE CLUB--------------------" << endl;
   cout << "Male" << endl;
   cout << " Adult( age > 19 ).......................$100" << endl;
   cout << " Teenager( age 13-19 )....................$75" << endl;
   cout << "Female" << endl;
   cout << " Adult( age > 19 ).......................$80" << endl;
   cout << " Teenager( age 13-19 )...................$85" << endl;
   cout << "How old are you? ";
   cin >> age;
   cout << "What is your gender (M/F)? ";
   char myGender;
   cin >> myGender;
   //Convert
   gender = myGender;
  


}
void thankyou()
{
   cout << "Your membership is $" << total << endl;

}
void kidWarn()
{
   cout << "You are a kid. No membership for you" << endl;

}
void theEnd()
{
   cout << "Thank you for your time." << endl;
   system("Pause");
}

int main()
{
   __asm {
       //gender, age,
       //Determine gender
   menu:
       call menu; //Menu gets variables.
       mov al, gender; //al = gender
       cmp al, male;
       je male1;
       cmp al, 'm';
       je male1;
       //Check for female.
       mov al, female;
       cmp al, female;
       je female1;
       //Check for female lowercase
       mov al, female;
       cmp al, 'f';
       je female1;
       jmp menu;
   female1:
       mov ax, age; //ax = age
       cmp ax, 20; //
       jge femaleTwenty;
       cmp ax, 13;
       jge female13to19;
       jmp kid;
   femaleTwenty:
       //20 years old female.
       mov total, 80;
       jmp finish;
   female13to19:
       mov ax, age;
       mov total, 85;
       jmp finish;
   male1:
       mov ax, age; //ax = age
       cmp ax, 20; //
       jge maleTwenty;
       cmp ax, 13;
       jge male13to19;
       jmp kid;
   maleTwenty:
       //20 years old female.
       mov total, 100;
       jmp finish;
   male13to19:
       mov ax, age;
       mov total, 75;
       jmp finish;
   kid:
       call kidWarn;
       jmp endgame;

   finish:
       call thankyou;

   endgame:
       call theEnd;
   }
   return 0;
}


Part4.cpp

#include "stdafx.h"
#include <iostream>

using namespace std;

short a = 0, b = 0, c = 0;
short d = 0, e = 0, f = 0;
short x = 0, y = 0;

short temp1 = 0, temp2 = 0;
short upperHalf = 0, lowerHalf = 0;
short zero = 0, negitiveOne = -1;


void mainMessage()
{
   cout << "This program solves the system" << endl << "aX + bY =c" << endl;
   cout << "dX + eY = f" << endl;
   cout << "ENter the values of a,b, and c:";
   cin >> a >> b >> c;
   cout << endl;
   cout << "Enter the values of d,e, and f:";
   cin >> d >> e >> f;
   cout << endl;
}

void endMessage()
{
   cout << "X =" << x << "      " << "Y =" << y;
   cin >> x;// to pause program
}

int main()
{
   __asm {
       call mainMessage;
       //First calculating Y
       //Firstly the Upper half of the equation
       //(a*f - c*d)
       mov ax, a;
       mov bx, f;
       mul bx;
       mov temp1, ax;

       mov ax, c;
       mov bx, d;
       mul bx;
       mov temp2, ax;

       mov ax, temp1;
       mov bx, temp2;
       sub ax, bx;
       mov upperHalf, ax;
       //Then the lower half
       //(a*e - b*d)
       mov ax, a;
       mov bx, e;
       mul bx;
       mov temp1, ax;

       mov ax, b;
       mov bx, d;
       mul bx;
       mov temp2, ax;

       mov ax, temp1;
       mov bx, temp2;
       sub ax, bx;
       mov lowerHalf, ax;
           //final Y calc
       mov ax, upperHalf;
       mov bx, lowerHalf;
       idiv bx;
       mov y, ax;
       //Lastly calculate X
       //Top Half
       //(c*e - b*f)
       mov ax, c;
       mov bx, e;
       mul bx;
       mov temp1, ax;

       mov ax, b;
       mov bx, f;
       mul bx;
       mov temp2, ax;

       mov ax, temp1;
       mov bx, temp2;
       sub ax, bx;
       mov upperHalf, ax;
      
       //Lower half
       //(a*e - b*d)
       mov ax, a;
       mov bx, e;
       mul bx;
       mov temp1, ax;

       mov ax, b;
       mov bx, d;
       mul bx;
       mov temp2, ax;

       mov ax, temp1;
       mov bx, temp2;
       sub ax, bx;
       mov lowerHalf, ax;
           //final X calc
       mov ax, upperHalf;
       mov bx, lowerHalf;
       imul negitiveOne;
       idiv bx;
       imul negitiveOne;
       mov x, ax;
       call endMessage;
   }

    return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote