字符串比较的解读由C->汇编
if(strcmp(input_word,password)==0)
{
cout<<"graduations!\n";
}
else
{
cout<<"sorry\n";
}
在此过程中eax放置的是password的偏移量,即password的地址,esi则是输入的字符串的地址级input_word的地址
.text:00401061 mov cl, [esi];首先将输入的字符串的一个字节放到CL当中
.text:00401063 cmp cl, [eax];将password字符串的一个字节与CL中的数据进行比较
.text:00401065 jnz short loc_401081;不相等的话则跳转到loc_401081,将eax置1,输入sorry
.text:00401067 test cl, cl;//相等,并且为零,即已到字符串的末尾
.text:00401069 jz short loc_40107D;跳转到loc_40107D,将eax置0输出graduations
.text:0040106B mov cl, [esi+1]
.text:0040106E cmp cl, [eax+1]
.text:00401071 jnz short loc_401081
.text:00401073 add esi, 2
.text:00401076 add eax, 2
.text:00401079 test cl, cl
.text:0040107B jnz short loc_401061;//比较下一个字节
.text:0040107D
.text:0040107D loc_40107D: ; CODE XREF: _wmain+49j该程序段的作用是将eax中的内容置0
.text:0040107D xor eax, eax
.text:0040107F jmp short loc_401086
.text:00401081 ; ---------------------------------------------------------------------------
.text:00401081
.text:00401081 loc_401081: ; CODE XREF: _wmain+45j该程序段的作用是将eax中的内容置1
.text:00401081 ; _wmain+51j
.text:00401081 sbb eax, eax
.text:00401083 sbb eax, 0FFFFFFFFh
.text:00401086
.text:00401086 loc_401086: ; CODE XREF: _wmain+5Fj
.text:00401086 test eax, eax
.text:00401088 jnz short loc_4010A0
.text:0040108A mov edx, ds:__imp_?cout@std@@3V?$basic_ostream@DU?$char_traits@D@std@@@1@A ; std::basic_ostream<char,std::char_traits<char>> std::cout
.text:00401090 push offset aGraduations ; "graduations!\n"
.text:00401095 push edx ; _Ostr
.text:00401096 call ??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z ; std::operator<<<std::char_traits<char>>(std::basic_ostream<char,std::char_traits<char>> &,char const *)
.text:0040109B add esp, 8
.text:0040109E jmp short loc_4010B3
.text:004010A0 ; ---------------------------------------------------------------------------
.text:004010A0
.text:004010A0 loc_4010A0: ; CODE XREF: _wmain+68j
.text:004010A0 mov eax, ds:__imp_?cout@std@@3V?$basic_ostream@DU?$char_traits@D@std@@@1@A ; std::basic_ostream<char,std::char_traits<char>> std::cout
.text:004010A5 push offset aSorry ; "sorry\n"
.text:004010AA push eax ; _Ostr
.text:004010AB call ??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z ; std::operator<<<std::char_traits<char>>(std::basic_ostream<char,std::char_traits<char>> &,char const *)
.text:004010B0 add esp, 8
.text:004010B3
.text:004010B3 loc_4010B3: ; CODE XREF: _wmain+7Ej
.text:004010B3 ; _wmain:loc_4010B3j
.text:004010B3 jmp short loc_4010B3
.text:004010B3 _wmain endp