1

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?

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
szyjas
  • 11
  • 2
  • The fact that no error is shown trying to assemble `asm.asm` (which has an error too) suggests to me that possibly ML64.EXE isn't installed on the path and the error is really because ML64.EXE doesn't exist where it is expected so it can't even attempt to assemble the file. – Michael Petch Jun 19 '23 at 15:42
  • I would expect the assembly to fail, due to the errors in the asm file. VS should be showing you the lines that contain the errors. What happens if you make all 3 places where you talk about `sum` use the same name (instead of sometimes using `suma`)? – David Wohlferd Jun 19 '23 at 19:39
  • Possible duplicate of [external assembly file in visual studio](https://stackoverflow.com/q/33751509) (mixed C++ and asm). Also related: [Assembly programming - WinAsm vs Visual Studio 2017](https://stackoverflow.com/q/52796300) (pure asm) – Peter Cordes Jun 19 '23 at 22:36
  • No @PeterCordes : I don't agree. Since there is no line number and error message this is likely that the 64-bit VS2019 build tools that include MASM's ML64.EXE are either not installed or they are no longer on VS2019 path. I recently saw this problem with a newer version of VS but in my brief search I couldn't seem to find the question. You'll see the errors the OP is describing if ML64.EXE just doesn't seem to exist. – Michael Petch Jun 19 '23 at 23:05
  • @PeterCordes : This question is probably more related if I had to guess: https://stackoverflow.com/questions/73230274/visual-studio-2022-error-msb3721-the-command-ml-exe-exited-with-code-1 . While the answer leaves something to be desired, the idea to increase the build verbosity level should tell us something. One can do that by pulling down the `Tools` menu; select `Options...`, select `Projects and Solutions` then `Build and Run` and set `Build output verbosity` to `Diagnostic`. Then rerun the build. – Michael Petch Jun 19 '23 at 23:24
  • 1
    @MichaelPetch: Oh right, it is trying to run `ml64` on it, unlike when VS treats the source file as C++ which is a different problem. I didn't have time to look at this question in any detail earlier, just wanted to link one of the canonical duplicates with a step-by-step guide. Turns out I should have said "possibly related" instead of "possible duplicate". If that guide no longer works 100% of the time, I guess it should get updated, or a new answer added for newer VS versions? IDK, I used VS for one job over 10 years ago, and that was just C++. – Peter Cordes Jun 20 '23 at 01:44

1 Answers1

0

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.

  • I see that i made an error in my initial post. I ve created separate .asm file and wrote assembly code there and did each of three points written above. To be sure i have checked my project with proposed solution and everything was as said above. – szyjas Jun 19 '23 at 14:23
  • 2
    I believe this works better if you add the Build Dependencies *before* adding the file. In my experience, doing it this way removes the need for step 3. – David Wohlferd Jun 19 '23 at 19:41