"Hello World" in C++, compiled to x86 Assembly (gist.github.com) 10 points by charliesome 14y ago ↗ HN
[–] dlsspy 14y ago ↗ It'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.
[–] [dead] DasFuxx 14y ago ↗ Without and with some optimization i get this results.g++ -o hello hello.cppobjdump --disassemble hello | wc -l289With some optimizationg++ -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 -l256
[–] greyfade 14y ago ↗ This 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.
3 comments
[ 3.6 ms ] story [ 20.6 ms ] threadInterestingly, 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.
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
Edit: In fact, GCC 4.6.1 compiles it down to two function calls and some stack operations - about 15 instructions in all.