I am trying to use the following inline assembly in C to read the high word (%edx
) of Time Stamp Counter for time measurement:
unsigned int tsc;
asm volatile ("rdtscp; xchgl %%edx, %%eax" : "=r" (tsc));
Unfortunately, the code crashes. If the xchgl
instruction is removed, or use rdtsc
instruction, there is no problem. For the former, although the code does not crash, I have no way to take out what I want -- the value in %edx
register. I have checked an online document about inline assembly in C but failed to find any clue to return the value in %edx
to the output C variable directly without any additional instructions (if I change xchgl
to movl
, the same crash occurs). With little hope that I missed any syntax or did not understand the document correctly, I come here to ask: is there any way to specify %edx
register to be the output instead of conventional %eax
in inline assembly in C? Thank you.
PS1: I am working in Linux on an intel i386 compatible CPU whose TSC works well to me.
PS2: For some reason I just need the value in %edx
.