Guys..My task is to convert for loop c++ to asm....and the speed shoud be fast....i managed to convert to asm the loop part but when i run and enter 2000 it shows 33 second is it possible to be lower the 5 second....
#include <iostream>
#include <ctime>
using namespace std;
void main ()
{
time_t start, end;
unsigned short a, b, c, y, count=0;
float diff;
cout << "Enter y : ";
cin >> y;
cout << "Calculation start..." << endl;
start = clock();
//this is loop part which need to change to increase the speed
_asm{
mov dx,y // Set value of y to dx
mov ax,0 // AX as a, start from 0
set1: mov bx,0 // BX as b, start from 0 / reset to 0
set2: mov cx,0 // CX as c, start from 0 / reset to 0
again: push ax // Store AX value to Stack
add ax,ax // This 3 line to calculate the
add ax,bx // value of 2a + b - c
sub ax,cx //
again2: cmp ax,dx // Compare the value (2a + b - c) with y (DX)
jne skip // IF not equal then jump to skip
inc count // Else IF equal then count++;
skip: cmp cx,dx // Comparing c (CX) with y (DX)
jge up // IF c >= y, jump to up
inc cx // Else c++;
pop ax // Restore the 'a' (AX) value form stack
// (because AX value changed when calculate the value 2a+b-c)
jmp again // Jump to again to recount and recheck
up: cmp bx,dx // Comparing b (BX) with y (DX)
jge up2 // IF b >= y, jump to up2
inc bx // Else b++;
pop ax // Restore 'a' value.
jmp set2 // Jump to set2 which will reset c value to 0
up2: pop ax // Restore 'a' value
cmp ax,dx // Compare a (AX) with y (DX)
jge stop // IF a >= y, jump to stop
inc ax // Else a++;
jmp set1 // Jump to set1 which will reset b value to 0
stop:
}
//Do not change the code below
end = clock();
diff = (float)(end - start)/CLOCKS_PER_SEC;
cout << "Calculation complete." << endl;
cout << "Time used is " << diff << " second" << endl;
cout << "There are " << count << " combination to produce " << y << endl;
system ("pause");
}