编程语言中代码块中的变量
using namespace std;
int max10 = 10;
int i = 0; // 放入内存中
int length[10];
for ( i = 0; i < max10; i++)
{
cout << i + 1 << endl; // 把相加的结果放入 寄存器中 具体看汇编代码 ,这样不应影响内存中的值
length[i] = i;
}
汇编代码:
using namespace std;
int max10 = 10;
00760F55 mov dword ptr [max10],0Ah
int i = 0;
00760F5C mov dword ptr [i],0
int length[10];
for ( i = 0; i < max10; i++)
00760F63 mov dword ptr [i],0
00760F6A jmp __$EncStackInitStart+39h (0760F75h)
00760F6C mov eax,dword ptr [i]
00760F6F add eax,1
00760F72 mov dword ptr [i],eax
00760F75 mov eax,dword ptr [i]
00760F78 cmp eax,dword ptr [max10]
00760F7B jge __$EncStackInitStart+7Fh (0760FBBh)
{
cout << i + 1 << endl;
00760F7D mov esi,esp
00760F7F push offset std::endl<char,std::char_traits<char> > (0761064h)
00760F84 mov eax,dword ptr [i]
00760F87 add eax,1
00760F8A mov edi,esp
00760F8C push eax
00760F8D mov ecx,dword ptr [__imp_std::cout (07760B8h)]
00760F93 call dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (07760C0h)]
00760F99 cmp edi,esp
00760F9B call __RTC_CheckEsp (07614DDh)
00760FA0 mov ecx,eax
00760FA2 call dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (0776098h)]
00760FA8 cmp esi,esp
00760FAA call __RTC_CheckEsp (07614DDh)
length[i] = i;
00760FAF mov eax,dword ptr [i]
00760FB2 mov ecx,dword ptr [i]
00760FB5 mov dword ptr length[eax*4],ecx
}
00760FB9 jmp __$EncStackInitStart+30h (0760F6Ch)