Take the 2-minute tour ×

I would like to ask about something I am thinking to try with Visual Studio 2010.

I am generating an .asm file from the.cpp file by setting the option to the "Assembler Output" in the project properties --> C/C++ --> Output Files (/FAs).

My question is, how can I on a next step use that .asm generated file to link again from that one without using anymore the .cpp file, in case I want to do some modifications inside the .asm file and then link again by keeping the modifications I did at assembly level.

It would be very helpful if you could provide the exact steps, including the correct configuration may needed in the project properties.

share|improve this question
First you need to compile it with ML, then you can go to linker. Look at command line parameters of ML.EXE, I never tried it in VS2010. –  Al Kepp Oct 11 '11 at 22:43
You could use inline asm in some cases –  BlackBear Oct 12 '11 at 12:08
Be careful if you want to use this for anything beyond experimentation/learning. MSVC assembler output doesn't play well with C++ (exception handling in particular), and MS doesn't support assembly listings other than for "informational purposes". See stackoverflow.com/questions/7488056/… –  Michael Burr Oct 27 '11 at 5:19
@Al Kepp, maybe you tried it with VS2008? It should be the same. Please let me know. –  Economou Kyriakos Oct 28 '11 at 15:52
@BlackBear, I know this. I just need to use the whole .asm generated file. –  Economou Kyriakos Oct 28 '11 at 15:53

2 Answers 2

Here is a tutorial http://www.cs.virginia.edu/~evans/cs216/guides/vsasm.html

share|improve this answer
Thank you for your time, but I am already aware of that tutorial which describes another case, different than mine. As already said I don't want just to link a function written in asm. I can do this easily with inline asm inside the .cpp file itself. –  Economou Kyriakos Oct 28 '11 at 15:55
You don't need the cpp file after that. I is compile using ml.exe with a custom build step. –  MartyTPS Oct 28 '11 at 17:48
As I said, I was actually looking for a solution to use the entire .asm generated file after compiling a C++ source (cpp file), and then use only the generated asm in order to compile again without using the cpp anymore. Thank you. That specific tutorial, describes a case in which he uses a function he wrote in asm along with the cpp file, which is different from what I want. However, I may use that tutorial to find a custom solution for my case since I have written a lot of my code in .asm inside the cpp file. –  Economou Kyriakos Oct 29 '11 at 22:49

I did this recently. Here is a repeat of the answer I gave here compile-assembly-output-generated-by-vc. It turns out you can still do this in 32-bit mode in MSVC2012 but I think 64-bit mode is hopeless.

For 32-bit mode here is what you do.

Create an empty project and a source file Source.cpp

 #include <stdio.h>
 int main() {
     printf("hello world\n");
     return 0;
  1. Right lick on your project and select "Build Customization" and
    select masm as described here http://www.masm32.com/board/index.php?topic=9231.0
  2. Under C++/OutputFiles select Assembly Output /FA
  3. Comipile in 32-bit mode Release mode
  4. Load the Source.asm file into MSVC so you can view it. It won't work yet. A few changes are still necessary.
  5. Under C++/Optimization turn off Whole Program Optimization (removes /GL). This adds the line INCLUDELIB MSVCRT
  6. In the Linker/Advanced set the last option "Image Has Safe Exception Handlers"to No (/SAFESEH:NO)
  7. Now you should have a Source.asm file which will do the same thing that Source.cpp file did. Copy the Source.cpp from the Release directory to the same directory as Source.cpp (so it's not deleted when you build/clean).
  8. Add Source.asm (as an existing file) to the Source Files and remove Source.cpp from the build.
  9. Rebuild and you should see "Hello World" without having to change any assembly lines by hand.

I have used this for more complicated functions. I usually do it on a separate module and use extern "C" on the function name to remove the C++ name mangling.

share|improve this answer

Your Answer


