问题描述
g++ 向我抱怨以下代码中缺少括号:
g++ is complaining to me about a missing bracket in the following code:
1 2 3
v v v
__asm__ volatile("inb %1, %0" : : "=a" (result) : "Nd" (portnumber) );
^ ^ ^
1 2 3
如您所见,括号是匹配的,并且有三个左括号和三个右括号.
as you can see the brackets are matching and there are three open brackets and three close brackets.
还有更多信息,我正在关注 youtube 教程
also for more information i am following a youtube tutorial
推荐答案
您在输出之前有一个额外的 :
,因此您最终在输出声明中输入部分.该错误的原因是:您的输入操作数声明,其中编译器需要 clobber 列表. clobber 列表只能包含字符串文字(寄存器名称和 memory"
和/或 cc"
),而不是 ()
.
You have an extra :
before the output, so you ended up with your output declaration in the input part. And the reason for that error: your input operand declaration where the compiler expects the clobber list. The clobber list can only include string literals (register names and "memory"
and/or "cc"
), not ()
.
__asm__ volatile("inb %1, %0"
: "=a" (result) // output
: "Nd" (portnumber) // input
// : "memory" // optional, clobber list
);
您可能需要一个 "memory"
破坏者列表来确保这是有序的.内存访问.或者不,如果你确定它不需要.
You might want a "memory"
clobber list to make sure this is ordered wrt. memory accesses. Or not, if you're sure it doesn't need to be.
脚注 1:x86 上的 asm 语句隐含地破坏了条件代码,cc"
.如果您愿意,可以将其用于文档.但是你不希望它在这里,因为 inb
不接触 EFLAGS.
Footnote 1: asm statements on x86 implicitly clobber the condition codes, "cc"
. You can use it for documentation if you like. But you don't want it here because inb
doesn't touch EFLAGS.
这篇关于括号中的 g++ 内联汇编不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!