Sparc 过程调用约定

发布于 2024-09-09 06:10:19 字数 442 浏览 2 评论 0原文

我想在 Sparc 中进行一些“内联”汇编编程,我想知道如何通过寄存器传递来做到这一点。

最好用一个小例子来解释我的问题

int main()
{
   int a = 5;
   int b = 6;
   int res;

   asm_addition(a,b);

   printf("Result: %d\n", res);
   return(0);
}
  // My assembler addition

.global asm_addition            

.align  4   

    add rs1, rs2, rd
    restore

有谁知道我必须使用哪些寄存器才能添加值 a 和 b ?最后,我需要为 rd 指定哪个寄存器,以便将结果与汇编例程后面的最后一个 printf 语句一起打印。

非常感谢您的一些意见!

I would like to do some "inline" assemly programming in Sparc and I am wondering how I can do that with register passing.

Best to explain my issue with a small example

int main()
{
   int a = 5;
   int b = 6;
   int res;

   asm_addition(a,b);

   printf("Result: %d\n", res);
   return(0);
}
  // My assembler addition

.global asm_addition            

.align  4   

    add rs1, rs2, rd
    restore

Does anyone know which registers I have to use so that the values a and b will be added? Finally, which register do I need to speficy for rd so that the result will then be printed put with the last printf statement following the assemly routine.

Thanks so much for some input!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最舍不得你 2024-09-16 06:10:19

调用约定可能取决于操作系统。我认为是索拉里斯。谷歌system v application binary interface sparc,很容易找到PDF。

完整的内联汇编器文档隐藏在 SunStudio PDF 中的某个位置,不太容易找到。官方也可以通过 man -s 1 inline 访问它,尽管在我的系统上我必须手动打开该文件。在手册页中,查找“SPARC 系统的编码约定”。

The calling convention might depend on OS. I presume Solaris. Google for system v application binary interface sparc, the PDF is easy to find.

Full inline assembler documentation is buried somewhere in the SunStudio PDFs and not so easy to find. Officially it is also accessible via man -s 1 inline, though on my system I have to open the file manually. In the man page, look for "Coding Conventions for SPARC Systems".

时光清浅 2024-09-16 06:10:19

在 Solaris 上,参数通过寄存器 %o0 传递到 %o5,然后通过堆栈传递。如果被调用的函数是叶函数(即它不调用另一个函数),则寄存器窗口不会向前移动,并且函数直接通过%o0到%o5访问它们。如果寄存器窗口移动,则函数可以通过%i0 至%i5 寄存器访问参数。返回值以相同的方式通过被调用者中的 %i0 变为调用者中的 %o0。
对于浮点参数,它们是通过 FP 寄存器处理的,但您必须阅读 Dummy00001 指向的文档。

On Solaris the parameter are passed via register %o0 to %o5 then over the stack. If the called function is a leaf function (i.e. it doesn't call another function) the register window is not moved forward and the function accesses them directly via %o0 to %o5. If the register window is moved, then the function can access the parameters via the %i0 to %i5 registers. The return value goes the same way via %i0 in the callee which becomes %o0 in the caller.
For floating point parameter they are handled via the FP registers but there you will have to read the document Dummy00001 pointed to.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文