📄 main.cpp
字号:
//**************************
//Inline assembly using
//bubble-up algorithm
//**************************
#include <iostream>
#include <windows.h>
#include <time.h>
using namespace std;
#define array_size 30000
void main()
{
//Generate array;
int a[array_size];
srand (GetTickCount());
for (int i=0; i<array_size; i++)
{
a[i] = rand()%50000;
}
int *p;
p=&a[0];
p--;
DWORD timelapse, timestart;
timestart = GetTickCount();
__asm
{
mov esi,p;
mov ecx,array_size;
_outloop:
mov edx,ecx;
_inloop:
mov eax, [ esi+ecx*4 ];
mov ebx, [ esi+edx*4 ];
cmp eax, ebx;
jnb _noxchg;
mov [ esi+ecx*4 ], ebx;
mov [ esi+edx*4 ], eax;
_noxchg:
dec edx;
jnz _inloop;
loop _outloop;
}
timelapse = GetTickCount() - timestart;
for (i=0; i<array_size; i++)
{
cout<<a[i]<<" ";
}
cout<<endl<<"Time elapsed "<<timelapse<<endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -