szyjas
szyjas

Reputation: 19

I cannot compile any project in VS2019 with .asm and MASM

Hello and thanks in advance for helping

I'm total newbie in working with VS 2019, and i have to start now because it's needed in my uni.

Step-by-step given by my tutor:

  1. Create new project -> Windows Desktop Wizard -> (Default name optional)
  2. Console Application
  3. Configuration manager choose x64 (yes it needs to be 64-bit)
  4. Build Dependencies -> Build Customisations -> Select masm
  5. Add new -> New item -> c++ file named asm.asm

I`m following steps given by our teacher step-by-step to start a new project with simple a+b=c but when trying to compile that project VS returns lines presented below:

Build started...
1>------ Build started: Project: Project2, Configuration: Debug x64 ------
1>Assembling asm.asm...
1>D:\Visual\MSBuild\Microsoft\VC\v160\BuildCustomizations\masm.targets(70,5): error MSB3721: The command "ml64.exe /c /nologo /Zi /Fo"x64\Debug\asm.obj" /W3 /errorReport:prompt  /Taasm.asm" exited with code 1.
1>Done building project "Project2.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

My project's .cpp file contains:

#include <iostream>
using namespace std;
extern "C" __int64 sum(int a, int b);
int main(int argc, char* argv[])
{
    int a = 10;
    int b = 20;
    int c;
    c = sum(a, b);
    cout << "Sum = " << c << endl;
    system("PAUSE");
    return 0;
}

My file assembly file asm.asm that computes a+b=c contains:

.CODE
_DATA SEGMENT
_DATA ENDS
_TEXT SEGMENT
PUBLIC sum
suma PROC
    movsxd rax, ecx
    movsxd rdx, edx
    add rax, rdx
    ret
sum ENDP
_TEXT ENDS
END

Why am I getting a build error, and how can I solve this problem in my Visual Studio 2019 project?

Upvotes: 1

Views: 1270

Answers (1)

Iman Abdollahzadeh
Iman Abdollahzadeh

Reputation: 659

You have to do three things.

  1. Create a separate .asm file and write your assembly code there.

  2. Right click your solution and navigate to Build Dependencies->Build Customizations and check the masm box.

  3. Right click on your .asm file and go to Properties->Item Type and select Microsoft Macro Assembler.

Now you can link your assembly code to the C/C++ code.

Upvotes: 0

Related Questions