2013-06-18 00:21:18 +04:00
|
|
|
; Sorting bunch of dwords, count = ecx, locating at address = edx,
|
|
|
|
; comparison function at ebx
|
|
|
|
; Destroy content of eax, ecx, esi, edi
|
2007-06-14 16:56:45 +04:00
|
|
|
sort:
|
|
|
|
jecxz .done
|
|
|
|
mov eax, ecx
|
2013-06-18 00:21:18 +04:00
|
|
|
|
|
|
|
@@:
|
2007-06-14 16:56:45 +04:00
|
|
|
push eax
|
|
|
|
call .restore
|
|
|
|
pop eax
|
|
|
|
dec eax
|
|
|
|
jnz @b
|
2013-06-18 00:21:18 +04:00
|
|
|
|
|
|
|
@@:
|
2007-06-14 16:56:45 +04:00
|
|
|
cmp ecx, 1
|
|
|
|
jz .done
|
|
|
|
mov esi, 1
|
|
|
|
mov edi, ecx
|
|
|
|
call .exchange
|
|
|
|
dec ecx
|
|
|
|
mov eax, 1
|
|
|
|
call .restore
|
|
|
|
jmp @b
|
2013-06-18 00:21:18 +04:00
|
|
|
|
|
|
|
.done:
|
2007-06-14 16:56:45 +04:00
|
|
|
ret
|
|
|
|
|
2013-06-18 00:21:18 +04:00
|
|
|
.exchange:
|
2007-06-14 16:56:45 +04:00
|
|
|
push eax ecx
|
|
|
|
mov eax, [edx+esi*4-4]
|
|
|
|
mov ecx, [edx+edi*4-4]
|
|
|
|
mov [edx+esi*4-4], ecx
|
|
|
|
mov [edx+edi*4-4], eax
|
|
|
|
pop ecx eax
|
|
|
|
ret
|
|
|
|
|
2013-06-18 00:21:18 +04:00
|
|
|
.restore:
|
2007-06-14 16:56:45 +04:00
|
|
|
lea esi, [eax+eax]
|
|
|
|
cmp esi, ecx
|
2013-06-18 00:21:18 +04:00
|
|
|
ja .donerr
|
2007-06-14 16:56:45 +04:00
|
|
|
push esi
|
|
|
|
mov esi, [edx+esi*4-4]
|
|
|
|
mov edi, [edx+eax*4-4]
|
|
|
|
call ebx
|
|
|
|
pop esi
|
|
|
|
ja .need_xchg
|
|
|
|
cmp esi, ecx
|
2013-06-18 00:21:18 +04:00
|
|
|
jae .donerr
|
2007-06-14 16:56:45 +04:00
|
|
|
push esi
|
|
|
|
mov esi, [edx+esi*4]
|
|
|
|
mov edi, [edx+eax*4-4]
|
|
|
|
call ebx
|
|
|
|
pop esi
|
2013-06-18 00:21:18 +04:00
|
|
|
jbe .donerr
|
|
|
|
|
|
|
|
.need_xchg:
|
2007-06-14 16:56:45 +04:00
|
|
|
cmp esi, ecx
|
|
|
|
jz .do_xchg
|
|
|
|
push esi
|
|
|
|
mov edi, [edx+esi*4-4]
|
|
|
|
mov esi, [edx+esi*4]
|
|
|
|
call ebx
|
|
|
|
pop esi
|
|
|
|
sbb esi, -1
|
2013-06-18 00:21:18 +04:00
|
|
|
|
|
|
|
.do_xchg:
|
2007-06-14 16:56:45 +04:00
|
|
|
mov edi, eax
|
|
|
|
call .exchange
|
|
|
|
mov eax, esi
|
|
|
|
jmp .restore
|
2013-06-18 00:21:18 +04:00
|
|
|
|
|
|
|
.donerr:
|
2007-06-14 16:56:45 +04:00
|
|
|
ret
|
2013-06-18 00:21:18 +04:00
|
|
|
|
|
|
|
; vim: ft=fasm tabstop=4
|
|
|
|
|