Reputation: 30605
I am looking at the Dissembly window in Visual Studio 2012 and I have the setting for interlacing C++ and generated ASM turned on. For this C++:
int main(){
int h = my_func(6);
}
I get this ASM:
int main(){
push ebp
mov ebp,esp
sub esp,0CCh
push ebx
push esi
push edi
lea edi,[ebp-0CCh]
mov ecx,33h
mov eax,0CCCCCCCCh
rep stos dword ptr es:[edi]
int h = my_func(4);
push 4
call my_func (0121159h)
add esp,4
mov dword ptr [h],eax
}
xor eax,eax
pop edi
pop esi
pop ebx
add esp,0CCh
cmp ebp,esp
} //What is this bracket??????
call __RTC_CheckEsp (01212E9h)
mov esp,ebp
pop ebp
ret
What is the odd bracket towards the end of the ASM? It doesn't have a corresponding bracket?
Upvotes: 0
Views: 81
Reputation: 283614
If you turn on the setting to include source line numbers in the interleaved listing, I think you'll see that both braces are the same, the end of the main
function.
It's completely normal for one line of C++ code to generate more than one instruction, and it's not unusual for those instructions to appear in multiple non-consecutive blocks. (In fact, when optimization is enabled, multiple blocks is the rule rather than the exception.)
This mixed listing contains the true machine code the compiler generated, expressed as assembly to make it easier to read. The C++ snippets are annotations telling you why the compiler generated each bit of assembly. The C++ snippets cannot be recombined into a complete C++ program.
Upvotes: 3