[英]Is this assembly code generated complete?
I wrote this simple C code and compiled it using Visual Studio 2010, with assembler output. 我编写了这个简单的C代码,并使用Visual Studio 2010编译它,带有汇编程序输出。
int main(){
int x=1;
int y=2;
int z=x+y;
return 0;
}
And this is the assembly output.. 这是装配输出..
; 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 do not see any
ADD
statement. 我没有看到任何
ADD
声明。 What compiler can be used to compile it? 可以使用什么编译器来编译它?
Since your code doesn't do anything with those values, the compiler has optimized most of it out. 由于您的代码不对这些值执行任何操作,因此编译器已对其中的大部分进行了优化。 As Carl mentioned, all that remains is the
xor eax, eax
which is zeroing eax, the register that the return value is placed. 正如Carl所提到的,剩下的就是
xor eax, eax
将eax归零,返回值的寄存器。
Even if you were to printf("%d", z)
, your result z
is a compile-time constant (3), and that is all you would see in the assembly listing. 即使你是
printf("%d", z)
,你的结果z
也是一个编译时常量(3),这就是你在汇编列表中看到的全部内容。
What you can do is disable optimizations in your project C++ properties, and you should see your expected assembly. 您可以做的是在项目C ++属性中禁用优化,您应该看到预期的程序集。 Also, building in Release mode should minimize the extra debug stuff you see in the asm.
此外,在Release模式下构建应该最小化您在asm中看到的额外调试内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.