; ; ;冒泡排序算法 ; author: wangguolaing ; date: revised 4/14 .386 .MODEL FLAT INCLUDE io.h includelib Kernel32.lib ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD cr EQU 0dh Lf EQU 0ah .STACK 4096 .DATA Array DWORD 23,12,5,78,27,33,4,32 address DWORD ? count DWORD ? count2 DWORD ? number BYTE 11 DUP (?) .CODE _start: lea ebx,Array ;取数组的首地址 mov edx,ebx mov address,ebx add address,32 L1: mov eax,[ebx] L2: mov ecx,[edx] cmp eax,ecx jbe L3 ;小于或等于转移 xchg eax,ecx ;大于则交换 mov [ebx],eax ;将交换后的数存入存储器 mov [edx],ecx ;这两步很重要 L3: add edx,4 ; cmp edx,address ;判断内层循环是否结束 jb L2 ;没结束,继续循环 ;内层循环结束了 add ebx,4 ;外层加一,相当于i++ cmp ebx,address ja endwhile ;完成结束 mov edx,ebx ;相当于j=i jmp L1 ;通过寄存器实现两个存储器数据间的交换 endwhile : lea ebx,Array mov ecx,8 mov count,0 whileup : ; mov eax,count ;cmp eax,8 ;jge quit mov eax,[ebx] dtoa number,eax output number ;inc count add ebx,4 loop whileup quit: INVOKE ExitProcess, 0 ; exit with return code 0 PUBLIC _start ; make entry point public END ; end of source code