最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c - ARM AAPCS Rules - Stack Overflow

programmeradmin3浏览0评论

I have a project in which I first have to write the arm subroutine and then pass it to a C code to be solved on M3 board. Now, my subroutine gets two parameters in R0 and R1. I was wondering based on the AAPCS standard is it okay to save the subroutine result in R2, or should it be saved in R0? ChatGPT says R0 is the correct way, but I'm not sure.

The whole functions works. But it is this dilemma that keeps me wondering

I have a project in which I first have to write the arm subroutine and then pass it to a C code to be solved on M3 board. Now, my subroutine gets two parameters in R0 and R1. I was wondering based on the AAPCS standard is it okay to save the subroutine result in R2, or should it be saved in R0? ChatGPT says R0 is the correct way, but I'm not sure.

The whole functions works. But it is this dilemma that keeps me wondering

Share Improve this question asked Feb 15 at 21:22 GhazalGhazal 191 bronze badge New contributor Ghazal is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 2
  • 7 If you don't trust ChatGPT (and you shouldn't) why not consult the source document which is available in many places on the web. Return values should be placed in R0 and R1. It's not clear to me why you think R2 is appropriate. – Tangentially Perpendicular Commented Feb 15 at 21:33
  • 1 The other thing you can do to check how calling conventions work is look at compiler-generated asm, like where it puts return values for a function returning int or uint64_t when you compile int foo(){ return 1 }; And/or where a caller looks for the return value, like return foo() + 1; . godbolt. is useful for that. – Peter Cordes Commented Feb 15 at 21:47
Add a comment  | 

1 Answer 1

Reset to default 6

The whole point of a standards document is that you can read it and then not have to wonder; you know you're getting an answer from the authoritative source.

The official home of the AAPCS standard is https://github/ARM-software/abi-aa/releases. The file you want is aapcs32.pdf. Return values are explained in section 6.4. There you can see that an integer or pointer result of 4 bytes or less is returned in r0. 64-bit values are returned in r0 and r1. (For floating-point return values, there are some variants of the ABI described in chapter 7, and you'll have to determine which one your compiler is using.)

Reading and working from official specs is an essential skill for any programmer, so if you're learning, this is a great time to develop that skill. It's not as good a habit to become reliant on ChatGPT and its possible hallucinations.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论