x86 汇编代码未编译
x86 assembly code not compiling
我有以下代码,其中我试图在 C 中调用一个汇编函数,它试图在(QEmu 的)VGA 显示器上打印 "e":
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
为什么会出现这个错误?
NASM gives special treatment to symbols beginning with a period. A label beginning with a single period is treated as a local label
NASM does have a global
directive,但是写的没有句首。所以也许你打算写 global _put_in_mem
我有以下代码,其中我试图在 C 中调用一个汇编函数,它试图在(QEmu 的)VGA 显示器上打印 "e":
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
为什么会出现这个错误?
NASM gives special treatment to symbols beginning with a period. A label beginning with a single period is treated as a local label
NASM does have a global
directive,但是写的没有句首。所以也许你打算写 global _put_in_mem