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 |1 Answer
Reset to default 6The 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.
int
oruint64_t
when you compileint foo(){ return 1 };
And/or where a caller looks for the return value, likereturn foo() + 1;
. godbolt. is useful for that. – Peter Cordes Commented Feb 15 at 21:47