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
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
ADVERTISEMENT