c - 如何从 Assembly 调用 C 函数?

标签 c assembly

完整的汇编程序如下:

.model small
.stack 256

.code
start:
    call printer
    mov ax, 3       ; store 3 into ax

    mov ah, 76      ; back to DOS
    mov al, 0       ; no errors
    int 21h         ; interupt -> DOS
end start

这就是我定义 C 函数 printer

#include <stdio.h>

void printer()
{
    printf("Hello!\n");
}

编译汇编代码时,出现错误:undefined symbol: printer。在 C 中,我会做一个 #include "file.h",我如何在这里获得相同的结果?

最佳答案

问题不是编译,而是链接。您必须链接(如果在 Unix/Linux 上,则使用 ld)您的可执行文件,包括带有汇编代码的目标文件和带有 C 代码的目标文件。

或者使用 "asm" block 将汇编代码放入 C 文件。

关于c - 如何从 Assembly 调用 C 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26136927/

相关文章:

c - 浮点舍入错误将报告的结果移动到范围内

c - 臂组件 memset 更换

c - volatile 指令的执行

c++ - 手动添加 vector 异常处理程序

c - C语言中的字符串连接?

c - 无法比较多个字符

assembly - 关于 X86-64 的 glibc 启动代码的问题

汇编寻址模式

c -/usr/include/linux 和/usr/include/x86_64-linux-gnu/有什么区别

c - GLSL 着色器编译失败(但只是有时)