"Hello World" in C++, compiled to x86 Assembly
gist.github.com
"Hello World" in C++, compiled to x86 Assembly
1–4 of 4 posts
Re: "Hello World" in C++, compiled to x86 Assembly
#2It's significantly smaller when I do it on my machine with an optimizer.
Interestingly, g++ compiles it to the exact same code if you remove all the crap that isn't the main with the cout printing a literal string.
Re: "Hello World" in C++, compiled to x86 Assembly
#3Without and with some optimization i get this results.
g++ -o hello hello.cpp
objdump --disassemble hello | wc -l
289
With some optimization
g++ -o hello hello.cpp -O3 -fno-rtti -fno-exceptions -fmessage-length=0 -funroll-all-loops -fomit-frame-pointer -falign-loops=2 -falign-jumps=2 -falign-functions=2 ;
objdump --disassemble hello | wc -l
256
Re: "Hello World" in C++, compiled to x86 Assembly
#4This looks like it was compiled with `-O0 -g`. It'll be a lot slimmer with `-O1` or even `-Os`.
Edit: In fact, GCC 4.6.1 compiles it down to two function calls and some stack operations - about 15 instructions in all.