Can We Feed the Output of MSVC++ Assembly Listing to MASM32

Started by msqweasm, May 14, 2011, 07:41:06 AM

Previous topic - Next topic

msqweasm

(Originally wrongly placed in another subforum .  I guess here is a better place for it)

In MSVC++ 2008, we can use the /FA switch to create an assembly listing file for the C++ code.  Can we edit this file directly and assemble it using say MASM32 or any other tools available to MSVC++ 2008 (say ml.exe)?  I mean, is this file created for human reading only or is it just part of the compiler output used internally for the assembler?

The way I assemble the listing file is like this:

In the VC++ 2008 Tools menu->External Tool, create a new item to ml.exe:

Command:C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\ml.exe
Arguments:  /c $(ItemPath)
Initial Directory: $(targetdir)
Use Output Window: (selected)

Then open the .asm file in the IDE and click Tools->"the Newly Created Menu item for ml.exe".  This should invoke the ml.exe with the asm file as argument.

I have tried this myself with VC++ 2008.  When compiled to the Debug version (listing file generated in the Debug dir), it has errors:

Assembling: C:\work\cpp\editasm\editasm\Debug\editasm.asm
C:\work\cpp\editasm\editasm\Debug\editasm.asm(18) : error A2008:syntax error : .
C:\work\cpp\editasm\editasm\Debug\editasm.asm(22) : error A2008:syntax error : .
Microsoft (R) Macro Assembler Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.

MASM doesn't like these stuff:
; Listing generated by Microsoft (R) Optimizing Compiler Version 15.00.21022.08

   TITLE   c:\work\cpp\editasm\editasm\editasm.cpp
   .686P
   .XMM
   include listing.inc
   .model   flat

INCLUDELIB MSVCRTD
INCLUDELIB OLDNAMES

PUBLIC   _wmain
EXTRN   __RTC_Shutdown:PROC
EXTRN   __RTC_InitBase:PROC
;   COMDAT rtc$TMZ
; File c:\work\cpp\editasm\editasm\editasm.cpp
rtc$TMZ   SEGMENT
__RTC_Shutdown.rtc$TMZ DD FLAT:__RTC_Shutdown <------------ A2008
rtc$TMZ   ENDS
;   COMDAT rtc$IMZ
rtc$IMZ   SEGMENT
__RTC_InitBase.rtc$IMZ DD FLAT:__RTC_InitBase <------------ A2008
; Function compile flags: /Odtp /RTCsu /ZI
rtc$IMZ   ENDS
;   COMDAT _wmain
_TEXT   SEGMENT
_argc$ = 8                  ; size = 4
_argv$ = 12                  ; size = 4
_wmain   PROC                  ; COMDAT
; Line 8
   push   ebp
   mov   ebp, esp
   sub   esp, 192            ; 000000c0H
   push   ebx
   push   esi
   push   edi
   lea   edi, DWORD PTR [ebp-192]
   mov   ecx, 48               ; 00000030H
   mov   eax, -858993460            ; ccccccccH
   rep stosd
; Line 9
   xor   eax, eax
; Line 10
   pop   edi
   pop   esi
   pop   ebx
   mov   esp, ebp
   pop   ebp
   ret   0
_wmain   ENDP
_TEXT   ENDS
END


The Release version works fine.

Why are there errors for the Debug version?


jj2007

ML doesn't like the dot. Perhaps OPTION DOTNAME in one of the first lines could help, although afaik it is meant for leading dots.

msqweasm

No luck with OPTION DOTNAME (btw, is my modification correct?)

:
:
:
INCLUDELIB MSVCRTD
INCLUDELIB OLDNAMES

OPTION DOTNAME

PUBLIC   _wmain
EXTRN   __RTC_Shutdown:PROC
EXTRN   __RTC_InitBase:PROC
;   COMDAT rtc$TMZ
; File c:\work\cpp\editasm\edit
:
:
:


Assembling: C:\work\cpp\editasm\editasm\Debug\editasm.asm
C:\work\cpp\editasm\editasm\Debug\editasm.asm(18) : error A2008:syntax error : .rtc$TMZ
C:\work\cpp\editasm\editasm\Debug\editasm.asm(22) : error A2008:syntax error : .rtc$IMZ
Microsoft (R) Macro Assembler Version 9.00.21022.08


jj2007

Your modification is correct, but no surprise that it didn't work. Strange that ml chokes over that, one should think it must digest a listing generated by a C compiler... ::)

shileiyu

Turn off all RTCs (running-time checks).
so generated asm-listing is acceptable to MASM