【发布时间】:2020-02-12 15:48:25
【问题描述】:
我试图在我的主程序集文件中包含一个包含宏的头文件,但编译失败。
下面是我的main.S文件
#include "common.h"
BEGIN
mov $0x0E40, %ax
int $0x10
hlt
以下是我的common.h 文件:
.macro BEGIN
LOCAL after_locals
.code16
cli
ljmp $0, $1f
1:
xor %ax, %ax
/* We must zero %ds for any data access. */
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
mov %ax, %bp
/* Automatically disables interrupts until the end of the next instruction. */
mov %ax, %ss
/* We should set SP because BIOS calls may depend on that. TODO confirm. */
mov %bp, %sp
/* Store the initial dl to load stage 2 later on. */
mov %dl, initial_dl
jmp after_locals
initial_dl: .byte 0
after_locals:
.endm
两个文件都在同一个目录中。当我进行编译时:
$ as --32 -o main.o main.S
main.S: Assembler messages:
main.S:2: Error: no such instruction: `begin'
我错过了什么?我做了一些研究并在 SO 中得到了this answer,但它没有帮助。请帮忙。
【问题讨论】:
-
as不会对您的文件调用 C 预处理器。只有gcc可以。您可以手动运行它或使用gcc -c。或者您可以使用由as自己处理的.include。 -
在没有首先运行 CPP 的纯 GAS 中,以
#开头的行是总是 cmets。 -
谢谢小丑和彼得。这很有帮助。您能否将其发布为答案,以便我接受它并帮助未来的访问者。
标签: gcc assembly gnu gnu-assembler att