Require
Introduction to ATPCS
Rules for the use of registers in ATPCS
When making a subfunction call,When there are parameters in the sub-function, the parameters are passed between the sub-programs through the registers R0, R1, R2, R3. If there are more than 4 parameters, the extra part is passed by the stack, the called subroutine does not need to restore the contents of registers R0~R3 before returning.
In the subroutine,Use registers R4 to R11 to save local variables.If some registers in R4~R11 are used in the subroutine, the values of these registers must be saved when the subroutine is entered, and the values of these registers must be restored before returning; for the registers that are not used in the subroutine, it is not necessary to do these operate. In Thumb programs, usually only registers R4~R7 can be used to save local variables.
Register R12 is used as a scratch register between subroutines (used to save SP, which is used to pop the stack when the function returns), denoted as ip.This rule is often used in linking sections of code between subroutines.
Register R13 is used as a data stack pointer, denoted as sp, and the address of the stack top of the currently used stack is stored in sp. Register R13 cannot be used for other purposes in subroutines.The value of register sp when entering the subroutine and the value when exiting the subroutine must be equal.
Register R14 is called the connection register, denoted as lr. It is used to hold the return address of the subroutine.Register R14 can be used for other purposes if the return address is stored in the subroutine.
Register R15 is the program counter, denoted as pc.It cannot be used for other purposes.
Data stack usage rules
Parameter passing rules
ARM and Thumb mixed programming
working status
Working state switching programming (time to watch, no time to not watch)
1. BX implements state switching
2. BLX implements state switching
3. LDR, LDM and POP instructions to switch the program state
Subject
classroom test questions
1、
Answer:
2、
Analysis:
choose CEDF
3、
Answer: CD
4、
Answer:
BD; C