minix/lib/libc/arch/i386/string/_strncmp.S
Arun Thomas 9a21d1a2fd Macros for symbols used in both ASM and C
-The macros take care of prepending the leading underscore when
 necessary.
2010-08-17 16:44:07 +00:00

34 lines
731 B
ArmAsm

/* strncmp() Author: Kees J. Bot */
/* 1 Jan 1994 */
/* int strncmp(const char *s1, const char *s2, size_t ecx) */
/* Compare two strings. */
/* */
#include <machine/asm.h>
ENTRY(_strncmp)
push %ebp
movl %esp, %ebp
push %esi
push %edi
testl %ecx, %ecx /* Max length is zero? */
je done
movl 8(%ebp), %esi /* esi = string s1 */
movl 12(%ebp), %edi /* edi = string s2 */
cld
compare:
cmpsb /* Compare two bytes */
jne done
cmpb $0, -1(%esi) /* End of string? */
je done
decl %ecx /* Length limit reached? */
jne compare
done:
seta %al /* al = (s1 > s2) */
setb %ah /* ah = (s1 < s2) */
subb %ah, %al
movsbl %al, %eax /* eax = (s1 > s2) - (s1 < s2), i.e. -1, 0, 1 */
pop %edi
pop %esi
pop %ebp
ret