home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / EMXLIB8F.ZIP / EMX / LIB / STR / MEMCHR.S < prev    next >
Encoding:
Text File  |  1993-01-02  |  876 b   |  40 lines

  1. / memchr.s (emx+gcc) -- Copyright (c) 1990-1993 by Eberhard Mattes
  2.  
  3.         .globl _memchr
  4.  
  5. / void *memchr (const void *s, int c, size_t n)
  6. / {
  7. /   size_t i;
  8. /   const char *p;
  9. /
  10. /   p = s;
  11. /   for (i = 0; i < n; ++i)
  12. /       if (p[i] == (char)c)
  13. /           return ((void *)(p+i));
  14. /   return (NULL);
  15. / }
  16.  
  17. / assumes ds=es!
  18.  
  19.         .text
  20.  
  21.         .align  2, 0x90
  22.  
  23. _memchr:
  24.         pushl   %edi
  25.         movl    2*4(%esp), %edi         / s
  26.         movb    3*4(%esp), %al          / c
  27.         movl    4*4(%esp), %ecx         / n
  28.         jecxz   1f                      / not found
  29.         repne
  30.         scasb
  31.         jne     1f                      / not found
  32.         lea     -1(%edi), %eax
  33.         popl    %edi
  34.         ret
  35.  
  36.         .align  2, 0x90
  37. 1:      xorl    %eax, %eax              / return (NULL)
  38.         popl    %edi
  39.         ret
  40.