Subversion Repositories Kolibri OS

Rev

Rev 3709 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3709 clevermous 1
; Sort array of unsigned dwords in non-decreasing order.
2
; ecx = array size, edx = array pointer.
3
; Destroys eax, ecx, esi, edi.
4
sort:
3711 clevermous 5
        test    ecx, ecx
6
        jz      .done
3709 clevermous 7
        mov     eax, ecx
8
@@:
9
        push    eax
10
        call    .restore
11
        pop     eax
12
        dec     eax
13
        jnz     @b
14
@@:
15
        cmp     ecx, 1
16
        jz      .done
17
        mov     esi, 1
18
        mov     edi, ecx
19
        call    .exchange
20
        dec     ecx
21
        mov     eax, 1
22
        call    .restore
23
        jmp     @b
24
.done:
25
        ret
26
 
27
.exchange:
28
        push    eax ecx
29
        mov     eax, [edx+esi*4-4]
30
        mov     ecx, [edx+edi*4-4]
31
        mov     [edx+esi*4-4], ecx
32
        mov     [edx+edi*4-4], eax
33
        pop     ecx eax
34
        ret
35
 
36
.restore:
37
        lea     esi, [eax+eax]
38
        cmp     esi, ecx
39
        ja      .doner
40
        mov     edi, [edx+eax*4-4]
3711 clevermous 41
        cmp     [edx+esi*4-4], edi
3709 clevermous 42
        ja      .need_xchg
43
        cmp     esi, ecx
44
        jae     .doner
45
        mov     edi, [edx+eax*4-4]
3711 clevermous 46
        cmp     [edx+esi*4], edi
3709 clevermous 47
        jbe     .doner
48
.need_xchg:
49
        cmp     esi, ecx
50
        jz      .do_xchg
51
        mov     edi, [edx+esi*4-4]
3711 clevermous 52
        cmp     [edx+esi*4], edi
3709 clevermous 53
        sbb     esi, -1
54
.do_xchg:
55
        mov     edi, eax
56
        call    .exchange
57
        mov     eax, esi
58
        jmp     .restore
59
.doner:
60
        ret