VS2017如何使用C_C++语言调用汇编函数
VS2017如何使用C_C++语言调用汇编函数
1. 使用VS 创建一个新的空项目
2. 新建 main.cpp 文件和 test.asm 文件
3. main.cpp 文件与 test.asm 文件
main.cpp
//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 ", sum); system("pause"); return 0; }
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
4. 配置test.asm 文件
【1】 【2】 点击确定
【3】 再次打开属性页 命令行填写: ml /c /coff %(fileName).asm 输出填写:%(fileName).obj;%(OutPuts) ————-(注意空格)——–