PDA

Click to See Complete Forum and Search --> : AT&T inline: local variables


hellisher
Mar 24th, 2008, 05:40 PM
Hello, been looking at tutorial on the web about using local variables with AT&T inline assembly in gcc. And i cant figure it out how to use the output/input/clobber operators..

The code below works fine when declaring the variables as globals. But i would prefer them as local. So if anyone can fix the below code to work with local variable would hopefully help me draw a logical conclusion to get me understand how to use local variable.

Cheers!

unsigned int cpu_info, cpu_sse3, cpu_info_amd;
asm
(
"movl $0x1, %eax\n"
"cpuid\n"
"movl %edx, _cpu_info\n" //test
"movl %ecx, _cpu_sse3\n"
"movl $0x80000001, %eax\n"
"cpuid\n"
"movl %edx, _cpu_info_amd\n"
);

hellisher
Mar 25th, 2008, 10:42 AM
Never mind, manage to solve it. The little thing that stop me before was that all eax, edc, ecx required double %% character, even when i didnīt write to the local variables.


asm
(
"movl $0x1, %%eax\n\t"
"cpuid\n\t"
"movl %%edx, %0\n\t"
"movl %%ecx, %1\n\t"
"movl $0x80000001, %%eax\n\t"
"cpuid\n\t"
"movl %%edx, %2\n\t"
: "=g" (cpu_info), "=g" (cpu_sse3), "=g" (cpu_info_amd)
);

wossname
Mar 26th, 2008, 02:32 PM
As far as I understand, you only need to use %% when you have used at least one of the three ":" lines. Its got something to do with how gcc resolves the register names.

I'm having much trouble with inline AT&T in gcc also.