This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
why tow local variables take the same register?
- From: Parmenides <mobile dot parmenides at gmail dot com>
- To: Gcc mailing list <gcc-help at gcc dot gnu dot org>
- Date: Fri, 31 Dec 2010 10:53:18 +0800
- Subject: 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.