Visual Studio-X64匯編編寫方法
更新時間:2024年09月30日 10:00:47 作者:向你扔雞爪
本文介紹了在Visual Studio中配置64位匯編環(huán)境和C++與匯編的混合編程的方法,詳細說明了設置平臺工具集、生成依賴項、鏈接器等步驟,并提供了解決可能出現(xiàn)的編譯錯誤的方案,感興趣的朋友跟隨小編一起看看吧
純64位匯編:
includelib ucrt.lib includelib legacy_stdio_definitions.lib includelib user32.lib extern printf:proc extern MessageBoxA:proc .data szFormat db "%s",0 szHello db "HelloWorld",0 szRk db "123",0 .code start proc sub rsp,28h mov rdx,offset szHello mov rcx,offset szFormat call printf mov r9,0 mov r8,offset szHello mov rdx,offset szRk mov rcx,0 call MessageBoxA add rsp,28h ret start endp end
注意:
1.平臺工具集要選VS2015
2.屬性->生成依賴項->masm
3.鏈接器->高級->入口點
64位混合編程(C++/Asm):一定要嚴格執(zhí)行代碼規(guī)范,不然各種報錯
1.asm:
includelib legacy_stdio_definitions.lib includelib user32.lib extern printf:proc .data szformat db "%s\n",0 .code Myadd proc sub rsp,28h add rcx,rdx mov rax,rcx add rsp,28h ret Myadd endp Myprintf proc sub rsp,28h mov rdx,rcx lea rcx,szformat call printf add rsp,28h ret 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后綴的文件右鍵屬性->常規(guī)->項類型->Microsoft Macro Assembler即可。
到此這篇關于Visual Studio-X64匯編編寫的文章就介紹到這了,更多相關Visual Studio-X64匯編內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
您可能感興趣的文章: