Observing the C Compiler

Honors Computer Systems Organization (Prof. Grishman)

Generating Assembly Code

You can make the Visual C++ compiler (and most other C compilers) display the code which they generate in the form of assembly language.

For the Visual C++ compiler, on the project menu, selecting "settings".  When the project settings window opens, select the C/C++ tab.  On the C/C++ pane, select category "Listing Files".  For "Listing File Type", select "Assembly with Source Code."  This will add the "/FAs" option to the compiler, which will produce a file with source and assembly code.  It will put it into the directory specified by the "/FA" option, which by default is the Debug directory.  Once this is set, a listing file (with extension .asm) will be generated each time the program is compiled.


By default, the compiler generates code which is well suited for debugging, with minimal regard for the efficiency of the generated code.  Each variable is loaded from memory each time it is used, and stored back into memory each time it is changed.  To generate more efficient code, on the C/C++ pane, select category "Optimizations".  On optimizations, select "Maximum Speed".  The compiler will then generate much more efficient code -- for example, by keeping variables in registers whenever possible.  Several compiler options, including /ZI and /GZ, are applicable only to debug mode;  these will need to be removed from the "Project Options" list on the C/C++ pane or the compiler will complain.