Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. ; Sorting bunch of dwords, count = ecx, locating at address = edx,
  2. ; comparison function at ebx
  3. ; Destroy content of eax, ecx, esi, edi
  4. Sort:
  5.         jecxz   .Done
  6.         mov     eax,ecx
  7.     @@:
  8.         push    eax
  9.         call    .Restore
  10.         pop     eax
  11.         dec     eax
  12.         jnz     @B
  13.     @@:
  14.         cmp     ecx,1
  15.         jz      .Done
  16.         mov     esi,1
  17.         mov     edi,ecx
  18.         call    .Exchange
  19.         dec     ecx
  20.         mov     eax,1
  21.         call    .Restore
  22.         jmp     @B
  23.     .Done:
  24.         ret
  25.  
  26.     .Exchange:
  27.         push    eax ecx
  28.         mov     eax,[edx+esi*4-4]
  29.         mov     ecx,[edx+edi*4-4]
  30.         mov     [edx+esi*4-4],ecx
  31.         mov     [edx+edi*4-4],eax
  32.         pop     ecx eax
  33.         ret
  34.  
  35.     .Restore:
  36.         lea     esi,[eax+eax]
  37.         cmp     esi,ecx
  38.         ja      .DonErr
  39.         push    esi
  40.         mov     esi,[edx+esi*4-4]
  41.         mov     edi,[edx+eax*4-4]
  42.         call    ebx
  43.         pop     esi
  44.         ja      .NeedXchg
  45.         cmp     esi,ecx
  46.         jae     .DonErr
  47.         push    esi
  48.         mov     esi,[edx+esi*4]
  49.         mov     edi,[edx+eax*4-4]
  50.         call    ebx
  51.         pop     esi
  52.         jbe     .DonErr
  53.     .NeedXchg:
  54.         cmp     esi,ecx
  55.         jz      .DoXchg
  56.         push    esi
  57.         mov     edi,[edx+esi*4-4]
  58.         mov     esi,[edx+esi*4]
  59.         call    ebx
  60.         pop     esi
  61.         sbb     esi,-1
  62.     .DoXchg:
  63.         mov     edi,eax
  64.         call    .Exchange
  65.         mov     eax,esi
  66.         jmp     .Restore
  67.     .DonErr:
  68.         ret
  69.