c++cvisual-studio-2010assembly

Disassembling Simple Hello World program


I wrote this small C++ program and built it(Release)

#include<iostream>
int main(){
     std::cout<<"Hello World";
     return 0;
}

When I disassemble it, it has a lot of extra code(security cookie etc..). I believe Visual Studio is adding all those. How can I compile this program without any extra information, so that its easy to understand its disassembled code?

I know assembly is comparatively harder, but what I mean is getting a hello world asm code out of a hello world c++ program. Is this possible?


Solution

  • You're starting with a huge code base with <iostream>. What you might want to do is avoid the use of a runtime library entirely. Try something like this:

    #include <windows.h>
    
    int main() {
        HANDLE stdout = GetStdHandle(STD_OUTPUT_HANDLE);
        WriteFile(stdout, "Hello world\n", 12, NULL, NULL);
        return 0;
    }
    

    Compile that with assembly listing turned on, and that should give you some "raw" Win32 code to start with.