简体   繁体   English

MASM32 程序集在 Visual Studio 中不起作用

[英]MASM32 Assembly does not work in Visual Studio

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.首先,我尝试使用 py il 和 python 但它没有用。 Now I have a Visual Studio 2022 and I installed the MASM32.现在我有一个 Visual Studio 2022,我安装了 MASM32。 The problem is Visual Studio give a A1000 error so it does not find the file, and the second error:问题是 Visual Studio 给出了 A1000 错误,所以它找不到文件,第二个错误:

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 MSB3721 命令“ml.exe /c /nologo /Zi /Fo"Debug\Main.obj" /W3 /errorReport:prompt /TaMain.asm" 已退出,代码为 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所以我检查了模板文件的 Property > Linker: Output file: D:Assembly
Additional Library Directories: C:\Users\User\source\repos\Template\Template附加库目录:C:\Users\User\source\repos\Template\Template

After I checked the Main.asm file's Property > General > Ithem type: Microsoft Macro Assembler在我检查了 Main.asm 文件的 Property > General > Ithem 类型之后: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!感谢您的回答!

Visual Studio 2022 and prior versions include 32 bit masm (ml.exe) and 64 bit masm (ml64.exe). Visual Studio 2022 和之前的版本包括 32 位 masm (ml.exe) 和 64 位 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. Shell 输出并将源文件复制到目录中。 Add existing item to add source file(s) to project.添加现有项以将源文件添加到项目。 Double click on file name for it to show in main window.双击文件名,在 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.对于 64 位构建,请使用 ml64(64 位汇编程序)而不是 ml。

When doing a build, ignore Link warning about /LTCG (whole code optimization), it isn't an issue to leave it on.进行构建时,请忽略有关 /LTCG(整体代码优化)的链接警告,保留它不是问题。 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 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). Irvine32.inc 可能需要修改才能与 Visual Studio 一起使用(我从未使用过)。 The example masm code in that prior answer uses Visual Studio include files (for the.lib references).先前答案中的示例 masm 代码使用 Visual Studio 包含文件(用于 .lib 引用)。 As noted in that prior answer, the legacy lib is needed for printf, scanf, since VS 2015.如之前的回答所述,自 VS 2015 以来,printf、scanf 需要旧版库。

When in doubt about using some library or naming conventions (like C++ mangled function names), I code it in C |当对使用某些库或命名约定有疑问时(如 C++ 损坏的 function 名称),我将其编码为 C | C++, and have Visual Studio produce assembly code to get the calling sequence code. C++,并让Visual Studio生成汇编代码来获取调用序列代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 了解masm32和Visual Studio 2013的程序集语法问题 - Understanding assembly syntax issues with masm32 and Visual Studio 2013 Visual Studio (MASM) 程序集 - 为什么标签中的代码会自动执行,即使没有调用 label - Visual Studio (MASM) assembly - why does code in labels automatically execute, even if label not called 在Visual Studio 2012中生成XML序列化程序集不起作用 - Generating XML Serialization Assembly in Visual Studio 2012 does not work 在没有Visual Studio的情况下安装Masm - Install masm without visual studio 使用Visual Studio 2008来组装,链接,调试和执行MASM 6.11汇编代码 - Using Visual Studio 2008 to Assemble, Link, Debug, and Execute MASM 6.11 Assembly Code MASM64,Visual Studio 2015 C程序,在单独的文件中具有汇编功能 - MASM64, Visual studio 2015 C program with assembly function in separate file Visual Studio是否将测试类编译为程序集? - Does Visual Studio compile test classes into an assembly? 程序集引用的“特定版本”属性在Visual Studio中的工作原理是什么? - How exactly does the “Specific Version” property of an assembly reference work in Visual Studio? Visual Studio 中“首选 32 位”设置的目的是什么?它实际上是如何工作的? - What is the purpose of the "Prefer 32-bit" setting in Visual Studio and how does it actually work? Greenshot在Visual Studio中不起作用 - Greenshot does not work in Visual Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM