strcmp() 的原型
int strcmp(
const char *string1,
const char *string2
);
该函数返回一个 int ,其解释如下,
所以我认为这可以回答您的问题,即它何时跳转,何时不
跳转,如果 eax 是 > 或 < 0
,如果 eax == 0 则不跳转
Return Value
The return value for each of these functions indicates
the lexicographic relation of string1 to string2.
< 0 string1 less than string2
0 string1 identical to string2
> 0 string1 greater than string2
test eax,eax 执行一个二进制和两个输入,
并且它要跳转 eax 需要为 0 如果 eax 为 0 test eax,eax 会将 ZF 设置为 1 否则它会将 ZF 设置为 0
通常测试 eax 将被使用,如果高级语言的程序测试结果是这样的
if(!strcmp( a, b ) ) { do something }
请参阅下面的示例程序和反汇编
>>> eax = -1
>>> print eax & eax
-1
>>> eax = 0
>>> print eax & eax
0
>>> eax = 1
>>> print eax & eax
1
>>>
示例程序
#include <stdio.h>
#include <string.h>
int main (void) {
char *first="same";char *secon="same";char *third="diff";char *forth="tiff";
int fis = strcmp(first,secon);
int sec = strcmp(first,third);
int tid = strcmp(first,forth);
printf("%8x %8x %8x\n",fis,sec,tid);
if(!strcmp(first,secon)){
printf("trings are same \n");
}
if( strcmp(first,third) == 1 ) {
printf("second string has a chareceter that is greater than first string\n");
}
if( strcmp(first,forth) == -1 ) {
printf("second string has a chareceter that is lesser than first string\n");
}
}
主要拆解