⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 内嵌汇编写的起泡排序
💻 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 + -