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