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?
如何编译它们?
您可以逐步解释吗?
推荐答案
如何在Visual Studio中使用x64程序集文件构建混合源x64项目.:
1)启动Visual Studio(社区)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 - Add New Item
.
9) Create callee.asm: PROJECT - Add New Item
.
10)在下一个窗口中,选择C++File(.cpp)
,然后--重要!-给它起一个带有.asm
扩展名的名称.点击Add
.
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屋!