Question
Write one, and only one, assembly language procedure which takes parameters for an element to search for in an array, the array itself, and the
Write one, and only one, assembly language procedure which takes parameters for an element to search for in an array, the array itself, and the number of elements of an array as arguments. The assembly language procedure returns a value of 0 if the element to search for is not in the array, or the assembly language procedure returns a value of 1 if the element to search for is in the array.
NOTE: For the assembly language source code you should use Microsoft Macro Assembler constant variable syntax for the values of true and false. Specifically place into your assembly code these values for true and false:
.data
TRUE = 1
FALSE = 0
Use the TRUE or FALSE constants in the procedure when returning if the element to search for is found or if the element to search for is not found. You should return TRUE or FALSE as an 8-nit value when using them in a function. The 8-bit value should be stored in the lower 8-bit part of the eax register, and the values of eax register that are not in its lower 8-bit part should contain values of 0.
Source code for the C++ main program is included and is to be used for taking input from the user and displaying whether the array element was found or not found. The C++ main program included and does not need to be modified.
#include
using namespace std;
extern "C" bool FindArray( long searchVal, long array[], unsigned count );
int main() { // Fill an array with pseudorandom integers. Loop 10 billion times. const unsigned ARRAY_SIZE = 100000; const unsigned LOOP_SIZE = 100000;
long array[ARRAY_SIZE]; for(unsigned i = 0; i < ARRAY_SIZE; i++) array[i] = rand();
long searchVal; time_t startTime, endTime; cout << "Enter value to find: "; cin >> searchVal; cout << "Please wait. This will take between 10 and 20 seconds... ";
// Call the assembly language function:
time( &startTime ); bool found = false;
for( int n = 0; n < LOOP_SIZE; n++) found = FindArray( searchVal, array, ARRAY_SIZE );
time( &endTime ); cout << "Elapsed CPP time: " << long(endTime - startTime) << " seconds." << endl;
if( found ) cout << "The number was found "; else cout << "Not found ";
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started