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\n", 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)
————-(注意空格)——–
这里写图片描述

5. 编译 运行

这里写图片描述

猜你喜欢

转载自blog.csdn.net/qq_33775402/article/details/78828235
今日推荐