Subversion Repositories Kolibri OS

Rev

Rev 1408 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1408 Rev 1627
Line 1... Line 1...
1
# strchr() Author: Kees J. Bot 1 Jan 1994
1
/*	strchr()					Author: Kees J. Bot */
-
 
2
/*								1 Jan 1994 */
Line 2... Line 3...
2
 
3
 
3
# char *strchr(const char *s, int c)
4
/* char *strchr(const char *s, int c) */
4
# Look for a character in a string.
5
/*	Look for a character in a string. */
5
 
-
 
6
.intel_syntax
-
 
7
 
6
/* */
8
.globl _strchr
7
#include "asm.h"
9
 
-
 
10
.text
-
 
11
           .align  16
8
 
12
_strchr:
9
ENTRY(strchr)
13
           push    ebp
10
	push	%ebp
14
           mov     ebp, esp
11
	movl	%esp, %ebp
15
           push    edi
12
	push	%edi
16
           cld
13
	cld
17
           mov     edi, [ebp+8]    # edi = string
14
	movl	8(%ebp), %edi	/* edi = string */
18
           mov     edx, 16         # Look at small chunks of the string
15
	movl	$16, %edx	/* Look at small chunks of the string */
19
next:
16
next:
20
           shl     edx, 1          # Chunks become bigger each time
17
	shll	$1, %edx	/* Chunks become bigger each time */
21
           mov     ecx, edx
18
	movl	%edx, %ecx
-
 
19
	xorb	%al, %al	/* Look for the zero at the end */
22
           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 */
Line 23... Line -...
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
26
	movb	12(%ebp), %al	/* The character to look for */
29
           movb    al, [ebp+12]    # The character to look for
27
 
30
           repne scasb
-
 
31
           je      found
28
	repne scasb
32
 
-
 
33
           popf                    # Did we find the end of string earlier?
29
	je	found
34
 
-
 
35
           jne     next            # No, try again
30
	popf	/* Did we find the end of string earlier? */
36
 
31
	jne	next	/* No, try again */
37
           xor     eax, eax        # Return NULL
32
	xorl	%eax, %eax	/* Return NULL */
38
           pop     edi
33
	pop	%edi
39
           pop     ebp
34
	pop	%ebp
40
           ret
35
	ret
41
found:
36
found:
42
           pop     eax             # Get rid of those flags
37
	pop	%eax	/* Get rid of those flags */
43
           lea     eax, [edi-1]    # Address of byte found
38
	leal	-1(%edi), %eax	/* Address of byte found */
44
           pop     edi
39
	pop	%edi