Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 1626 → Rev 1627

/drivers/ddk/string/_strncmp.S
1,44 → 1,34
# strncmp() Author: Kees J. Bot 1 Jan 1994
/* strncmp() Author: Kees J. Bot */
/* 1 Jan 1994 */
 
# int strncmp(const char *s1, const char *s2, size_t ecx)
# Compare two strings.
#
/* int strncmp(const char *s1, const char *s2, size_t ecx) */
/* Compare two strings. */
/* */
#include "asm.h"
 
.intel_syntax
 
.globl __strncmp
 
.text
.align 16
__strncmp:
push ebp
mov ebp, esp
 
push esi
push edi
 
test ecx, ecx # Max length is zero?
ENTRY(_strncmp)
push %ebp
movl %esp, %ebp
push %esi
push %edi
testl %ecx, %ecx /* Max length is zero? */
je done
 
mov esi, [ebp+8] # esi = string s1
mov edi, [ebp+12] # edi = string s2
movl 8(%ebp), %esi /* esi = string s1 */
movl 12(%ebp), %edi /* edi = string s2 */
cld
compare:
cmpsb # Compare two bytes
cmpsb /* Compare two bytes */
jne done
 
cmpb [esi-1], 0 # End of string?
cmpb $0, -1(%esi) /* End of string? */
je done
 
dec ecx # Length limit reached?
decl %ecx /* Length limit reached? */
jne compare
done:
seta al # al = (s1 > s2)
setb ah # ah = (s1 < s2)
subb al, ah
movsx eax, al # eax = (s1 > s2) - (s1 < s2), i.e. -1, 0, 1
 
pop edi
pop esi
pop ebp
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