余沁遥 發表於 2024-9-30 10:00:47

Visual Studio-X64汇编编写方法

<p>纯64位汇编:</p>
<div class="jb51code"><pre class="brush:plain;">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 </pre></div>
<p>注意:</p>
<p>1.平台工具集要选VS2015</p>
<p>2.属性-&gt;生成依赖项-&gt;masm</p>
<p>3.链接器-&gt;高级-&gt;入口点</p>
<p style="text-align:center"><img alt="" src="https://img.jbzj.com/file_images/article/202409/2024093009474721.png" /></p>
<p>64位混合编程(C++/Asm):<strong>一定要严格执行代码规范,不然各种报错</strong></p>
<p style="text-align:center"><img alt="" src="https://img.jbzj.com/file_images/article/202409/2024093009474722.png" /></p>
<p>1.asm:</p>
<div class="jb51code"><pre class="brush:plain;">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 </pre></div>
<p>main.cpp:</p>
<div class="jb51code"><pre class="brush:cpp;">#include &lt;iostream&gt;
#include &lt;windows.h&gt;
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;
}</pre></div>
<p>注意:</p>
<p>如果生成报错,并且没有属性里面没有<strong>Microsoft Macro Assembler,</strong>换成VS2015也没有的话,</p>
<p>就在源文件里面找到.asm后缀的文件右键属性-&gt;常规-&gt;项类型-&gt;Microsoft Macro Assembler即可。</p>
<p style="text-align:center"><img alt="" src="https://img.jbzj.com/file_images/article/202409/2024093009474723.png" /></p>
<p>到此这篇关于Visual Studio-X64汇编编写的文章就介绍到这了,更多相关Visual Studio-X64汇编内容请搜索琼殿技术社区以前的文章或继续浏览下面的相关文章希望大家以后多多支持琼殿技术社区!</p>
                           
                            <div class="art_xg">
                              <b>您可能感兴趣的文章:</b><ul><li>在 Visual Studio 中查看反汇编代码</li></ul>
                            </div>

                        </div>
                        <!--endmain-->
頁: [1]
查看完整版本: Visual Studio-X64汇编编写方法