Visual Studio編寫C++代碼使用彙編函數
- 建立空項目
- 建立如下源檔案
;test.asm ;測試函數 三個數相加 ;.386 .model flat, c ;public test_ .code test_ proc ;初始化棧幀指針 push ebp mov ebp,esp ;加載參數值 mov eax,[ebp+8] mov ecx,[ebp+12] mov edx,[ebp+16] ;求和 add eax,ecx add eax,edx ;恢複父函數的棧幀指針 pop ebp ret test_ endp end
//main.cpp #include <stdio.h> #include <stdlib.h> extern "C" int test_(int a, int b, int c); int main() { int a = 17; int b = 20; int c = 19; int sum = test_(a, b, c); printf("c = %d\n", sum); system("pause"); return 0; }
- 更改
檔案的屬性如下asm

- 繼續更改自定義生成工具
VisualStudio C++使用彙編函數 -
指令行與輸出添加如下條件語句
指令行填寫:
ml /c /coff %(fileName).asm
其實是指 編譯器ml
後邊跟的是指令ml.exe
隻編譯,不連結\c
\coff
生成這種格式的目标檔案
輸出填寫:
%(fileName).obj;%(OutPuts)
- 編譯運作即可