纯64位汇编:
includelib ucrt.lib
includelib legacy_stdio_definitions.lib
includelib user32.libextern printf:proc
extern MessageBoxA:proc.data
szFormat db "%s",0
szHello db "HelloWorld",0
szRk db "123",0.code
start procsub rsp,28hmov rdx,offset szHellomov rcx,offset szFormatcall printfmov r9,0mov r8,offset szHellomov rdx,offset szRkmov rcx,0call MessageBoxAadd rsp,28hret
start endp
end
注意:
1.平台工具集要选VS2015
2.属性->生成依赖项->masm
3.链接器->高级->入口点
64位混合编程(C++/Asm):一定要严格执行代码规范,不然各种报错
1.asm:
includelib legacy_stdio_definitions.lib
includelib user32.libextern printf:proc.dataszformat db "%s\n",0.code
Myadd procsub rsp,28hadd rcx,rdxmov rax,rcxadd rsp,28hret
Myadd endpMyprintf procsub rsp,28hmov rdx,rcxlea rcx,szformatcall printfadd rsp,28hret
Myprintf endp
end
main.cpp:
#include <iostream>
#include <windows.h>EXTERN_C UINT64 Myadd(UINT64 a, UINT64 b);
EXTERN_C void Myprintf(const char* szbuffer);int main()
{UINT64 num = Myadd(1, 2);printf("%lld\r\n", num);Myprintf("hello word");system("pause");return 0;
}
注意:
如果生成报错,并且没有属性里面没有Microsoft Macro Assembler,换成VS2015也没有的话,
就在源文件里面找到.asm后缀的文件右键属性->常规->项类型->Microsoft Macro Assembler即可。