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

in Assembly language X86 processors starting with _asm{} Project No. 4 (loop str

ID: 3751852 • Letter: I

Question

in Assembly language X86 processors starting with _asm{}

Project No. 4 (loop structures) Write assembly programs for each of the following. All functions must be written in assembly 1. Read a string of 10 'y'( for YES votes) and 'n'l for NO votes). Count the number of YES and NO votes and ten displayaccording to the frequency of the votes Sample Vo Enter a string of votes: ynnyynyyvy No. of YES votes 7 No. of NO votes-3 2. Read a sentence with period at the end. Display the sentence so that all vowels are in uppercase Sample I/o Enter a sentence: proud is self-respect. Output: prOUd Is sElf-rEspEct. 3-Practice Addition&Subtraction a. Practice Addition b. Practice Subtraction Enter your choice(a/b): a 22 33? 55 CORRECT Continue(y/n)? y 11+55-?75 WRONG Continuely/n)? N No. of CORRECT answers 1 No. of WRONG answers 1 Are you donely/n)? n Enter your choice(a/b):b 44-33 ? 12 WRONG Continue(y/n)? y 11- 30?29 WRONG Continue(y/n)? n No. of CORRECT answers- No. of WRONG answers 2 Have a nice day Choices are lowercase Are you done(y/n)? Y NOTES.-Numbers are random integers between 1 and 100 - Continuation choices are case sensitive

Explanation / Answer

Question3.cpp

#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;

char YesNo, choice, done;
int x, y, ans, numCorrect, numWrong;

void generateXY();
void displayCorrect() { cout << "             CORRECT "; }
void displayWrong() { cout << "             WRONG "; }
void continueTN();
void displayQuesAd();
void displayQuesSub();
void displayMenu();
void getChoice();
void isDone();
void displayNumAns();

int main()
{
   displayMenu();

   _asm
   {
   //do-while loop
   doLoop:
       call   getChoice;

   //inner while loop
   innerLoop:
       call   generateXY;
       cmp       choice, 'a';            //comopare choice == 'a'?
       Jne       Subtraction;            //if choice is not equal 'a', jump to Subtraction
       call   displayQuesAd;
  
       mov       eax, x;                 //eax = x
       add       eax, y;                 //eax = x + y
       Jmp       check;                  //jump to check

   Subtraction:
       call   displayQuesSub;
       mov       eax, x;                 //eax = x
       sub       eax, y;                 //eax = x - y

   check:
       cmp       eax, ans;               //compare eax == ans?
       Je       showCorrect;            // if eax = ans, jump to showCorrect

       call   displayWrong;
       inc       numWrong;               //numWrong++
       Jmp       continueLoop;           //jump to continueLoop

   showCorrect:
       call   displayCorrect;
       inc       numCorrect;             //numCorrect++
       Jmp       continueLoop;           //jump to continueLoop
  
   continueLoop:
       call   continueTN;
       cmp       YesNo, 'y';             //compare YesNo == 'y'?
       Je       innerLoop;              //jump to innerLoop if YesNo = 'y'
       cmp       YesNo, 'Y';             //compare YesNo == 'Y'?
       Je       innerLoop;              //jump to innerLoop if YesNo = 'Y'
      
       call   displayNumAns;

       mov       numCorrect, 0;          //numCorrect = 0
       mov       numWrong, 0;            //numWrong = 0

       call   isDone;
       cmp       done, 'n';              //compare done == 'n'?
       Je       doLoop;                 //if done = 'n', jump back to doLoop
       cmp       done, 'N';              //compare done == 'N'?
       Je       doLoop;                 //if done = 'N', jump back to doLoop
   }

   cout << "       Have a nice day ";

   cout << endl;
   system("pause");
   return 0;
}

void displayMenu()
{
   cout << "--------Practice Addition & Subtraction----------------- "
       << "a.   Practice Addition "
       << "b.   Practice Subtraction ";
}

void getChoice()
{
   cout << "       Enter your choice(a/b): ";
   cin >> choice;
}

void isDone()
{
   cout << "     Are you done(y/n)? ";
   cin >> done;
}

void generateXY()
{
   srand((unsigned int)time(NULL));
   x = rand() % 99 + 1;
   y = rand() % 99 + 1;
}

void continueTN()
{
   cout << "             Continue(y/n) ";
   cin >> YesNo;
}

void displayQuesAd()
{
   cout << "          " << x << " + " << y << " = ? ";
   cin >> ans;
}

void displayQuesSub()
{
   cout << "          " << x << " - " << y << " = ? ";
   cin >> ans;
}

void displayNumAns()
{
   cout << "       No. of CORRECT answer = " << numCorrect << endl;
   cout << "       No. of WRONG answer = " << numWrong << endl;
}


Question1.cpp

#include <iostream>
#include <string>

using namespace std;

string starsY, starsN;
char c;
int numOfYes, numOfNo, i, j;

void askForString();
void readChar();
void starYes();
void starNo();

int main()
{
   _asm
   {
       call   askForString;
       call   readChar;           //read first character
       mov       numOfYes, 0;       //numOfYes = 0
       mov       numOfNo, 0;           //numOfNo = 0
  
   //while loop
   whileloop:
       cmp       c, ' ';           //compare c == ' '?
       Je       yesLoop;           //jump to yesLoop if they are equal
       cmp       c, 'y';               //compare c == 'y'
       Je       incYes;               //jump to incYes if c == 'y'
       Jne       incNo;               //jump to incNo if c is not equal 'y'
       call   readChar;           //read the next character
       Jmp       whileloop;           //jump back to the whileloop when c is not ' '

   incYes:
       inc       numOfYes;           //numOfYes++
       call   readChar;           //read the next character
       Jmp       whileloop;           //jump back to the whileloop

   incNo:
       inc       numOfNo;           //numOfNo++
       call   readChar;           //read the next character
       Jmp       whileloop;           //jump back to the whileloop

       mov       i, 0;               //i = 0
       mov       j, 0;               //j = 0

   //for loop to print 'y' vote
   yesLoop:
       mov       eax, numOfYes;       //eax = numOfYes
       cmp       i, eax;               //compare i < numOfYes
       Jge       noLoop;               //jump to noLoop if i is not less than numOfYes
       inc       i;                   //i++
       call   starYes;           //increment the stars for each 'y'
       Jmp       yesLoop;           //jump back to yesLoop

   //for loop to print 'n' vote
   noLoop:
       mov       eax, numOfNo;       //eax = numOfNo
       cmp       j, eax;               //compare j < numOfNo
       Jge       done;               //jump to done if j is not less than numOfNo
       inc       j;                   //j++
       call   starNo;               //increment the stars for each 'n'
       Jmp       noLoop;               //jump back to noLoop
   done:
   }

   cout << "No. of YES votes = " << numOfYes << " = " << starsY << endl;
   cout << "No. of NO votes = " << numOfNo << " = " << starsN << endl;

   cout << endl;
   system("pause");
   return 0;
}

void askForString()
{
   cout << "Enter a string of votes: ";
}

void readChar()
{
   cin.get(c);
}

void starYes()
{
   starsY += "* ";
}

void starNo()
{
   starsN += "* ";
}


Question2.cpp

#include <iostream>
#include <string>

using namespace std;

char c;
string sentence;

void askForSentence();
void readChar();
void result();

int main()
{
   _asm
   {
       call   askForSentence;
       call   readChar;
  
   whileLoop:
       cmp       c, ' ';
       Je       done;
       cmp       c, 'a';
       Je       changeUpper;
       cmp       c, 'e';
       Je       changeUpper;
       cmp       c, 'i';
       Je       changeUpper;
       cmp       c, 'o';
       Je       changeUpper;
       cmp       c, 'u';
       Je       changeUpper;
       cmp       c, 'y';
       Je       changeUpper;

       call   result;
       call   readChar;
       Jmp       whileLoop;

   changeUpper:
       sub       c, 32;
       call   result;
       call   readChar;
       Jmp       whileLoop;
   done:
   }

   cout << " Output: " << sentence << endl;

   cout << endl;
   system("pause");
   return 0;
}

void askForSentence()
{
   cout << "Enter a sentence: ";
}

void readChar()
{
   cin.get(c);
}

void result()
{
   sentence += c;
}