# Trouble converting VC inline ASM to GCC inline ASM

This topic is 5192 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

So I woke up 7 AM this morning after having spent a good part of the night trying to figure out why this returns an error when I try to compile it in DevC++ (using the GCC compiler). The code sample I took it from originally was for VC I believe, watching the syntax.
unsigned long CTimer::GetTicks(void)
{
asm volatile //Taken from AMD SDK
(
"xor %eax, %eax;"
"xor %ebx, %ebx;"
"xor %ecx, %ecx;"
"xor %edx, %edx;"
"cpuid;"
"rdtsc;"
"mov %eax, (_g_Elapsed);"
: //no output registers
: //nothing here either
: "%eax", "%ebx", "%ecx", "%edx"
);
return g_Elapsed;
}


The problem is not the code part. The problem is the fourth part, that is the "clobbed" registers' entry. If I compile without the clobbed registers I don't get any erros (in fact the code works until it is run somewhere where the destruction of EAX, EBX, ECX and EDX doesn't matter). When I try to compile it like the code above I get: "invalid asm', C:\Dev\Rome\Code\Timer Win32.cpp:9, operand number missing after %-letter" This same error repeats itself 9 times additionally. It makes no sense since I think the syntax which I use it quite correct. Thus I have to turn to the forums for help...

##### Share on other sites
Never mind, I just found out what caused the error (though I don't see why). Using the % prefix for the registers is fine until they are added to the clobbered registers' list. If they are, they must be prefixed with a double %%. Example:

unsigned long CTimer::GetTicks(void){    asm volatile //Taken from AMD SDK    (        "xor %%eax, %%eax;"        "xor %%ebx, %%ebx;"        "xor %%ecx, %%ecx;"        "xor %%edx, %%edx;"        "cpuid;"        "rdtsc;"        "mov %%eax, (_g_Elapsed);"        : //no output registers        : //nothing here either        : "%eax", "%ebx", "%ecx", "%edx"    );        return g_Elapsed;}`

1. 1
2. 2
3. 3
Rutin
18
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633659
• Total Posts
3013216
×