Subversion Repositories Kolibri OS

Rev

Rev 1408 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1627 serge 1
/*	strncmp()					Author: Kees J. Bot */
2
/*								1 Jan 1994 */
1408 serge 3
 
1627 serge 4
/* int strncmp(const char *s1, const char *s2, size_t ecx) */
5
/*	Compare two strings. */
6
/* */
7
#include "asm.h"
1408 serge 8
 
1627 serge 9
ENTRY(_strncmp)
10
	push	%ebp
11
	movl	%esp, %ebp
12
	push	%esi
13
	push	%edi
14
	testl	%ecx, %ecx	/* Max length is zero? */
15
	je	done
16
	movl	8(%ebp), %esi	/* esi = string s1 */
17
	movl	12(%ebp), %edi	/* edi = string s2 */
18
	cld
1408 serge 19
compare:
1627 serge 20
	cmpsb	/* Compare two bytes */
21
	jne	done
22
	cmpb	$0, -1(%esi)	/* End of string? */
23
	je	done
24
	decl	%ecx	/* Length limit reached? */
25
	jne	compare
1408 serge 26
done:
1627 serge 27
	seta	%al	/* al = (s1 > s2) */
28
	setb	%ah	/* ah = (s1 < s2) */
29
	subb	%ah, %al
30
	movsbl	%al, %eax	/* eax = (s1 > s2) - (s1 < s2), i.e. -1, 0, 1 */
31
	pop	%edi
32
	pop	%esi
33
	pop	%ebp
34
	ret