我写完这个简单程序后,在Visual Studio的反汇编模式下发现了一些奇怪的东西:编译器添加了一个左移0位的指令。
它为什么要这样做呢?
以下是C++代码:
#include <iostream>
using namespace std;
int main(int argc, char **argv) {
if (argc != 3)
return 0;
if (strcmp(argv[1], "-r") == 0) {
printf("test");
}
return 0;
}
这是汇编代码:
...
return 0;
00131C94 xor eax,eax
00131C96 jmp main+57h (0131CC7h)
if (strcmp(argv[1], "-r") == 0) {
00131C98 push offset string "-r" (0138B30h)
00131C9D mov eax,4
00131CA2 shl eax,0 <------------------------- HERE
00131CA5 mov ecx,dword ptr [argv]
00131CA8 mov edx,dword ptr [ecx+eax]
00131CAB push edx
00131CAC call _strcmp (01313D9h)
00131CB1 add esp,8
00131CB4 test eax,eax
00131CB6 jne main+55h (0131CC5h)
printf("test");
00131CB8 push offset string "test" (0138BD0h)
00131CBD call _printf (01313E8h)
00131CC2 add esp,4
...