Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -=-=-=-=-ASM EXTERN SORT-=-=-=-=-
- #include <conio.h>
- #include <stdio.h>
- #include <iostream>
- #include <time.h>
- #include <Windows.h>
- int main()
- {
- int again = 4;
- start:
- int N = 30000;
- srand((time(NULL)) );
- int *a = new int[N];
- for(int i = 0; i < N; i++)
- a[i] = rand()%100 + 1;
- int *aa = new int[N];
- for (int i = 0; i < N; i++)
- aa[i] = a[i];
- double time = GetTickCount();
- for (int i = 0; i < N-1; i++)
- for (int j = 1; j < N; j++)
- if (aa[j-1] > aa[j])
- {
- int tmp = aa[j-1];
- aa[j-1] = aa[j];
- aa[j] = tmp;
- }
- printf("C++: %f\n", GetTickCount() - time);
- time = GetTickCount();
- __asm
- {
- xor ecx, ecx // ecx - i
- xor edx, edx // edx - j
- mov esi, a; // esi - a[0];
- mov ecx, [N] // i = n;
- dec ecx; // i = n-1
- c1: // for i
- mov edx, [N]; // j = n;
- dec ecx; // i--
- test ecx, ecx // if i == 0 goto endAsm
- jz endAsm;
- c2: // for j
- dec edx // j--
- cmp edx, 1; // if j-1 == 0 goto c1;
- jz c1;
- mov eax, [esi + edx * 4] // eax = a[j]
- mov ebx, [esi + edx * 4 - 4]
- cmp eax, ebx// cmp a[j] - a[j-1]
- jns c2; // if a[j-1] > a[j]
- c3: // if
- mov dword ptr [esi + edx * 4], ebx; //a[j] = a[j-1]
- mov dword ptr [esi + edx * 4 - 4], eax; // a[j-1] = a[j]
- jmp c2
- endAsm:
- }
- printf("ASM: %f\n", GetTickCount() - time);
- delete []a;
- delete []aa;
- printf("\n");
- again--;
- if (again != 0) goto start;
- printf("\n-=-=end=-=-");
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment