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

  1. / strrchr.s (emx+gcc) -- Copyright (c) 1990-1993 by Eberhard Mattes
  2.  
  3.         .globl _strrchr
  4.   
  5. / char *strrchr (const char *string, int c)
  6. / {
  7. /   int i;
  8. /   
  9. /   i = 0;
  10. /   while (string[i] != 0) ++i;
  11. /   while (i >= 0)
  12. /     if (string[i] == (char)c)
  13. /       return ((char *)(string+i));
  14. /     else
  15. /       --i;
  16. /   return (NULL);
  17. / }
  18.  
  19.         .text
  20.  
  21.         .align  2, 0x90
  22.  
  23. _strrchr:
  24.         pushl   %edi
  25.         movl    2*4(%esp), %edi         / string
  26.         movl    $-1, %ecx
  27.         xorb    %al, %al
  28.         repne
  29.         scasb
  30.         notl    %ecx                    / ecx = strlen (string) + 1
  31.         decl    %edi                    / edi = string + strlen (string)
  32.         movb    3*4(%esp), %al          / c
  33.         std
  34.         repne
  35.         scasb
  36.         cld
  37.         jne     1f
  38.         lea     1(%edi), %eax
  39.         popl    %edi
  40.         ret
  41.  
  42.         .align  2, 0x90
  43. 1:      xorl    %eax, %eax
  44.         popl    %edi
  45.         ret
  46.