why tow local variables take the same register?

Parmenides mobile.parmenides@gmail.com
Fri Dec 31 08:23:00 GMT 2010


Hi,

In a the following function, the inline assembly delcares that both
'input' and 'output' use registers.

void tst(void)
{
     int input = 3, output = 5;
     asm volatile(
          "addl %1, %0\n\t"
          : "=r" (output)
          : "r" (input)
          );
}

But, it seems that the logic is wrong in its corresponding assembly code:

        movl    $3, -8(%ebp)
        movl    $5, -4(%ebp)
        movl    -8(%ebp), %eax   # eax is allocated for 'input'
#APP
        addl %eax, %eax

#NO_APP
        movl    %eax, -4(%ebp)   #eax is allocated for 'output'

Obviously, the gcc has allocated the same eax for both 'input' and
'output'. Althrough it is can be resolved by including 'output' in the
input list within the inline assembly, I wonder what is the strategy
taken by gcc to allocate registers in this kind of situation.



More information about the Gcc-help mailing list