VS2022 汇编
项目右键 生成依赖项 生成自定义 勾选masm
链接器 高级 入口点 main
X86
.686
.model flat,stdcall
option casemap:none
includelib ucrt.lib
includelib legacy_stdio_definitions.libEXTERN printf:proc.data
szFormat db '%s',0
szStr db 'hello',0.code
main proclea eax, szStrpush eaxlea eax, szFormatpush eaxcall printfadd esp,8mov eax,eaxret
main endp
end
x64
includelib ucrt.lib
includelib legacy_stdio_definitions.libEXTERN printf:proc.data
szFormat db '%s',0
szHello db 'HelloWorld',0.code
main procsub rsp,28hlea rdx, szHellomov rcx,offset szFormatcall printfadd rsp,28hret
main endp
end
cpp文件调用汇编函数
要注意汇编文件的项类型正确配置
;includelib ucrt.lib
includelib legacy_stdio_definitions.libEXTERN printf:proc.data
szFormat db '%s',0
szHello db 'Hello X64',0.code
x64_print procsub rsp,28hlea rcx, szHellocall printfmov eax,666add rsp,28hret
x64_print endp
end
extern "C" int x64_print();int main()
{x64_print();return 0;
}