[英]ARM inline assembly - input operand constraint contains '='
This is my current code: 这是我当前的代码:
void int32hex(u32 val, char *out) {
asm("rev %[dst], %[src]" :: [dst]"=r"(val), [src]"r"(val));
binhex((u8*)&val, 4, out);
}
My idea is to take the argument val
, flip it (endianness) using the rev
instruction, and then pass it on. 我的想法是采用参数val
,使用rev
指令翻转它(字节序),然后将其传递。
From what I've read, the above code seems to be correct, the destination register has the =r
flag, which implies that the register can be written to. 根据我的阅读,以上代码似乎是正确的,目标寄存器具有=r
标志,这意味着可以写入该寄存器。 However, when run though GCC, I get the error: input operand constraint contains '=' 但是,当通过GCC运行时,出现错误:输入操作数约束包含'='
If I change the flag to simply r
then it will compile fine, but the value of val
does not change. 如果我将标志更改为简单的r
则它将正常编译,但val
的值不会更改。
The error is telling you what is going wrong -- the =
constraint applies only to outputs, not inputs, and your asm pattern has two inputs (one confusingly called 'dst') and no outputs. 错误告诉您出了什么问题- =
约束仅适用于输出,不适用于输入,并且您的asm模式具有两个输入(一个令人困惑地称为“ dst”),而没有任何输出。 You probably meant to have 'dst' be an output: 您可能打算将“ dst”作为输出:
asm("rev %[dst], %[src]" : [dst]"=r"(val) : [src]"r"(val));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.