Subversion Repositories Kolibri OS

Rev

Rev 1408 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*      strncmp()                                       Author: Kees J. Bot */
  2. /*                                                              1 Jan 1994 */
  3.  
  4. /* int strncmp(const char *s1, const char *s2, size_t ecx) */
  5. /*      Compare two strings. */
  6. /* */
  7. #include "asm.h"
  8.  
  9. ENTRY(_strncmp)
  10.         push    %ebp
  11.         movl    %esp, %ebp
  12.         push    %esi
  13.         push    %edi
  14.         testl   %ecx, %ecx      /* Max length is zero? */
  15.         je      done
  16.         movl    8(%ebp), %esi   /* esi = string s1 */
  17.         movl    12(%ebp), %edi  /* edi = string s2 */
  18.         cld
  19. compare:
  20.         cmpsb   /* Compare two bytes */
  21.         jne     done
  22.         cmpb    $0, -1(%esi)    /* End of string? */
  23.         je      done
  24.         decl    %ecx    /* Length limit reached? */
  25.         jne     compare
  26. done:
  27.         seta    %al     /* al = (s1 > s2) */
  28.         setb    %ah     /* ah = (s1 < s2) */
  29.         subb    %ah, %al
  30.         movsbl  %al, %eax       /* eax = (s1 > s2) - (s1 < s2), i.e. -1, 0, 1 */
  31.         pop     %edi
  32.         pop     %esi
  33.         pop     %ebp
  34.         ret
  35.