用会变写个冒泡,做个记录,主要是学习循环的使用
.386 .model flat,stdcall option casemap:none include windows.inc include user32.inc includelib user32.lib include kernel32.inc includelib kernel32.lib .data bytes db 'hello,asm',0 lenth dw ? .code swap proc near push ebp; mov ebp ,esp sub esp ,100 push ebx push esi lea edi,[esp]; mov eax,0cccccccch; mov ecx,25; rep stos dword ptr es:[edi]; mov eax,[ebp+8] mov [ebp-4],eax; mov eax,[ebp+12]; mov [ebp-8],eax; mov eax,[ebp-4];//temp=a mov al,[eax]; mov [ebp-12],al; mov eax,[ebp-8];//a=b; mov al,[eax]; mov ebx,[ebp-4]; mov [ebx],al; mov al,[ebp-12];//b=tmp mov ebx,[ebp-8]; mov [ebx],al; pop esi; pop ebx; add esp ,100; pop ebp; ret 8 swap endp bubleSort proc near push ebp mov ebp,esp sub esp ,100 push ebx; push esi; lea edi,[ebp-100]; mov eax,0cccccccch mov ecx,25 rep stos dword ptr es:[edi]; mov eax,[ebp+8] mov [ebp-4],eax; mov eax,[ebp+12] mov [ebp-8],eax; mov eax,0 ; mov [ebp-12],eax; jmp LoopOneJudge; LoopOneBody: mov eax,0; mov [ebp-16],eax; jmp LoopTwoJudge; LoopTwoBody: mov eax,[ebp-4]; add eax,[ebp-16]; mov bl,[eax]; mov bh,[eax+1]; cmp bl,bh; jl SwapEnd; push eax; add eax,1; push eax; call swap; SwapEnd: mov eax,[ebp-16]; inc eax; mov [ebp-16],eax; LoopTwoJudge: mov eax,[ebp-16]; mov ebx,[ebp-8]; sub ebx,[ebp-12]; sub ebx,1; cmp eax,ebx; jl LoopTwoBody; mov eax,[ebp-12]; inc eax; mov [ebp-12],eax; LoopOneJudge: mov eax,[ebp-12] mov ebx,[ebp-8]; sub ebx,1 cmp eax,ebx; jl LoopOneBody; pop esi; pop ebx; add esp,100; pop ebp; ret 8; bubleSort endp start: mov eax,9; push eax; mov eax,offset bytes; push eax; call bubleSort; invoke MessageBox,0,offset bytes,0,MB_OK ret end start
原文地址:http://blog.csdn.net/ultimater/article/details/46593891