1,8 → 1,10 |
; ®àâ¨à®¢ª dword'®¢ ¢ ª®«¨ç¥á⢥ ecx ¯® ¤à¥áã edx, äãªæ¨ï áà ¢¥¨ï ¢ ebx |
; §àãè ¥â eax, ecx, esi, edi |
; Sorting bunch of dwords, count = ecx, locating at address = edx, |
; comparison function at ebx |
; Destroy content of eax, ecx, esi, edi |
sort: |
jecxz .done |
mov eax, ecx |
|
@@: |
push eax |
call .restore |
9,6 → 11,7 |
pop eax |
dec eax |
jnz @b |
|
@@: |
cmp ecx, 1 |
jz .done |
19,6 → 22,7 |
mov eax, 1 |
call .restore |
jmp @b |
|
.done: |
ret |
|
34,7 → 38,7 |
.restore: |
lea esi, [eax+eax] |
cmp esi, ecx |
ja .doner |
ja .donerr |
push esi |
mov esi, [edx+esi*4-4] |
mov edi, [edx+eax*4-4] |
42,13 → 46,14 |
pop esi |
ja .need_xchg |
cmp esi, ecx |
jae .doner |
jae .donerr |
push esi |
mov esi, [edx+esi*4] |
mov edi, [edx+eax*4-4] |
call ebx |
pop esi |
jbe .doner |
jbe .donerr |
|
.need_xchg: |
cmp esi, ecx |
jz .do_xchg |
58,10 → 63,15 |
call ebx |
pop esi |
sbb esi, -1 |
|
.do_xchg: |
mov edi, eax |
call .exchange |
mov eax, esi |
jmp .restore |
.doner: |
|
.donerr: |
ret |
|
; vim: ft=fasm tabstop=4 |
|