1

Since coding in C is way easier than coding in assembly, my question is, "If I have a complex function, is there a way to directly see the assembly version of my C code?"

Is the command prompt the only place to do it? Or is there a quicker way to do the same thing but in Visual Studio (2022)? I've found in the Visual Studio documentation a paragraph about this issue, and I've read this path: "debug --> properties --> C/C++ --> output files -->", and I've changed the filename by specifying the folder name of the project but it didn't work.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • 2
    https://godbolt.org/ is great for code that doesn't need separate `.h` files, or that you can manually include. See also [How to remove "noise" from GCC/clang assembly output?](https://stackoverflow.com/q/38552116) for more about using it and writing functions that have compiler-generated asm worth looking at. – Peter Cordes Feb 24 '23 at 12:01

1 Answers1

3

In Visual Studio, you can specify that a C/C++ project should generate assembly code output files in the project's properties.

Right-click on the project1 in the Solution Explorer and select the "Properties" command. In the popup that appears, open the "C/C++" node in the left-hand pane (tree view) and then select the "Output Files" child node. In the right-hand pane that is displayed, there is an "Assembler Output" option (which is set to "No Listing" by default). Click on that option to see a drop-down list of the various output options available and select the one that best suits you.

The following shows this display for V/S 2022 but it is similar in other versions of the IDE:

enter image description here

The "Assembly-Only Listing" option gives the tersest output but the "Assembly With Source Code" option is generally more useful. Also, note that the assembler code generated by the MSVC compiler can be quite arcane – especially when using high optimisation levels.


1 You can also specify the assembler output options on an individual file within a project, by right-clicking on that file, rather than on the project itself.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • i've selected the listing but nothing happened when I've clicked "apply" and "ok", I'm still viewing the original function I've written in C – Gabriel Burzacchini Feb 24 '23 at 12:38
  • 2
    There will be a file or files in the "intermediate" directory/folder with the ".asm" extension. Open those from the VS IDE and you will see the generated assembler code. (The same folder as where the ".obj" files are.) Of course, you will need to rebuild (or at least re-compile) the project to get those files generated. – Adrian Mole Feb 24 '23 at 12:44