1分钟左右随机生成2000万行随机字符串

#include<windows.h>
#pragma comment(linker,"/entry:Test")
#include <stdlib.h>

char * str="012345aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ567890";
char * szPath = "z:\\Test.txt";
char * szFormat = "总共用时:%d\r\n";


__declspec(naked) void Test()
{

__asm
{
push ebp
mov ebp,esp
sub esp,0x10

;将进程级别提高到最高
push REALTIME_PRIORITY_CLASS
push 0xFFFFFFFF
call dword ptr[SetPriorityClass]

;将线程优先级提到最高
push THREAD_PRIORITY_TIME_CRITICAL
call dword ptr[GetCurrentThread]
push eax
call dword ptr [SetThreadPriority]

;设置随机种子
call dword ptr[GetTickCount]
mov [ebp-0xC],eax
push eax
call dword ptr[srand]


;创建文件
push NULL
push FILE_ATTRIBUTE_NORMAL
push OPEN_ALWAYS
push NULL
push FILE_SHARE_WRITE|FILE_SHARE_READ
push GENERIC_WRITE|GENERIC_READ
push dword ptr[szPath]
call dword ptr[CreateFileA]

;保存HANDLE
mov [ebp-4],eax

;内存文件映射 懒了 不做返回值判断了..
push NULL
push 0x15752A00 ;18 * 20000000 = 360000000 = 0x15752A00
push NULL
push PAGE_READWRITE
push NULL
push [ebp-4]
call dword ptr[CreateFileMappingA]
;保存HANDLE
mov [ebp-8],eax


push 0x15752A00
push 0
push 0
push FILE_MAP_WRITE
push [ebp-8]
call dword ptr[MapViewOfFile]
;保存内存地址
mov [ebp-0x10],eax
mov esi,eax


mov ebx,0x1312D00
mov edi,dword ptr[str]
B:
dec ebx
cmp ebx,0
je EXIT

mov edx,0
A:
call dword ptr[rand]
;rand 返回最大值为0x7FFF 二进制为:111 111111 111111
and eax,0x7FFF
push eax

;截取后0-6位
and eax,0x3F
mov eax,[edi+eax]
mov byte ptr [esi], al
inc esi

;截取6-12位
mov eax,[esp]
shr eax,6
and eax,0x3F
mov eax,[edi+eax]
mov byte ptr [esi], al
inc esi

;截取3-9位
mov eax,[esp]
shr eax,3
and eax,0x3F
mov eax,[edi+eax]
mov byte ptr [esi], al
inc esi

;截取9-15位
mov eax,[esp]
shr eax,9
and eax,0x3F
mov eax,[edi+eax]
mov byte ptr [esi], al
inc esi
add esp,4

inc edx
cmp edx,4
jne A

;换行
mov byte ptr [esi], 0xD
inc esi
mov byte ptr [esi],0xA
inc esi

jmp B
EXIT:

call dword ptr [GetTickCount]
sub eax,[ebp-0xC]
push eax
push dword ptr [szFormat]
call dword ptr [printf]

push [ebp-0x10]
push 0x15752A00
call dword ptr [FlushViewOfFile]

mov esp,ebp
pop ebp
ret
}
}

VC6 新建CONSOLE程序
选择hello world模板
粘贴以上代码
工程->设置
照图设置

 



最后编译的时候,记得选择Release方式

 



你可能感兴趣的:(字符串)