在全局函数中使用sparc扩展asm(Use sparc extended asm in global function)

编程入门 行业动态 更新时间:2024-10-17 23:28:41
全局函数中使用sparc扩展asm(Use sparc extended asm in global function)

我试图在不使用c原型的情况下编写汇编函数。 由于某种原因,它看起来像gcc不允许在全局上下文中使用扩展的asm。

请考虑以下编译succssefully的代码:

void *g_var; void foo() { asm ("stx %%i7, [%0]" :"=r" (g_var)); }

当我也尝试使用asm定义原型时,如下所示:

asm(".global foo2\n\t" "foo2:\n\t"); asm ("stx %%i7, [%0]" :"=r" (g_var));

编译器给我以下错误,好像扩展的asm不能在全局上下文中使用。

foo.c:151:2:错误:预期')'在':'之前:'= r“(return_addr)); ^

请注意,当我不按如下方式使用扩展的asm时,编译器会批准代码:

asm(".global foo2\n\t" "foo2:\n\t"); asm("jmpl %o7 + 8, %g0\n\t");

谢谢。

I am trying to write an assembly function without using c prototypes. For some reason it looks like the gcc doesn't allow to use extended asm in the global context.

Please consider the following code that compiles succssefully:

void *g_var; void foo() { asm ("stx %%i7, [%0]" :"=r" (g_var)); }

When I am also trying to define the prototype using asm, as follows:

asm(".global foo2\n\t" "foo2:\n\t"); asm ("stx %%i7, [%0]" :"=r" (g_var));

the compiler give me the following error as if extended asm cannot be used in global context.

foo.c:151:2: error: expected ')' before ':' token :"=r" (return_addr)); ^

Please note that when I don't use extened asm as follows, the compiler approves the code:

asm(".global foo2\n\t" "foo2:\n\t"); asm("jmpl %o7 + 8, %g0\n\t");

Thanks.

最满意答案

来自海湾合作委员会文件 :

请注意, 扩展的asm语句必须位于函数内 。 只有基本asm可能是外部函数(参见Basic Asm )。 使用naked属性声明的函数也需要基本的asm(请参阅函数属性 )。

因此,您的问题的答案是 - 不可能在全局上下文中的函数外部使用扩展的汇编程序模板。 正如您所发现的那样,允许使用基本的汇编语句。

From the GCC Documentation:

Note that extended asm statements must be inside a function. Only basic asm may be outside functions (see Basic Asm). Functions declared with the naked attribute also require basic asm (see Function Attributes).

So the answer to your question is that - no it isn't possible to use extended assembler templates outside a function in the global context. As you have found basic assembler statements are allowed.

更多推荐

本文发布于:2023-07-06 07:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047394.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:全局   函数   sparc   asm   global

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!