我有以下代码,我试图在C中调用汇编函数,它试图打印" e"在VGA显示器(QEmu):
void main()
{
extern void put_in_mem();
char c = 'e';
put_in_mem(c, 0xA0);
}
put_in_mem函数定义如下:
.global _put_in_mem
_put_in_mem:
push bp
mov bp, sp
mov cx, [bp + 4]
mov ax, [bp + 6]
mov ax, 0xb800
mov ds, ax
mov [bx], cx
add bx, 0x1
mov cx, 0x7
mov [bx], cx
pop bp
ret
当我使用nasm编译上面的汇编代码时,我收到以下错误:
put_in_mem.asm:1: error: attempt to define a local label before any non-local labels
put_in_mem.asm:1: error: parser: instruction expected
为什么会出现这个错误?
答案 0 :(得分:1)
NASM对以句号开头的符号给予特殊处理。以单个句点开头的标签被视为本地标签
NASM does have a global
directive,但它的编写没有初始阶段。所以也许你打算写global _put_in_mem