Question

please write this in "MARIE assembly language" #include <iostream> using namespace std; int DivideByTwo(int, int); //...

please write this in "MARIE assembly language"

#include <iostream>
using namespace std;

int DivideByTwo(int, int);

// Data section
int Data[] = {
0x0102, 0x0105, 0x0106, 0x0108, 0x011A, 0x0120,
0x0225, 0x0230, 0x0231, 0x0238, 0x0339, 0x0350,
0x0459, 0x055F, 0x066A, 0x0790, 0x08AB, 0x09AF,
0x0AB9, 0x0BBD, 0x0CC1, 0x0DCA, 0x0EFE, 0x0FFE
};

int main() {
int* BAddr = &Data[0];
int* EAddr = &Data[23];
int Count = 24; // the number of Data
int Ffff = 0xffff; // value for "not found"
int num; // input
int low = 0; // low index for binary search
int high = Count - 1; // high index for binary search
int mid; // mid index for binary search
int ONE = 1;

// the following cout is not required in the term project
cout << "Enter an integer (in hexadecimal): ";

cin >> hex >> num;

// Binary Search Algorithm
while (true) {

// Define DivideByTwo subprogram that computes
// mid = (low + high) / 2
mid = DivideByTwo(low, high);

if (num == Data[mid]) {
break; // found!
} else if (num < Data[mid]) {
high = mid - ONE;
} else {
low = mid + ONE;
}

if (low > high) {
mid = Ffff;
break;
}
}

if (mid == Ffff) {
// not found
cout << hex << Ffff << endl;
} else {
// found.
   // Print only the address of the data in the term project
cout << "Addr: " << &Data[mid] << " at Index: " << mid << endl;
}

}

int DivideByTwo(int a, int b) {
return (a + b) / 2;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Variants on a Simple Program Statement

Begin with a program statement in some high–level language.

Z = X + Y

In the MARIE assembly language, this would be written as follows.

Load        X
Add         Y
Store        Z

The hexadecimal representation of the MARIE machine language might be as follows.

30BC
202D

#include <iostream>
using namespace std;

int DivideByTwo(int, int);

// Data section
int Data[] = {
0x0102, 0x0105, 0x0106, 0x0108, 0x011A, 0x0120,
0x0225, 0x0230, 0x0231, 0x0238, 0x0339, 0x0350,
0x0459, 0x055F, 0x066A, 0x0790, 0x08AB, 0x09AF,
0x0AB9, 0x0BBD, 0x0CC1, 0x0DCA, 0x0EFE, 0x0FFE
};

int main() {
int* BAddr = &Data[0];
int* EAddr = &Data[23];
int Count = 24; // the number of Data
int Ffff = 0xffff; // value for "not found"
int num; // input
int low = 0; // low index for binary search
int high = Count - 1; // high index for binary search
int mid; // mid index for binary search
int ONE = 1;

// the following cout is not required in the term project
cout << "Enter an integer (in hexadecimal): ";

cin >> hex >> num;

// Binary Search Algorithm
while (true) {

// Define DivideByTwo subprogram that computes
// mid = (low + high) / 2
mid = DivideByTwo(low, high);

if (num == Data[mid]) {
break; // found!
} else if (num < Data[mid]) {
high = mid - ONE;
} else {
low = mid + ONE;
}

if (low > high) {
mid = Ffff;
break;
}
}

if (mid == Ffff) {
// not found
cout << hex << Ffff << endl;
} else {
// found.
   // Print only the address of the data in the term project
cout << "Addr: " << &Data[mid] << " at Index: " << mid << endl;
}

}

int DivideByTwo(int a, int b) {
return (a + b) / 2;
}

output:

Enter an integer (in hexadecimal): ffff

Add a comment
Know the answer?
Add Answer to:
please write this in "MARIE assembly language" #include <iostream> using namespace std; int DivideByTwo(int, int); //...
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
  • Convert the below code into if else selection: #include <iostream> using namespace std; int main() {...

    Convert the below code into if else selection: #include <iostream> using namespace std; int main() { int num; sin. >> num; switch (num) { case 1: cout << "Casel: Value is: << num << endl; break; case 2: break; case 3: cout << "Case3: Value is: " << num << endl; break; default: cout << "Default: Value is: << num << endl; break; } return; }

  • #include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void...

    #include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void displayArrayContent(int[]); void displayLargestValue(int[]); void displaySmallestValue(int[]); int main(){    int number;    int numbers[SIZE] = {9,1,90,98,53,22,76,29,37,65}; cout <<"Enter a number: "; cin >> number; cout << endl;    displayGreaterThan(numbers,number); cout << endl; displaySmallerThan(numbers,number); cout << endl; displayArrayContent(numbers); cout << endl; displayLargestValue(numbers); cout << endl; displaySmallestValue(numbers); cout << endl;    return 0;       } void displayGreaterThan(int value[],int num){ cout << " All larger value(s)than" <<...

  • #include <iostream> using namespace std; bool binarySearch(int arr[], int start, int end, int target){ //your code...

    #include <iostream> using namespace std; bool binarySearch(int arr[], int start, int end, int target){ //your code here } void fill(int arr[], int count){ for(int i = 0; i < count; i++){ cout << "Enter number: "; cin >> arr[i]; } } void display(int arr[], int count){ for(int i = 0; i < count; i++){ cout << arr[i] << endl; } } int main() { cout << "How many items: "; int count; cin >> count; int * arr = new...

  • Find and fix errors #include <iostream> #include <cstdlib> #include <ctime> using namespace std; const int MIN...

    Find and fix errors #include <iostream> #include <cstdlib> #include <ctime> using namespace std; const int MIN = 1; const int MAX = 10; int getRandom(int low, int high); int main() {    int random_num = 0; int player_num; int tries; int seed = static_cast<int>(time(0)); bool guessed = false;    srand(seed); // call the getRandom function below       tries = 4; while ( tries > 0 && !guessed ) { cout << "Enter a number within the range 1 to...

  • #include <iostream> #include <vector> #include <fstream> #include <time.h> #include <chrono> #include <sstream> #include <algorithm> class Clock...

    #include <iostream> #include <vector> #include <fstream> #include <time.h> #include <chrono> #include <sstream> #include <algorithm> class Clock { private: std::chrono::high_resolution_clock::time_point start; public: void Reset() { start = std::chrono::high_resolution_clock::now(); } double CurrentTime() { auto end = std::chrono::high_resolution_clock::now(); double elapsed_us = std::chrono::duration std::micro>(end - start).count(); return elapsed_us; } }; class books{ private: std::string type; int ISBN; public: void setIsbn(int x) { ISBN = x; } void setType(std::string y) { type = y; } int putIsbn() { return ISBN; } std::string putType() { return...

  • #include<iostream> using namespace std; int main() { float num,avg,sum=0.0; int count=0; bool moreNumbers=true; cout<<"Enter grades:"<<endl; while(moreNumbers)...

    #include<iostream> using namespace std; int main() { float num,avg,sum=0.0; int count=0; bool moreNumbers=true; cout<<"Enter grades:"<<endl; while(moreNumbers) { cin>>num; if(num < 0) { moreNumbers=false; } else { count = count+1; sum=sum+num; } } avg=sum/count; cout<<"Average grade:"<<avg<<endl; cout<<"How many grades were entered:"<<count<<endl; return 0; } Question: We need to add another loop to check input. Just like the input loop we already have, this one should use a boolean variable as a control. So, the logic could be something like this: Loop...

  • #include #include #include #include #include #include // NOLINT (build/c++11) #include class Clock { private: std::chrono::high_resolution_clock::time_point start;...

    #include #include #include #include #include #include // NOLINT (build/c++11) #include class Clock { private: std::chrono::high_resolution_clock::time_point start; public: void Reset() { start = std::chrono::high_resolution_clock::now(); } double CurrentTime() { auto end = std::chrono::high_resolution_clock::now(); double elapsed_us = std::chrono::duration std::micro>(end - start).count(); return elapsed_us; } }; class books{ private: std::string type; int ISBN; public: void setIsbn(int x) { ISBN = x; } void setType(std::string y) { type = y; } int putIsbn() { return ISBN; } std::string putType() { return type; } }; std::ostream...

  • #include <iostream> #include <string> using namespace std; int main() { int number; int sum = 0;...

    #include <iostream> #include <string> using namespace std; int main() { int number; int sum = 0; while(true) { cout << "Please enter a number between 1 and 11: "; cin >> number; if (number >= 1 && number <= 11) { cout << number << endl; sum = sum + number; //only add the sum when number is in range: 1-11, so add wthin this if case } else { cout << number << endl; cout << "Out of range;...

  • #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str);...

    #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() {    char string[100];    char inputChoice, choice[2];    int vowelTotal, consonantTotal;    //Input a string    cout << "Enter a string: " << endl;    cin.getline(string, 100);       do    {        //Displays the Menu        cout << "   (A) Count the number of vowels in the string"<<endl;        cout << "   (B) Count...

  • #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str);...

    #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() {    char string[100];    char inputChoice, choice[2];    int vowelTotal, consonantTotal;    //Input a string    cout << "Enter a string: " << endl;    cin.getline(string, 100);       do    {        //Displays the Menu        cout << "   (A) Count the number of vowels in the string"<<endl;        cout << "   (B) Count...

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