can anyone help me please? I have to sum n elements in C++ and ASM, everything is working for C++ but not for ASM, does anybody know how to fix the problem? It calculates the sum for C++ and shows me the time and sum, but in ASM shows 0. But, sometimes it shows 0 for C++, does anybody know whats the problem? I use TurboC++, here it is my code:
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <dos.h>
#include <time.h>
void main()
{
clrscr();
int n = 30000;
double s=0;
int a[30000];
cout << "Array has " << n << " elements 3 times summed";
for (int i=0; i<n; i++)
{
a[i]=rand() % 10 + 1;
}
clock_t begin = clock();
for(i=0; i<n; i++)
{
s+=a[i];
}
for(i=0; i<n; i++)
{
s+=a[i];
}
for(i=0; i<n; i++)
{
s+=a[i];
}
clock_t end = clock();
cout << "\nExecution time for the sum in C++ is: " << ((double)(end-begin)/CLOCKS_PER_SEC);
int tmp;
clock_t start = clock();
for (int j=0;j<3;j++){
for (i=0;i<n;i++)
asm {
mov ax,13
add ax,2
}
}
clock_t stop = clock();
cout << "\nExecution time for the sum in ASM is: " << ((double)(stop-start)/CLOCKS_PER_SEC);
cout<<"\nSum: "<< s;
getch();
}