开发者

inline assembly output register declaration

i'm just about to learn inline assembly.the GCC inline assembly cookbook http://www.ethernut.de/en/documents/arm-inline-asm.html says:

A strict rule is: Never ever write to an input operand.

can someone tell me whether - and if so why - this rule is true?

let's say i get the value of an input operand through some register. Am I no开发者_C百科t allowed to reuse this register within the same assembly block if i don't inted to declare it also as output operand?

example:

asm volatile("add %[value], %[value], %[value]   \n\t"
    "mov %[result], %[value]   \n\t"

       : [result]"=r" (y) 
       : [value]"r"   (x)
       : //no clober
);

I know the example doesn't make much sense - but is it invalid?

I ask because i'm writing some assembly function that takes many input operands, each taking a general purpose register. since there are only 12 GPR's available on my architecture, with each input operand i get less "free" registers to work with. so do I really have to declare the input registers also as output in order to use them to "work" with them inside the function (even though i don't need theyr value outside the inline-assembly body? If so - can someone explain why?

hope the question is clear

thanks!


The compiler doesn't know x is clobbered (and I think there is no way to clobber an input register in a valid way). So it might reuse the register holding x later in the code assuming it still holds an unaltered value which isn't true since you changed it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜