浮点数冒泡排序

;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ;-=- Double BubbleSort By G-Spider @2010 ;-=- ml /c /coff sort.asm ;-=- link /subsystem:console sort.obj ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ .386 .model flat,stdcall include user32.inc include kernel32.inc include msvcrt.inc includelib user32.lib includelib kernel32.lib includelib msvcrt.lib .data fmt0 db '%lf',0 fmt1 db '%.4lf ',0 fmt2 db 0dh,0ah,0 inform db 'Please input 6 real nums:',0dh,0ah,0 outform db 'Sort nums: ',0dh,0ah,0 szPause db 'Pause',0 .data? ArrTEST qword 10 dup(?) .code ;**************************** DoubleBubbleSort proc lpDest:DWORD,count:DWORD ; 双精度浮点冒泡排序,从小到大 mov edx, count mov ecx, 1 LOOP1: cmp ecx,0 je EXIT mov esi, lpDest xor ecx, ecx dec edx xor ebx, ebx LOOP2: cmp ebx, edx jge LOOP1 inc ebx ;比较 fld QWORD PTR[esi] fcom QWORD PTR[esi+8] fnstsw ax test ah, 65 jne NEXT2 ;需要交换 fld QWORD PTR[esi+8] fstp QWORD PTR[esi] fstp QWORD PTR[esi+8] mov ecx, 1 add esi, 8 jmp LOOP2 NEXT2: ;无须交换,恢复堆栈 fstp st(0) add esi, 8 jmp LOOP2 EXIT: xor eax,eax ret DoubleBubbleSort ENDP ;**************************** _Input proc xor ecx,ecx mov edi,offset ArrTEST @@: cmp ecx,6 je EXIT push ecx lea eax,dword ptr[edi+ecx*8] push eax push offset fmt0 call crt_scanf add esp,8 pop ecx inc ecx jmp @B EXIT: xor eax,eax ret _Input endp ;**************************** _Output proc lpDest:DWORD xor ecx,ecx mov edi,lpDest @@: cmp ecx,6 je EXIT push ecx fld qword ptr[edi+ecx*8] sub esp,8 fstp qword ptr[esp] push offset fmt1 call crt_printf add esp,12 pop ecx inc ecx jmp @B EXIT: xor eax,eax ret _Output endp ;**************************** start: push offset inform call crt_printf add esp,4 ;数据输出 ;-------- invoke _Input ;-------- ;冒泡排序 ;-------- invoke DoubleBubbleSort,offset ArrTEST,6 ;-------- push offset outform call crt_printf add esp,4 ;数据输出 ;-------- invoke _Output,offset ArrTEST ;-------- push offset fmt2 call crt_printf add esp,4 invoke crt_system,offset szPause invoke ExitProcess,0 end start

你可能感兴趣的:(Win32/64汇编)