-1

I wanted to start learn Assembly but it did not run any way. First I tried with py il with python but it did not work. Now I have a Visual Studio 2022 and I installed the MASM32. The problem is Visual Studio give a A1000 error so it does not find the file, and the second error:

MSB3721 The command "ml.exe /c /nologo /Zi /Fo"Debug\Main.obj" /W3 /errorReport:prompt /TaMain.asm" exited with code 1.TemplateC:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\BuildCustomizations\masm.targets

So I checked the template file's Property > Linker: Output file: D:Assembly
Additional Library Directories: C:\Users\User\source\repos\Template\Template

After I checked the Main.asm file's Property > General > Ithem type: Microsoft Macro Assembler

And my code:

INCLUDE Irvine32.inc

.386
.model flat, stdcall
.stack 4049
ExitProcess PROTO, dwExitCode:DWORD

.data

        ; define your variables here

.code
main PROC
        ; write your assembly code here

        mov eax, 3
        mov ebx, 5
        add eax, ebx

        INVOKE ExitProcess, 0
main ENDP
END main

What could be the problem? Thanks for the answers!

Vakos
  • 1
  • 1
    It must be showing the actual error somewhere - the MSB3721 and return code of 1 just means that something went wrong. What do you get if you run ml from the command-line with the arguments above? – 500 - Internal Server Error Jan 29 '23 at 14:26
  • [Assembly programming - WinAsm vs Visual Studio 2017](https://stackoverflow.com/q/52796300) shows how to set up an asm-only "project" in visual studio. IDK if you're doing something different. You might need to `INCLUDE Irvine32.inc` *after* `.386` / `.model flat, stdcall`, in case anything in it depends on those settings. (See also other links in https://stackoverflow.com/tags/x86/info for more guides, although mostly they're not specific to Irvine or VS.) – Peter Cordes Jan 29 '23 at 17:04

1 Answers1

2

Visual Studio 2022 and prior versions include 32 bit masm (ml.exe) and 64 bit masm (ml64.exe). Rather than using project defaults, I start off with empty projects and add custom build info. These are the steps I use:

create empty console project, use same directory for ..., creates a directory. Shell out and copy source file(s) into directory. Add existing item to add source file(s) to project. Double click on file name for it to show in main window.

project properties I use:

linker
 General
  Enable Incremental Linking: No (/INCREMENTAL:NO)
 Advanced
  Randomized Base Address: No (/DYNAMICBASE:NO)
  Image Has Safe Exception Handlers: No (/SAFESEH:NO)

source file properties I use:

Excluded From Build: No
Item Type: Custom Build Tool
Custom Build Tool for debug
 command line: ml /c /Zi /Fo$(OutDir)\x.obj x.asm
 output file:  $(OutDir)\x.obj
Custom Build Tool for release (/Zi is not needed)
 command line: ml /c /Fo$(OutDir)\x.obj x.asm
 output file:  $(OutDir)\x.obj

For 64 bit builds, use ml64 (64 bit assembler) instead of ml.

When doing a build, ignore Link warning about /LTCG (whole code optimization), it isn't an issue to leave it on. Randomized Base Address can affect benchmarks on some processors, which is why I turn it off.

Link to a prior answer that includes a source code example:

https://stackoverflow.com/a/64676049/3282056

There is a possibility that Irvine32.inc will need to be modified to work with Visual Studio (I've never used it). The example masm code in that prior answer uses Visual Studio include files (for the .lib references). As noted in that prior answer, the legacy lib is needed for printf, scanf, since VS 2015.

When in doubt about using some library or naming conventions (like C++ mangled function names), I code it in C | C++, and have Visual Studio produce assembly code to get the calling sequence code.

rcgldr
  • 27,407
  • 3
  • 36
  • 61