Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. # strncmp()  Author: Kees J. Bot 1 Jan 1994
  2.  
  3. # int strncmp(const char *s1, const char *s2, size_t ecx)
  4. #     Compare two strings.
  5. #
  6.  
  7. .intel_syntax
  8.  
  9. .globl __strncmp
  10.  
  11. .text
  12.            .align  16
  13. __strncmp:
  14.            push    ebp
  15.            mov     ebp, esp
  16.  
  17.            push    esi
  18.            push    edi
  19.  
  20.            test    ecx, ecx         # Max length is zero?
  21.            je      done
  22.  
  23.            mov     esi, [ebp+8]     # esi = string s1
  24.            mov     edi, [ebp+12]    # edi = string s2
  25.            cld
  26. compare:
  27.            cmpsb                    # Compare two bytes
  28.            jne     done
  29.  
  30.            cmpb    [esi-1], 0       # End of string?
  31.            je      done
  32.  
  33.            dec     ecx              # Length limit reached?
  34.            jne     compare
  35. done:
  36.            seta    al               # al = (s1 > s2)
  37.            setb    ah               # ah = (s1 < s2)
  38.            subb    al, ah
  39.            movsx  eax, al           # eax = (s1 > s2) - (s1 < s2), i.e. -1, 0, 1
  40.  
  41.            pop     edi
  42.            pop     esi
  43.            pop     ebp
  44.            ret
  45.