The rule that the parameters in the ARM sub-function definition are put into registers. arm registers

Source: Internet
Author: User

The rule that the parameters in the ARM sub-function definition are put into registers. arm registers

There are also many articles and books on the Internet about the rules for inserting parameters in the definition of ARM sub-functions into registers. However, many people do not know much about this basic knowledge. Here we will extract some online introductions, briefly.


For the ARM system, the mix CILS between functions written in different languages follows the ATPCS (ARM-Thumb Procedure Call Standard ), ATPCS mainly defines the parameter transfer rules for function calls and how to return parameters from functions. For details about ATPCS, see section 2.1 of the ADS1.2 Online Books Developer Guide.


Rules for using simple ATPCS registers:


1. The subroutine passes through the Register R0 ~ R3 to pass parameters. The register can be recorded as A0 ~ A3. The called subroutine does not need to recover the register R0 ~ before returning ~ R3 content.
2. In the subroutine, use R4 ~ R11 to save the local variable, then register R4 ~ R11 can be recorded as V1 ~ V8. If V1 ~ is used in the subroutine ~ Some registers of V8, the values of these registers must be saved when the subroutine enters, and the values of these registers must be restored before return. These operations are not required for the registers not used in the subroutine. in the THUMB program, you can only use the register R4 ~ R7 to save local variables.
3. Register R12 is used as the scratch register between subprograms and recorded as an ip address. This usage rule is often found in the connection code segment of subprograms.
4. Register R13 is used as the data stack pointer and recorded as SP. in the subroutine, register R13 cannot be used for other purposes. The value of register SP when it enters the subroutine must be equal to the value when it exits the subroutine.
5. Register R14 is used as the connection register and recorded as lr. It is used to save the return address of the subroutine. If the return address is saved in the subroutine, R14 can be used for other purposes.
6. Register R15 is a program counter and is recorded as a PC. It cannot be used for other purposes.
7. The registers in ATPCS are predefined in the ARM compiler and assembler.


Supplement:

It is recommended that the number of parameters of the ATPCS function be no more than 4. If the number of parameters is less than or equal to 4, the parameter is transmitted by four registers: R0, R1, R2, and R3. If the number of parameters is greater than 4, parts greater than 4 must be passed through the stack


Rules for returning subroutine results
1. If the result is a 32-bit integer, it can be returned through the R0 register.
2. if the result is a 64-bit integer, it can be returned through R0 and R1, and so on.
3. When the result is a floating point number, it can be returned through the floating point operation register f0, d0 or s0.
4. When the result is a composite floating point, you can use the register f0-fN or d0 ~ DN to return.
5. For results with more digits, the call memory is required.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.