gpt4 book ai didi

gcc - 内联程序集标签已定义错误

转载 作者:行者123 更新时间:2023-12-05 08:43:17 27 4
gpt4 key购买 nike

<分区>

我正在尝试编写我的第一个内联 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;
}

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com