This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

why tow local variables take the same register?


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]