Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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. However, when run though GCC, I get the error: input operand constraint contains '='

If I change the flag to simply r then it will compile fine, but the value of val does not change.

like image 495
yuikonnu Avatar asked Jan 27 '26 03:01

yuikonnu


1 Answers

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. You probably meant to have 'dst' be an output:

asm("rev %[dst], %[src]" : [dst]"=r"(val) : [src]"r"(val));
like image 80
Chris Dodd Avatar answered Jan 29 '26 17:01

Chris Dodd