Is this assembly code generated?
I wrote this simple C code and compiled it with Visual Studio 2010 with assembler output.
int main(){
int x=1;
int y=2;
int z=x+y;
return 0;
}
And this is the assembly.
; Listing generated by Microsoft (R) Optimizing Compiler Version 16.00.40219.01
TITLE foobar.cpp
.686P
.XMM
include listing.inc
.model flat
INCLUDELIB OLDNAMES
EXTRN @__security_check_cookie@4:PROC
PUBLIC _main
; Function compile flags: /Ogtp
; File foobar.cpp
; COMDAT _main
_TEXT SEGMENT
_main PROC ; COMDAT
; 2 : int x=1;
; 3 : int y=2;
; 4 : int z=x+y;
; 5 : return 0;
xor eax, eax
; 6 : }
ret 0
_main ENDP
_TEXT ENDS
END
Is this complete? I can't see the operator ADD
. What compiler can I use to compile it?
source to share
Since your code does nothing with these values, the compiler has optimized most of it. As Karl mentioned, all that's left is xor eax, eax
that eax is zeroed out, the register that the return value is placed in.
Even if you were printf("%d", z)
, your output z
is a compile-time constant (3), and that's all you'll see in the assembly list.
What you can do is turn off optimizations in your C ++ project properties and you will see your expected build. In addition, building in Release mode should minimize the extra debug data you see in asm.
source to share