Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. # strchr() Author: Kees J. Bot 1 Jan 1994
  2.  
  3. # char *strchr(const char *s, int c)
  4. # Look for a character in a string.
  5.  
  6. .intel_syntax
  7.  
  8. .globl _strchr
  9.  
  10. .text
  11.            .align  16
  12. _strchr:
  13.            push    ebp
  14.            mov     ebp, esp
  15.            push    edi
  16.            cld
  17.            mov     edi, [ebp+8]    # edi = string
  18.            mov     edx, 16         # Look at small chunks of the string
  19. next:
  20.            shl     edx, 1          # Chunks become bigger each time
  21.            mov     ecx, edx
  22.            xorb    al, al          # Look for the zero at the end
  23.            repne scasb
  24.  
  25.            pushf                   # Remember the flags
  26.            sub     ecx, edx
  27.            neg     ecx             # Some or all of the chunk
  28.            sub     edi, ecx        # Step back
  29.            movb    al, [ebp+12]    # The character to look for
  30.            repne scasb
  31.            je      found
  32.  
  33.            popf                    # Did we find the end of string earlier?
  34.  
  35.            jne     next            # No, try again
  36.  
  37.            xor     eax, eax        # Return NULL
  38.            pop     edi
  39.            pop     ebp
  40.            ret
  41. found:
  42.            pop     eax             # Get rid of those flags
  43.            lea     eax, [edi-1]    # Address of byte found
  44.            pop     edi
  45.            pop     ebp
  46.            ret
  47.