内联汇编标签已定义错误

时间:2015-07-21 02:07:12

标签: gcc assembly

我正在尝试编写我的第一个内联asm程序,这是一个素数函数。我收到这些错误......

../prime.c:30: Error: symbol `loop_top' is already defined
../prime.c:38: Error: symbol `loop_bot' is already defined
../prime.c:40: Error: symbol `loop_end' is already defined

int inline_prime(long n)
{
    if(n == 2)
        return 1;
    if(n % 2 == 0)
        return 0;
    long sr = sqrt(n);
    long prime = 0;
    __asm__
    (
        "jmp loop_bot \n"
        "movq $3, %%r8 \n"
        "loop_top:\n"

        "movq $0, %[prime] \n"
        "movq %[n], %%rax \n"
        "divq %%r8 \n"
        "test %[prime], %[prime] \n"
        "jz loop_end \n"


        "addq $2, %%r8 \n"
        "cmpq %[sr], %%r8 \n"
        "loop_bot: \n"
        "jle loop_top \n"
        "loop_end: \n"
        : [prime]"=d"(prime)
        : [n]"r"(n), [sr]"r"(sr)
        : "%r8", "%rax"
    );
    return prime;
}

我应该如何定义标签和跳转?

1 个答案:

答案 0 :(得分:6)

使用定义为here的特殊格式字符串%=

例如:

"loop_top_%=:\n"
"jmp loop_top_%=\n"