观看了库函数 strlen 函数的原型 尝试着自己模仿写了一下 但是看反汇编代码 感觉还是不太一样
库函数strlen的调用代码及反汇编代码程序代码:
00401000 >/$ 55 PUSH EBP 00401001 |. 8BEC MOV EBP,ESP 00401003 |. 83EC 18 SUB ESP,18 00401006 |. C745 FC EC2040>MOV DWORD PTR SS:[EBP-4],w5.004020EC ; ASCII "This is a test text." 0040100D |. 8B45 FC MOV EAX,DWORD PTR SS:[EBP-4] 00401010 |. 8945 F4 MOV DWORD PTR SS:[EBP-C],EAX 00401013 |. 8B4D F4 MOV ECX,DWORD PTR SS:[EBP-C] 00401016 |. 83C1 01 ADD ECX,1 00401019 |. 894D F0 MOV DWORD PTR SS:[EBP-10],ECX 0040101C |> 8B55 F4 /MOV EDX,DWORD PTR SS:[EBP-C] 0040101F |. 8A02 |MOV AL,BYTE PTR DS:[EDX] 00401021 |. 8845 EF |MOV BYTE PTR SS:[EBP-11],AL 00401024 |. 8345 F4 01 |ADD DWORD PTR SS:[EBP-C],1 00401028 |. 807D EF 00 |CMP BYTE PTR SS:[EBP-11],0 0040102C |.^75 EE \JNZ SHORT w5.0040101C 0040102E |. 8B4D F4 MOV ECX,DWORD PTR SS:[EBP-C] 00401031 |. 2B4D F0 SUB ECX,DWORD PTR SS:[EBP-10] 00401034 |. 894D E8 MOV DWORD PTR SS:[EBP-18],ECX 00401037 |. 8B55 E8 MOV EDX,DWORD PTR SS:[EBP-18] 0040103A |. 8955 F8 MOV DWORD PTR SS:[EBP-8],EDX 0040103D |. 8B45 F8 MOV EAX,DWORD PTR SS:[EBP-8] 00401040 |. 50 PUSH EAX ; /<%d> 00401041 |. 68 04214000 PUSH w5.00402104 ; |format = "len=%d " 00401046 |. FF15 A0204000 CALL DWORD PTR DS:[<&MSVCR100.printf>] ; \printf 0040104C |. 83C4 08 ADD ESP,8 0040104F |. 33C0 XOR EAX,EAX 00401051 |. 8BE5 MOV ESP,EBP 00401053 |. 5D POP EBP 00401054 \. C3 RETN 对应c代码如下: #include <stdio.h> #include <string.h> int main(void) { char* p="This is a test text."; int len=strlen(p); printf("len=%d\n",len); return 0; }