Subversion Repositories Kolibri OS

Rev

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

  1. /*      memchr()                                        Author: Kees J. Bot */
  2. /*                                                              2 Jan 1994 */
  3.  
  4. /* void *memchr(const void *s, int c, size_t n) */
  5. /*      Look for a character in a chunk of memory. */
  6. /* */
  7. #include "asm.h"
  8.  
  9. ENTRY(memchr)
  10.         push    %ebp
  11.         movl    %esp, %ebp
  12.         push    %edi
  13.         movl    8(%ebp), %edi   /* edi = string */
  14.         movb    12(%ebp), %al   /* The character to look for */
  15.         movl    16(%ebp), %ecx  /* Length */
  16.         cmpb    $1, %cl /* 'Z' bit must be clear if ecx = 0 */
  17.         cld
  18.  
  19.         repne scasb
  20.         jne     failure
  21.         leal    -1(%edi), %eax  /* Found */
  22.         pop     %edi
  23.         pop     %ebp
  24.         ret
  25. failure:
  26.         xorl    %eax, %eax
  27.         pop     %edi
  28.         pop     %ebp
  29.         ret
  30.