I am not able to relate my C code to the generated assembly code. How should I do that? That is, how can I find the generated assembly code for any one C line?
The easiest way to view the disassembly code in line with the C-source code is to view it in the mixed mode. For this, you can right click anywhere on your source-code after the build, and click on “Mixed” option in the menu.
It is also worth noting that this is only available if you have enabled the option 'Generate debug information' in the Compile:General section of the Project Options.
I'd hold fire on recommending Mixed Mode if building optimised, because of the way the compiler can re-order instructions or inline functions Mixed Mode can be a little misleading.
True that reading optimized assembler can be confusing, but it also shows where the optimizer may be too aggressive. For example, if you don't declare a variable as Volatile, the optimizer may not re-read it within a loop, but that won't happen in the non-optimized code.
Is there a temprary file that holds the disassembly that can be accessed directly? Is there another way of viewing the disassembly aside from the Disassembly Window and the mixed mode?
I would like to copy the disassembly in preparation of a report on various compiler optimizations. However, the Disassembly Window doesn't allow copying and the mixed mode is too cluttered with source code and is misordered.
If you're using the IDDE, you can go to the compiler property page (under Project Options) and select "Save Temporary Files".
If you're working on the command line, just add the -save-temps switch when you invoke the compiler.
You will find a file with the extension .s, same name as your .c file (foo.c generates foo.s). The .s file will be in the same location as the object file created by the compiler.
Thanks for your reply. While the .s file is a useful view of the assembly, it isn't quite what I'm looking for.
What I like about the Disassembly Window and mixed view mode is that they will show me the address in program memory of each instruction, and therefore allow me to determine the size of code modules. This is one of the key metrics in my compiler optimization experiments.
The Disassembly Window has exactly what I want. It just won't let me copy it!
The disassembly window lets you dump contents, which may match what you require; simply right-click on the disassembly window and choose "Dump...". Select to dump to a text file, and set the 'format' to "Assembly", and ensure you check "Show addresses". This will produce a listing to the text file containing the address and disassembly for each memory location.
Additionally, if you want to determine the size of code, you can check the XML Linker Map File generated by enabling the option: Project Options->Link->General->Generate symbol map.
Thanks Craig. I tried the dump previously but hadn't chosen the correct width for short-word memory. The map file is also a useful file.
Retrieving data ...