The earlier version of this answer (a "hack" for rextester.com) is mostly redundant now that http://gcc.godbolt.org/ provides CL 19 RC for ARM, x86, and x86-64 (targeting the Windows calling convention, unlike gcc, clang, and icc on that site).
The Godbolt compiler explorer is designed for nicely formatting compiler asm output, removing the "noise" of directives, so I'd highly recommend using it to look at asm for simple functions that take args and return a value (so they won't be optimized away).
For a while, CL was available on http://gcc.beta.godbolt.org/ but not the main site, but now it's on both.
To get MSVC asm output from the http://rextester.com/l/cpp_online_compiler_visual online compiler: Add /FAs
to the command line options. Have your program find its own path and work out the path to the .asm
and dump it. Or run a disassembler on the .exe
.
e.g. http://rextester.com/OKI40941
#include <string>
#include <boost/filesystem.hpp>
#include <Windows.h>
using namespace std;
static string my_exe(void){
char buf[MAX_PATH];
DWORD tmp = GetModuleFileNameA( NULL, // self
buf, MAX_PATH);
return buf;
}
int main() {
string dircmd = "dir ";
boost::filesystem::path p( my_exe() );
//boost::filesystem::path dir = p.parent_path();
// transform c:\foo\bar\1234\a.exe
// into c:\foo\bar\1234\1234.asm
p.remove_filename();
system ( (dircmd + p.string()).c_str() );
auto subdir = p.end(); // pointing at one-past the end
subdir--; // pointing at the last directory name
p /= *subdir; // append the last dir name as a filename
p.replace_extension(".asm");
system ( (string("type ") + p.string()).c_str() );
// std::cout << "Hello, world!\n";
}
... code of functions you want to see the asm for goes here ...
type
is the DOS version of cat
. I didn't want to include more code that would make it harder to find the functions I wanted to see the asm for. (Although using std::string and boost run counter to those goals! Some C-style string manipulation that makes more assumptions about the string it's processing (and ignores max-length safety / allocation by using a big buffer) on the result of GetModuleFileNameA
would be much less total machine code.)
IDK why, but cout << p.string() << endl
only shows the basename (i.e. the filename, without the directories), even though printing its length shows it's not just the bare name. (Chromium48 on Ubuntu 15.10). There's probably some backslash-escape processing at some point in cout
, or between the program's stdout and the web browser.