Introduction to the three registers of SP, LR, and PC in ARM

insert image description here

Stack pointer R13 (SP)

MSP stack pointer
PSP stack pointer

Link Register R14 (LR)

1". Function call

When using bl or blx to jump to a subroutine, r14 saves the return address, which can be restored at the end of the calling procedure.
When using BL or BLX, the jump instruction automatically puts the return address in r14; the subroutine returns by copying r14 to the PC, usually with one of the following instructions: MOV PC, LR
BX
LR

通常子程序这样写,保证了子程序中还可以调用子程序。
                     stmfd sp!, {lr}
                     ……
                     ldmfd sp!, {pc}

2". Interruption

When an exception occurs, the exception mode-specific physical R14 is set to the address to which the exception mode will return.

1. Interruption arrives

The value in the register will be saved in turn, which is automatically completed by the hardware
insert image description here

2. Call the interrupt handler

3. Interrupt return

insert image description here
Check the value of LR, if LR=0xffff fff1
? ? ? ?
Check the value of LR. If LR=0xffff fff9,
it means that before entering the interrupt, the MSP stack is used, because the value of the register will be saved in sequence before entering the interrupt. All can be found through the MSP pointer R0, R1, R2, R3, R12, LR, Return address, PSR
checks the value of LR. If LR=0xffff fffD,
it means that before entering the interrupt, the PSP stack is used, because the value of the register will be saved in sequence before entering the interrupt. All can be found through the PSP pointer R0, R1, R2, R3, R12, LR, return address, PSR

Program counter R15 (PC)

Guess you like

Origin blog.csdn.net/m0_37187962/article/details/123345689