+ -
当前位置:首页 → 问答吧 → win32汇编_简单的双精度浮点数冒泡排序,无聊送分

win32汇编_简单的双精度浮点数冒泡排序,无聊送分

时间:2010-12-29

来源:互联网

双精度浮点(double型)冒泡排序,从小到大,无聊送分
--------------------------------------
Assembly code

;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
;-=- 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:
        test    ecx,ecx
        jz      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  count:DWORD
;//输入count个双精度浮点数到数组ArrTEST[]中
     xor   ecx,ecx 
     mov   edi,offset ArrTEST
@@:   
     cmp   ecx,count
     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,count:DWORD
     xor   ecx,ecx 
     mov   edi,lpDest
@@: 
     cmp   ecx,count
     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:

     invoke crt_printf,offset inform
     ;//数据输入
     invoke _Input,6
     ;--------    
     ;//冒泡排序
     invoke DoubleBubbleSort,offset ArrTEST,6
     ;--------
     invoke crt_printf,offset outform
     ;//数据输出
     invoke _Output,offset ArrTEST,6
     ;--------
     invoke crt_printf,offset fmt2
     
     invoke crt_system,offset szPause
     invoke ExitProcess,0

end start 

作者: G_Spider   发布时间: 2010-12-29

写的好!膜拜!

作者: znxllyuan   发布时间: 2010-12-29