作者在 2008-10-12 07:52:03 发布以下内容
;调用冒泡排序函数的例子程序
;作者:ONEPROBLEM
;========================
.386
.model flat,stdcall
option casemap:none
;作者:ONEPROBLEM
;========================
.386
.model flat,stdcall
option casemap:none
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
.data
Array dd 20,30,50,80,100,105
Buffer dd 256 dup (?)
szCaption db '提示',0
szText db '结果是:%d,%d,%d,%d,%d,%d',0
Array dd 20,30,50,80,100,105
Buffer dd 256 dup (?)
szCaption db '提示',0
szText db '结果是:%d,%d,%d,%d,%d,%d',0
.code
_BubblingSort proc _lpData,_dwCount,_dwOption
local @dwCount
pushad
mov edi,1
.while edi < _dwCount
mov esi,_lpData
mov eax,_dwCount
mov @dwCount,eax
sub @dwCount,edi
mov ebx,1
.while ebx <= @dwCount
mov eax,[esi]
.if eax<[esi+4] && _dwOption==0
jmp next
.elseif eax>[esi+4] && _dwOption==0
jmp continue
.elseif eax<[esi+4] && _dwOption!=0
jmp continue
.elseif eax>[esi+4] && _dwOption!=0
jmp next
.endif
continue:
mov eax,[esi]
mov edx,[esi+4]
mov [esi],edx
mov [esi+4],eax
next:
add esi,4
inc ebx
.endw
inc edi
.endw
popad
ret
_BubblingSort endp
start:
lea edx,Array
invoke _BubblingSort,edx,6,-1 ;这第三个参数是非0,由大到小排序
lea edx,Array
mov eax,[edx]
mov ecx,[edx+4]
mov ebx,[edx+8]
mov esi,[edx+12]
mov edi,[edx+16]
mov ebp,[edx+20]
invoke wsprintf,addr Buffer,addr szText,eax,ecx,ebx,esi,edi,ebp
invoke MessageBox,NULL,addr Buffer,addr szCaption,MB_OK
invoke ExitProcess,NULL
end start
;==============================================
_BubblingSort proc _lpData,_dwCount,_dwOption
local @dwCount
pushad
mov edi,1
.while edi < _dwCount
mov esi,_lpData
mov eax,_dwCount
mov @dwCount,eax
sub @dwCount,edi
mov ebx,1
.while ebx <= @dwCount
mov eax,[esi]
.if eax<[esi+4] && _dwOption==0
jmp next
.elseif eax>[esi+4] && _dwOption==0
jmp continue
.elseif eax<[esi+4] && _dwOption!=0
jmp continue
.elseif eax>[esi+4] && _dwOption!=0
jmp next
.endif
continue:
mov eax,[esi]
mov edx,[esi+4]
mov [esi],edx
mov [esi+4],eax
next:
add esi,4
inc ebx
.endw
inc edi
.endw
popad
ret
_BubblingSort endp
start:
lea edx,Array
invoke _BubblingSort,edx,6,-1 ;这第三个参数是非0,由大到小排序
lea edx,Array
mov eax,[edx]
mov ecx,[edx+4]
mov ebx,[edx+8]
mov esi,[edx+12]
mov edi,[edx+16]
mov ebp,[edx+20]
invoke wsprintf,addr Buffer,addr szText,eax,ecx,ebx,esi,edi,ebp
invoke MessageBox,NULL,addr Buffer,addr szCaption,MB_OK
invoke ExitProcess,NULL
end start
;==============================================