Basic knowledge based on ARM Cortex-M3 microcontroller (STM32 series) (5) - mixed programming of assembly language and C language

Require

insert image description here

Introduction to ATPCS

insert image description here

Rules for the use of registers in ATPCS

insert image description here
insert image description here
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.
insert image description here

Data stack usage rules

insert image description here
insert image description here
insert image description here

Parameter passing rules

insert image description here
insert image description here
insert image description here

ARM and Thumb mixed programming

working status

insert image description here
insert image description here

Working state switching programming (time to watch, no time to not watch)

1. BX implements state switching

insert image description here

2. BLX implements state switching

insert image description here
insert image description here
insert image description here

3. LDR, LDM and POP instructions to switch the program state

insert image description here
insert image description here

Subject

insert image description here
insert image description here

classroom test questions

1、

insert image description here
Answer:

2、

insert image description here
Analysis:
insert image description here
choose CEDF

3、

insert image description here
Answer: CD

4、

insert image description here
Answer:
BD; C

If you like my article, please remember to make three consecutive, like, follow, and collect. Every like, every follow, and every collection will be the infinite motivation for me to move forward! ! ! ↖(▔▽▔)↗Thanks for your support, the next issue will be more exciting! ! !

Guess you like

Origin blog.csdn.net/qq_44631615/article/details/118701892