Trying to get this assignment completed Thanks in advance

I need to build a C++ function that forces the processor to multiply using the shift‐add. The multiplication code must be done in assembly, but I can
use the extended assembly for passing the C++ variables to the assembly code.

Please Help

Here is a framework that I'm trying to tweak:
#include <iostream>
#include <ctime>

using namespace std;

int multiplyAdds(int x, int y){
int result = 0;
asm("mov %1, %%edx;"
"mov %2, %%ecx;"
"mov $0, %%eax;"
"acc: add %%edx, %%eax;"
" loop acc;"
: "=a" (result)
:"r" (x), "r" (y));
}

inline int mMultiplyAdds(int x, int y){
int result = 0;
asm("mov %1, %%edx;"
"mov %2, %%ecx;"
"mov $0, %%eax;"
"acc2: add %%edx, %%eax;"
" loop acc2;"
: "=a" (result)
:"r" (x), "r" (y));
}

int multiplySAdd(int x, int y){
int result = 0;
//add your shift-add assembly code here
asm(""
: "=a" (result)
: "a" (x), "d" (y));
return result;
}

inline int mMultiplySAdd(int x, int y){
int result = 0;
//add your shift-add assembly code here
asm(""
: "=a" (result)
: "a" (x), "d" (y));
return result;
}

int main(){
int n = 100;
int seed = 100;
int original[n][n];
int mfactor[n][n];
int result[n][n];
int test[n][n];
int test2[n][n];
int test3[n][n];
cout << mMultiplyAdds(4, 5) << endl;
srand(seed);
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
original[i][j] = rand()%10;
mfactor[i][j] = rand()%10;
}
}
cout << "Start Original Test ..." << endl;
time_t start1 = time(NULL);
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
test[i][j] = original[i][j]*mfactor[i][j];
}
}
time_t end1 = time(NULL);
cout << "Original Process Took " << (end1 - start1) << endl;

time_t start2 = time(NULL);
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
test2[i][j] = multiplyAdds(original[i][j], mfactor[i][j]);
}
}
time_t end2 = time(NULL);
cout << "First Test Took " << (end2 - start2) << endl;

time_t start3 = time(NULL);
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
test3[i][j] = mMultiplyAdds(original[i][j], mfactor[i][j]);
}
}
time_t end3 = time(NULL);
cout << "Second Test Took " << (end3 - start3) << endl;

cout << "Enter any character to continue: ";
char c;
cin >> c;
system ("PAUSE");
return 0;
}
Topic archived. No new replies allowed.