I want to write some inline ARM assembly in my C code. For this code, I need to use a register or two more than just the ones declared as inputs and outputs to the function. I know how to use the clobber list to tell GCC that I will be using some extra registers to do my computation.

However, I am sure that GCC enjoys the freedom to shuffle around which registers are used for what when optimizing. That is, I get the feeling it is a bad idea to use a fixed register for my computations.

What is the best way to use some extra register that is neither input nor output of my inline assembly, without using a fixed register?

P.S. I was thinking that using a dummy output variable might do the trick, but I'm not sure what kind of weird other effects that will have...

有帮助吗?

解决方案

Ok, I've found a source that backs up the idea of using dummy outputs instead of hard registers:

4.8 Temporary registers: People also sometimes erroneously use clobbers for temporary registers. The right way is to make up a dummy output, and use “=r” or “=&r” depending on the permitted overlap with the inputs. GCC allocates a register for the dummy value. The difference is that GCC can pick a convenient register, so it has more flexibility.

from page 20 of this pdf.

For anyone who is interested in more info on inline assembly with GCC this website turned out to be very instructive.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top