Subversion Repositories Kolibri OS

Rev

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

  1. /*      strchr()                                        Author: Kees J. Bot */
  2. /*                                                              1 Jan 1994 */
  3.  
  4. /* char *strchr(const char *s, int c) */
  5. /*      Look for a character in a string. */
  6. /* */
  7. #include "asm.h"
  8.  
  9. ENTRY(strchr)
  10.         push    %ebp
  11.         movl    %esp, %ebp
  12.         push    %edi
  13.         cld
  14.         movl    8(%ebp), %edi   /* edi = string */
  15.         movl    $16, %edx       /* Look at small chunks of the string */
  16. next:
  17.         shll    $1, %edx        /* Chunks become bigger each time */
  18.         movl    %edx, %ecx
  19.         xorb    %al, %al        /* Look for the zero at the end */
  20.  
  21.         repne scasb
  22.         pushf   /* Remember the flags */
  23.         subl    %edx, %ecx
  24.         negl    %ecx    /* Some or all of the chunk */
  25.         subl    %ecx, %edi      /* Step back */
  26.         movb    12(%ebp), %al   /* The character to look for */
  27.  
  28.         repne scasb
  29.         je      found
  30.         popf    /* Did we find the end of string earlier? */
  31.         jne     next    /* No, try again */
  32.         xorl    %eax, %eax      /* Return NULL */
  33.         pop     %edi
  34.         pop     %ebp
  35.         ret
  36. found:
  37.         pop     %eax    /* Get rid of those flags */
  38.         leal    -1(%edi), %eax  /* Address of byte found */
  39.         pop     %edi
  40.         pop     %ebp
  41.         ret
  42.