分类: LINUX
2010-01-13 11:07:28
Clobber
ParameterOne of the dangers of intermixing assembly language and a compiled language such as Ada is that the compiler needs to be aware of which registers are being used by the assembly code. In some cases, such as the earlier examples, the constraint string is sufficient to indicate register usage (e.g. "a" for the eax register). But more generally, the compiler needs an explicit identification of the registers that are used by the Inline Assembly statements.
Using a register that the compiler doesn't know about
could be a side effect of an instruction (like mull
storing its result in both eax and edx).
It can also arise from explicit register usage in your
assembly code; for example:
Asm ("movl %0, %%ebx" & LF & HT &
"movl %%ebx, %1",
Inputs => Unsigned_32'Asm_Input ("g", Var_In),
Outputs => Unsigned_32'Asm_Output ("=g", Var_Out));
where the compiler (since it does not analyze the Asm
template string)
does not know you are using the ebx register.
In such cases you need to supply the Clobber
parameter to Asm
,
to identify the registers that will be used by your assembly code:
Asm ("movl %0, %%ebx" & LF & HT &
"movl %%ebx, %1",
Inputs => Unsigned_32'Asm_Input ("g", Var_In),
Outputs => Unsigned_32'Asm_Output ("=g", Var_Out),
Clobber => "ebx");
The Clobber parameter is a static string expression specifying the
register(s) you are using. Note that register names are not prefixed by a percent sign.
Also, if more than one register is used then their names are separated by commas; e.g., "eax, ebx"
The Clobber
parameter has several additional uses:
cc
to indicate that flags might have changed -- I think "cc" maybe is CPSR in ARM, is that correct?memory
if you changed a memory location