Share via


Creating a Listing of the Assembly Code

You can create a listing of the assembly code that the C/C++ compiler (Cl.exe) generates from your source code. This listing contains both the source code and the generated assembly code. This listing also lets you see line numbers, functions, and generated assembly code that can be helpful during debugging.

You can create an assembly code listing in one of the following ways:

  • To create an assembly code listing for every C/C++ source file in your project, add the following to your Sources file:

    USER_C_FLAGS=$(USER_C_FLAGS)/FAsc /Fa$(O)
    

    When you run the Build utility, it starts the NMAKE utility (Nmake.exe). For every C/C++ file that is listed in the SOURCES macro of your Sources file, NMAKE starts the C/C++ compiler to compile the source file and create the code listing (.cod) file. The .cod files are created in the same directory where the Build utility creates object files. For more information, see Specifying the Location of Created Files.

  • To create an assembly code listing for a single C/C++ source file in your project, type the following code in the command-line in the WDK build environment window:

    nmake SourceFileName.cod

    The C/C++ compiler, which is started by NMAKE, creates the .cod files for the specified file in the same directory where the source file resides.

    Note  You cannot use this method if your project requires precompiled header files as specified within your Sources file. For more information, see Using Precompiled Headers.

The following code example shows an excerpt of an assembly code listing from a .cod file:

?OnRead@CQueue@@UAGXPAUIWDFIoQueue@@PAUIWDFIoRequest@@K@Z PROC ; CQueue::OnRead, COMDAT

; 222  : {      

  000008b ff  npad 2
  0000255  push ebp
  000038b ec  mov ebp, esp
__annotation$73771:

; 223  :     Trace(TRACE_LEVEL_INFORMATION,"%!FUNC!");

  00005a1 00 00 00 00 mov eax, DWORD PTR _WPP_GLOBAL_Control
  0000a3d 00 00 00 00 cmp eax, OFFSET _WPP_GLOBAL_Control
 0000f74 1e  je SHORT $LN3@OnRead
 00011f6 40 1c 01 test BYTE PTR [eax+28], 1
  0001574 18  je SHORT $LN3@OnRead
  0001780 78 19 04 cmp BYTE PTR [eax+25], 4
  0001b72 12  jb SHORT $LN3@OnRead
  0001d68 00 00 00 00 push OFFSET _WPP_Queue_cpp_Traceguids
  000226a 0c  push 12; 0000000cH
  00024ff 70 14 push DWORD PTR [eax+20]
  00027ff 70 10 push DWORD PTR [eax+16]
  0002ae8 00 00 00 00 call _WPP_SF_@16
$LN3@OnRead:

; 224  : 
; 225  :     //
; 226  :     // No need to check for zero-length reads.
; 227  :     //
; 228  :     // The framework queue is created with the flag bAllowZeroLengthRequests = FALSE.
; 229  :     // FALSE indicates that the framework completes zero-length I/O requests instead
; 230  :     // of putting them in the I/O queue. 
; 231  :     //
; 232  : 
; 233  :     //
; 234  :     // TODO: Put your Read request processing here
; 235  :     //
; 236  : 
; 237  :     pRequest->CompleteWithInformation(S_OK, SizeInBytes);

  0002fff 75 14 push DWORD PTR _SizeInBytes$[ebp]
  000328b 45 10 mov eax, DWORD PTR _pRequest$[ebp]
  000358b 08  mov ecx, DWORD PTR [eax]
  000376a 00  push 0
  0003950  push eax
  0003aff 51 20 call DWORD PTR [ecx+32]

; 238  : 
; 239  :     return;
; 240  : 
; 241  : }

  0003d5d  pop ebp
  0003ec2 10 00 ret 16  ; 00000010H
?OnRead@CQueue@@UAGXPAUIWDFIoQueue@@PAUIWDFIoRequest@@K@Z ENDP ; CQueue::OnRead

In a .cod file, the code lines from the C/C++ source file are preceded by "; line-number :", such as "; 239 : return" as shown in the previous example.

A line of generated assembly code contains the following items:

  • The byte offset (for example, 0003e).

  • The operation code (opcode) or machine code for the instruction.

  • The mnemonic for the assembly instructions (mov, push, call, and so on).

For a C++ source file, the .cod file also shows the function name decoration, also known as mangled function names, such as the one shown in the previous example for the OnRead callback function. For more information about function name decorations, see the Description of C++ Name Decoration topic on the Microsoft Help and Support website.

 

 

Send comments about this topic to Microsoft

Build date: 5/3/2011