(turn) deep understanding of SP, LR, and PC

Source: Internet
Author: User

Website: http://blog.csdn.net/zhou1232006/article/details/6149548

An in-depth understanding of the three registers of arm is of great benefit to both programming and porting of the operating system.

1. Stack pointer R13 (SP): Each anomaly pattern has its own independent R13, which usually points to the stack dedicated to the exception mode, i.e. five exception modes, non-exception modes (user mode and system mode), each with separate stacks, indexed by different stack pointers. When the arm enters the abnormal mode, the program can push the general general register into the stack and return to the stack to ensure the state integrity of the program in various modes.

2, Connection Register R14 (LR): Each mode of R14 has its own version of the group, it has two special functions.

(1) Save the Sub-program return address. When using BL or BLX, the jump instruction automatically puts the return address into the R14; the subroutine returns by copying the R14 to the PC, usually with one of the following instructions:
MOV PC, LR
BX LR

The subroutine is usually written so that the subroutine can also be called.
Stmfd sp!, {LR}
......
Ldmfd sp!, {pc}

(2) When an exception occurs, the R14 of the exception mode is used to hold the exception return address, and the R14 such as the stack can handle nested interrupts.

3, program counter R15 (PC): PC is read and write restrictions. When there is no more than the read limit, the Read value is the address of the instruction plus 8 bytes, because the arm instruction is always word-aligned, so bit[1:0] is always 00. When storing a PC with STR or STM, the offset may be 8 or 12 other values. In V3 and the following versions, the values written to bit[1:0] will be ignored, and bit[1:0 in V4 and later written to R15 must be 00, otherwise the consequences are unpredictable.

(turn) deep understanding of SP, LR, and PC

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.