🆕 增加strcmp

This commit is contained in:
fslongjin 2022-04-21 23:32:40 +08:00
parent 9b382dab60
commit 2467367e05

View File

@ -231,6 +231,38 @@ void *memcpy(void *dst, void *src, long Num)
: "memory");
return dst;
}
/*
FirstPart and SecondPart
FirstPart = SecondPart => 0
FirstPart > SecondPart => 1
FirstPart < SecondPart => -1
*/
int strcmp(char * FirstPart,char * SecondPart)
{
register int __res;
__asm__ __volatile__ ( "cld \n\t"
"1: \n\t"
"lodsb \n\t"
"scasb \n\t"
"jne 2f \n\t"
"testb %%al, %%al \n\t"
"jne 1b \n\t"
"xorl %%eax, %%eax \n\t"
"jmp 3f \n\t"
"2: \n\t"
"movl $1, %%eax \n\t"
"jl 3f \n\t"
"negl %%eax \n\t"
"3: \n\t"
:"=a"(__res)
:"D"(FirstPart),"S"(SecondPart)
:
);
return __res;
}
void *memset_c(void *dst, unsigned char c, ul n)
{
unsigned char *s = (unsigned char *)dst;