Visual Studio 中的外部程序集文件 [英] external assembly file in visual studio
问题描述
我搜索并发现我无法在 Visual Studio 的 x64 中使用 __asm
.相反,我必须使用外部程序集文件.
I searched and found I can not use __asm
in x64 in visual studio. Instead I have to use an external assembly file.
如何将外部程序集文件添加到我的 win32 控制台项目中?
How can I add external assembly file to my win32 console project?
如何编译它们?
你能不能一步一步地解释一下.
Can you explain step by step.
推荐答案
如何在 Visual Studio 中使用 x64 程序集文件构建混合源 x64 项目:
1) 启动 Visual Studio (Community) 2015 并选择 FILE - New - Project
.
1) Start Visual Studio (Community) 2015 and choose FILE - New - Project
.
2) 在下一个窗口中选择Win 32 Console Application
.
2) In the next window choose Win 32 Console Application
.
3) 你得到一个确认.点击Next>
.
3) You get a confirmation. Click on Next >
.
4) 在下一个窗口中,您可以接受默认设置.点击Finish
.
4) In the next window you can accept the default settings. Click on Finish
.
5) 确保该项目在解决方案资源管理器中突出显示,然后从菜单中选择 PROJECT - Build Customizations...
.
5) Make sure, that the project is highlighted in the Solution Explorer and and choose PROJECT - Build Customizations...
from the menu.
6) 在下一个窗口中勾选masm(.targets,.props)
并点击OK
.
6) In the next window tick masm(.targets,.props)
and click on OK
.
7) 选择 Build - Configuration Manager...
8) 将 Active solution platform
更改为 x64
8) Change the Active solution platform
to x64
9) 创建 callee.asm:PROJECT - 添加新项目
.
9) Create callee.asm: PROJECT - Add New Item
.
10) 在下一个窗口中选择 C++File(.cpp)
和 - IMPORTANT! - 给它一个带有 .asm的名称代码> 扩展.点击
添加
.
10) In the next window choose C++File(.cpp)
and - IMPORTANT! - give it a name with an .asm
extension. Click on Add
.
10) 现在检查 .asm
文件是否具有正确的属性.在解决方案资源管理器中右键单击该文件并选择 Properties
.
10) Now check if the .asm
file has the right properties. In the Solution Explorer right-click on the file and choose Properties
.
11) 在属性页中,您至少应该看到:
11) In the Property Page you should see at least:
Excluded From Build (empty) or No
Item Type Microsoft Macro Assembler
在Command Line
下确保选择ml64.exe
作为汇编程序.
Under Command Line
ensure that ml64.exe
is chosen as the assembler.
点击OK
.
12) 现在您可以用内容填充文件了.
12) Now you can fill the files with content.
ConsoleApplication1.cpp:
#include <iostream>
using namespace std;
extern "C" void hello_from_asm();
int main()
{
cout << "Hello from CPP" << endl;
hello_from_asm();
return 0;
}
callee.asm:
PUBLIC hello_from_asm
EXTERN puts:PROC
.data
hello1 db "Hello from ASM.",0
.code
hello_from_asm PROC
push rbp
mov rbp, rsp
sub rsp, 32 ; Shadow Space
and spl, -16 ; Align stack at 16
lea rcx, hello1
call puts
leave ; Restore stack (rsp) & frame pointer (rbp)
ret
hello_from_asm ENDP
END
13) 构建 .exe
13) Build the .exe
并使用 CTRL-F5 运行它.
应用程序将在新窗口中打开.
The application will be opened in a new window.
这篇关于Visual Studio 中的外部程序集文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!