完整的汇编程序如下:
.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/