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