G
G
Gina Lee2015-10-12 19:47:33
C++ / C#
Gina Lee, 2015-10-12 19:47:33

Why doesn't asm("rdtsc\n":"=a"(start.t32.th), "=d"(start.t32.tl)) work?

Hello! :)
There is such a line of code (I'm trying to measure the clock frequency).

asm("rdtsc\n":"=a"(start.t32.th), "=d"(start.t32.tl));

Studio and GCC don't like the colon. Where did I go wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2015-10-13
@jcmvbkbc

Studio and GCC don't like the colon.

Studio (MSVS) does not seem to understand this format.
And my gcc likes everything, and the code is correct:
$ cat rdtsc.c
void f(unsigned long *low, unsigned long *high)
{
        asm("rdtsc\n":"=a"(*low), "=d"(*high));
}
$ gcc -O2 -S -W -Wall rdtsc.c
$ cat rdtsc.s
        .file   "rdtsc.c"
        .text
        .p2align 4,,15
        .globl  f
        .type   f, @function
f:
.LFB0:
        .cfi_startproc
#APP
# 3 "rdtsc.c" 1
        rdtsc

# 0 "" 2
#NO_APP
        movq    %rax, (%rdi)
        movq    %rdx, (%rsi)
        ret
        .cfi_endproc
.LFE0:
        .size   f, .-f
        .ident  "GCC: (GNU) 4.7.2 20121109 (Red Hat 4.7.2-8)"
        .section        .note.GNU-stack,"",@progbits

In that it did not result in a compiled code and an error message.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question