我想开始学习Assembly,但它根本运行不起来。首先我尝试使用 py il 和 python 但它不起作用。现在我有一个 Visual Studio 2022 并安装了 MASM32。问题是 Visual Studio 给出 A1000 错误,因此它找不到该文件,第二个错误:
MSB3721 命令“ml.exe /c /nologo /Zi /Fo"Debug\Main.obj" /W3 /errorReport:prompt /TaMain.asm”退出,代码为 1.TemplateC:\Program Files\Microsoft Visual Studio。 2\社区\MSBuild\微软\VC 170\BuildCustomizations\masm.targets
所以我检查了模板文件的属性>链接器:
输出文件:D:Assembly
其他库目录:C:\Users\User\source
epos\模板\模板
检查 Main.asm 文件的属性 > 常规 > 项目类型后:Microsoft Macro Assembler
我的代码:
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
可能是什么问题? 谢谢各位的解答!
Visual Studio 2022 及之前版本包括 32 位 masm (ml.exe) 和 64 位 masm (ml64.exe)。我没有使用项目默认值,而是从空项目开始并添加自定义构建信息。这些是我使用的步骤:
创建空控制台项目,使用相同的目录...,创建一个目录。解压源文件并将其复制到目录中。添加现有项目以将源文件添加到项目中。双击文件名,使其显示在主窗口中。
我使用的项目属性:
linker
General
Enable Incremental Linking: No (/INCREMENTAL:NO)
Advanced
Randomized Base Address: No (/DYNAMICBASE:NO)
Image Has Safe Exception Handlers: No (/SAFESEH:NO)
我使用的源文件属性:
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
对于 64 位构建,请使用 ml64(64 位汇编器)而不是 ml。
进行构建时,忽略有关 /LTCG(整体代码优化)的链接警告,保留它不是问题。随机基址可能会影响某些处理器上的基准测试,这就是我将其关闭的原因。
链接到包含源代码示例的先前答案:
https://stackoverflow.com/a/64676049/3282056
Irvine32.inc 可能需要修改才能与 Visual Studio 一起使用(我从未使用过它)。先前答案中的示例 masm 代码使用 Visual Studio 包含文件(用于 .lib 引用)。正如之前的答案所述,自 VS 2015 起,printf、scanf 需要旧版库。
当对使用某些库或命名约定(例如 C++ 损坏的函数名称)有疑问时,我用 C | 进行编码C++,并让 Visual Studio 生成汇编代码来获取调用序列代码。
您可以在此链接中学习“如何下载 Visual Studio 并用乌尔都语设置 MASM 和 Irvine 32 库|| 分步指南” https://www.youtube.com/watch?v=81UUI8kO1LE