在 Visual Studio 中编译程序集 [英] Compiling assembly in Visual Studio

查看:42
本文介绍了在 Visual Studio 中编译程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 Visual Studio 编译汇编代码?

How do you compile assembly code using Visual Studio?

我想在 Visual Studio 2010 中编译和运行程序集源文件.

I want to compile and run an assembly source file in Visual Studio 2010.

我创建了一个 Visual C++ 项目并在文件 code.asm 中插入了一些汇编代码:

I've created a Visual C++ project and inserted some assembly code in a file code.asm:

.586              ;Target processor.  Use instructions for Pentium class machines
.MODEL FLAT, C    ;Use the flat memory model. Use C calling conventions
.STACK            ;Define a stack segment of 1KB (Not required for this example)
.DATA             ;Create a near data segment.  Local variables are declared after
                  ;this directive (Not required for this example)
.CODE             ;Indicates the start of a code segment.

clear PROC
   xor eax, eax 
   xor ebx, ebx 
   ret 
clear ENDP 
END

然而,问题是当您尝试编译它时,您会得到:

However the problem is when you try and compile this, you get:

LINK : error LNK2001: unresolved external symbol _mainCRTStartup

我确实去启用了构建自定义masm.targets(右键单击项目>构建自定义..),但无济于事.

I did go and enable the build customization masm.targets (right click project > Build Customizations..), but to no avail.

推荐答案

在我看来,.asm 文件的自定义构建规则未启用.右键单击项目,自定义构建规则,勾选Microsoft Macro Assembler".使用END clear"指令并禁用增量链接,我得到了一个干净的构建.

Sounds to me like the custom build rules for .asm files isn't enabled. Right-click the project, Custom Build Rules, tick "Microsoft Macro Assembler". With the "END clear" directive and disabling incremental linking I'm getting a clean build.

VS2010开始就不同了:

  1. 右键单击项目构建自定义,勾选ma​​sm".
  2. 右键单击.asm 文件,属性,将项目类型更改为Microsoft Macro Assembler".
  1. Right-click Project, Build customizations, tick "masm".
  2. Right-click the .asm file, Properties, change Item Type to "Microsoft Macro Assembler".

这篇关于在 Visual Studio 中编译程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆