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)
- 编译运行即可