我有这段内联汇编代码,应该以文本模式打印4:
void print(){
asm volatile(
"mov ax,0xb800\n"
"mov ds,ax\n" /*<-as complains about this*/
"movb 0,'A'\n"
);
}
但是,当我尝试使用gcc(带有-m32和-masm = intel)进行编译时:
./source/kernel.c: Assembler messages:
./source/kernel.c:4: Error: invalid instruction suffix for `mov'
顺便说一句,这段代码来自我操作系统的内核,所以我不能使用stdio.h或类似的东西。
Despite GCC's line numbering in the error message, that's not the line it's actually complaining about, it's the
movb
store. You can test that by commenting the other instructions. The error is actually printed by the assembler, with numbering based on.loc
metadata directives from the compiler, and this is a multi-line asm template, so it's easy for that to go wrong I guess.IDK why GAS doesn't accept it, but
movb ds:0, 'A'
works, and so doesmovb [0], 'A'
. It's a good idea anyway to use square brackets or something to indicate a memory destination when you have a literal number as the address.