📄 shellsort.asm
字号:
; Date: 13.03.2004
; last modification: 11.04.2004
.code
IFNDEF PURE_ALGORITHM
ShellSort PROTO :DWORD, :DWORD
ShellSort PROC Arr:DWORD, count:DWORD
LOCAL @Element :DWORD
mov edi, Arr
mov ecx, count
mov eax, 1
@@:
shl eax, 2
inc eax
cmp eax, ecx
jb @B
@Loop1:
cmp eax, 1
je @Return
;-------------------------------------------------------------------------------
DelayAfterPass
;-------------------------------------------------------------------------------
shr eax, 2
mov ebx, eax
dec ebx
@Loop2:
inc ebx
cmp ebx, count
jnb @Loop1
mov ecx, DWORD PTR [edi + ebx*4]
;-------------------------------------------------------------------------------
push eax
lea eax, [edi + ebx*4]
mov @Element, eax
pop eax
;-------------------------------------------------------------------------------
push ebx
@Loop3:
mov esi, ebx
sub ebx, eax
mov edx, DWORD PTR [edi + ebx*4]
;-------------------------------------------------------------------------------
IncCMPCounter
push eax
push ebx
lea eax, [edi + ebx*4]
mov ebx, @Element
DelayAfterComparison eax, ebx
pop ebx
pop eax
;-------------------------------------------------------------------------------
cmp edx, ecx
jna @Loop3a
mov DWORD PTR [edi + esi*4], edx
;-------------------------------------------------------------------------------
IncMOVCounter
push eax
lea eax, [edi + esi*4]
RefreshElement eax
pop eax
DelayAfterExchange
;-------------------------------------------------------------------------------
cmp ebx, eax
jnb @Loop3
jmp @Loop3b
@Loop3a:
add ebx, eax
@Loop3b:
mov DWORD PTR [edi + ebx*4], ecx
;-------------------------------------------------------------------------------
IncMOVCounter
push eax
lea eax, [edi + ebx*4]
RefreshElement eax
pop eax
DelayAfterExchange
;-------------------------------------------------------------------------------
pop ebx
jmp @Loop2
@Return:
ret
ShellSort ENDP
ELSE
ShellSort_PURE PROTO :DWORD, :DWORD
ShellSort_PURE PROC Arr:DWORD, count:DWORD
mov edi, Arr
mov ecx, count
mov eax, 1
@@:
shl eax, 2
inc eax
cmp eax, ecx
jb @B
@Loop1:
cmp eax, 1
je @Return
shr eax, 2
mov ebx, eax
dec ebx
@Loop2:
inc ebx
cmp ebx, count
jnb @Loop1
mov ecx, DWORD PTR [edi + ebx*4]
push ebx
@Loop3:
mov esi, ebx
sub ebx, eax
mov edx, DWORD PTR [edi + ebx*4]
;-------------------------------------------------------------------------------
IncCMPCounter
;-------------------------------------------------------------------------------
cmp edx, ecx
jna @Loop3a
mov DWORD PTR [edi + esi*4], edx
;-------------------------------------------------------------------------------
IncMOVCounter
;-------------------------------------------------------------------------------
cmp ebx, eax
jnb @Loop3
jmp @Loop3b
@Loop3a:
add ebx, eax
@Loop3b:
mov DWORD PTR [edi + ebx*4], ecx
;-------------------------------------------------------------------------------
IncMOVCounter
;-------------------------------------------------------------------------------
pop ebx
jmp @Loop2
@Return:
ret
ShellSort_PURE ENDP
ENDIF
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -