Avatar ·

How to get assembly listing from C/C++ code in GCC?

Hello everyone. I'm learning C++ and trying to understand how the compiler translates my code into machine instructions. I want to see what, for example, a simple loop or function call turns into. I'm using GCC (g++) on Linux.\n\nI tried the `-S` flag, it seems to create a `.s` file, but there's a lot of garbage — labels, `.cfi_*` directives, obscure names like `.LC0`. Even a simple `hello.cpp`:\n\n```cpp\n#include \nint main() {\n std::cout << "Hello";\n return 0;\n}\n```\n\nAfter `g++ -S hello.cpp`, in `hello.s` I see not only the code but also a lot of extra stuff. How can I get a clean assembly listing where only my function's code is visible, without all this auxiliary information?\n\nI'm also interested: is it possible to view the assembly directly in the terminal without creating a file? And how to make a listing with interleaved source code?