开发者

LLVM complains about assembler error "Unexpected token in memory operand"

I'm doing a study assignment to measure memory access time on my machine. To determine the clock cycles on our machines, we have been given the following C snippet:

static inline void getcyclecount(uint64_t* cycles)
{
    __asm __volatile(
                     "cpuid            # force all previous instruction to complete\n\t"
                     "rdtsc            # TSC ->  edx:eax \n\t"
                     "movl %%edx, 4(0) # store edx\n\t"
                     "movl %%eax, 0(0) # store eax\n\t"
                     : : "r"(cycles) : "eax", "ebx", "e开发者_如何学运维cx", "edx");
}

However, when I try to compile this (XCode 4, using "Apple LLVM Compiler 2.1"), it results twice in the error "Unexpected token in memory operand" at the "\t" of the rdtsc resp. first movl instruction line.

I know basic assembler, but have no clue about the C inline assembler format.

Does anyone of you know what could be the issue with this code?

Thanks!


Assuming this is GCC inline assembly syntax, you're missing a % in the memory operand:

__asm __volatile(
                 "cpuid            # force all previous instruction to complete\n\t"
                 "rdtsc            # TSC ->  edx:eax \n\t"
                 "movl %%edx, 4(%0) # store edx\n\t"
                 "movl %%eax, 0(%0) # store eax\n\t"
                 : : "r"(cycles) : "eax", "ebx", "ecx", "edx");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜