Question: Write the MARIE assembly language program that corresponds to the attached C++ program as follows: The ordered data for the binary search is defined between

Write the MARIE assembly language program that corresponds to the attached C++ program as follows:

The ordered data for the binary search is defined between Data_B and Data_E o

The actual address of Data_B is stored at BAddr as 0003 o

The actual address of Data_E is stored at EAddr as 001A (hex) o

Modify the given template from the line with start, Do NOT modify the lines above start,

The program behavior:

The user enters a number (hexadecimal).

Using the binary search algorithm, the program locates the number at addresses between Data_B and Data_E

If the number is found, display (output) the address of the number (NOT actual number).

If the number is not found, display FFFF (hexadecimal)

#include 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 = 23; // high index for binary search int mid; // mid index for binary search int ONE = 1;

cout << "Enter an integer (in decimal): "; // Not required in assembly program

cin >> 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. // In term project, print the address of it // This C++ program simply prints the index of the data found. cout << mid << endl; }

}

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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!