none
Compile assembly language program in Visual Studio 2005

    Question

  • I am curious how to compile an assembly language program from the IDE.  The program is in full segment definition and I can compile and link it using ml and link on the command line, although, I would like to be able to do the same thing from the IDE.  The only examples I can find are for compiling inline assembly for previous versions of Visual Studio.  That said, I have just upgraded from visual studio 6 so the interface is a bit new also.

    Sunday, October 08, 2006 4:25 AM

Answers

  • Some steps to do this:

    1) create a Win 32 Console Application project (for example). In the project wizard go to the Application Settings page and check Empty Project option so you don't get any C/C++ files.

    2) Add the assembly files to the project.

    Altough there is no template for asm files you can create a new asm file by selecting New Item, selecting Code/C++ file (.cpp) and then entering the name of the file with an .asm extension. The IDE will actually create an asm file instead of a C++ file.

    3) Right click the project node in solution explorer and select Custom Build Rules. In the dialog that appears check the Microsoft Macro Assembler rule.

    Build and run the project as with a normal C/C++ project ! If the assembly code is OK it should work.

    At least it worked for me with the following code:

    .686

    .model flat, stdcall

    .code

    main: ret

    end main

     

    Sunday, October 08, 2006 10:20 AM
    Moderator
  •  

    I was able to get it going.  Thank you.  I also ended up redefining the rules file for the assembler in order to include all of ml's options.  The last and final way; I just created a simple makefile project, created and modified a new makefile, and defined the build commands using some option I found in the Solutions Explorer.  Although this is something I rarely ever have to work with, I'm a bit supprised the newer version is still so limited when it comes to working with assembly language.

    Sunday, October 08, 2006 9:18 PM

All replies

  • Some steps to do this:

    1) create a Win 32 Console Application project (for example). In the project wizard go to the Application Settings page and check Empty Project option so you don't get any C/C++ files.

    2) Add the assembly files to the project.

    Altough there is no template for asm files you can create a new asm file by selecting New Item, selecting Code/C++ file (.cpp) and then entering the name of the file with an .asm extension. The IDE will actually create an asm file instead of a C++ file.

    3) Right click the project node in solution explorer and select Custom Build Rules. In the dialog that appears check the Microsoft Macro Assembler rule.

    Build and run the project as with a normal C/C++ project ! If the assembly code is OK it should work.

    At least it worked for me with the following code:

    .686

    .model flat, stdcall

    .code

    main: ret

    end main

     

    Sunday, October 08, 2006 10:20 AM
    Moderator
  •  

    I was able to get it going.  Thank you.  I also ended up redefining the rules file for the assembler in order to include all of ml's options.  The last and final way; I just created a simple makefile project, created and modified a new makefile, and defined the build commands using some option I found in the Solutions Explorer.  Although this is something I rarely ever have to work with, I'm a bit supprised the newer version is still so limited when it comes to working with assembly language.

    Sunday, October 08, 2006 9:18 PM
  • Hey ! It doesn't work in VS 2003
    Monday, October 23, 2006 12:15 PM
  • Nope, VS 2003 does not have those custom rules.You need to create your own custom build steps.

     

    Monday, October 23, 2006 12:39 PM
    Moderator
  • Hmmm - any idea how to start ... ?
    Monday, October 23, 2006 12:48 PM
  • Add an .asm file to the project, right click on it in the solution explorer and select Properties. In properties go to Configuration Properties\Custom Build Step\General and you have

    Command line: ml /c "$(InputPath)" /Fo"$(OutDir)\$(InputName).obj"

    Outputs: $(OutDir)\$(InputName).obj

    I hope it works cause I have no VS2003 around to test it.

     

    Tuesday, October 24, 2006 10:55 AM
    Moderator
  • Hi All,

     

     

    I have cpp and asm files in a huge project and I am trying to migrate the project from VS2003 to VS2005. I am not able to generate the obj files for the asm files. I am getting the PRJ0019 errors. Below is the buildlog.

     

    BUILDLOG

     

     
    Creating temporary file "c:\ClearCase\ViewStore\ariyer_view_vs_2005\Logix\Engine\Executive\Debug\BAT00098831925452.bat" with contents
    [
    @echo off
    
    nasm -f win32 -o .\Debug\rtston.obj c:\ClearCase\ViewStore\ariyer_view_vs_2005\Logix\Engine\Source\rtston.asm
    
    
    
    if errorlevel 1 goto VCReportError
    
    goto VCEnd
    
    :VCReportError
    
    echo Project : error PRJ0019: A tool returned an error code from "Performing Custom Build Step"
    
    exit 1
    
    :VCEnd
    ]
    Creating command line "c:\ClearCase\ViewStore\ariyer_view_vs_2005\Logix\Engine\Executive\Debug\BAT00098831925452.bat"
    Creating temporary file "c:\ClearCase\ViewStore\ariyer_view_vs_2005\Logix\Engine\Executive\Debug\BAT00098931925452.bat" with contents
    [
    @echo off
    
    nasm -f win32 -o .\Debug\rtsctu.obj c:\ClearCase\ViewStore\ariyer_view_vs_2005\Logix\Engine\Source\rtsctu.asm
    

    Can I know if I am missing any libraries to compile the asm files?

     

    Thanks,

    Saturday, September 22, 2007 4:49 PM
  • Hi Ananth lyer,

    Did you find out any solution for your problem yet? I also see it when converting my project to VS2005.

    Thanks,

    Tuesday, October 23, 2007 9:48 AM
  • Hi Lylyconan,

     

    See if you have the cygwinb19.dll in the root windows directory (may be C:\Windows).  Its a requirement for NASM. If your not using nasm,then you might be missing a path. Pls post the build log.

     

    -Ananth

     

    Tuesday, October 23, 2007 12:57 PM
  • I had to do something similar with our build system that generates VS build rules. One gotcha I stumbled over was that the /Fo parameter is placement sensitive as per http://msdn.microsoft.com/en-us/library/s0ksfwcf(VS.80).aspx

    The Command line should be:  ml /Fo"$(OutDir)\$(InputName).obj"  /c "$(InputPath)"

    Regards,

    Robert

    Tuesday, April 27, 2010 5:47 PM