LR SP PC

LR SP PC

ARM-depth understanding of these three registers, there is a great benefit to programming and operating system migration.

    1, the stack pointer r13 (SP): Each exception mode has its own independent R13, it is usually dedicated point exception mode stack, that is to say five kinds of abnormal patterns, non abnormal pattern (user mode and the system mode) , has separate stack, the stack pointer with different indexed. ARM so that when the exception mode, the program can be as general purpose registers onto the stack, then the return stack, ensure the integrity of the program state in various modes.

    2, connected to the register r14 (LR): r14 each group has its own version of the model, it has two special features.

    (1) save the subroutine return address. When using a BL or BLX,, automatically jump instruction in the return address in r14; r14 subroutine by copying to the PC returned is achieved, usually one of the following instruction:
                        MOV PC, the LR 
                        BX the LR

    Usually a subroutine written to ensure that the subroutine can also call subroutines.
                         LR !, {SP} STMFD
                         ......
                         LDMFD SP !, {PC}

    (2) When an exception occurs, the exception mode to save r14 abnormal return address, the stack can be handled as r14 nested interrupts.

    3, the program counter r15 (PC): PC to read and write is limited. When the reading does not exceed the time limit, the value read is the address of the instruction plus 8 bytes, always due to the ARM instruction word aligned, so that bit [1: 0] is always 00. Str when using a PC or storage stm, there may be other offset value, 8 or 12. In V3 and below, the write bit [1: 0] values ​​will be ignored and the write bit r15 in V4 and above [1: 0] must be 00, otherwise the consequences unpredictable.

 

    Having a stack is a "last in first out" storage structure (LIFO --- Last In First Out) special access attribute. Physical resource stack RAM is generally used as the bank, together with the access interface LIFO.

                                    


    Implementation stack:
    the random access memory area as a division showing a stack area, data may be stored in a sequential manner (press-fitted) into this region, this process is called 'push' (push). Once a typically implemented using a pointer adjustment (stack pointer SP --- Stack Pointer), SP always points to the data unit (stack) is pushed on the stack last data resides. When reading data from the stack, the stack pointer stack according unit reads the data stack, a process called 'pop' (POP), a pop up each data, SP namely to make an adjustment in the opposite direction, so to achieve a LIFO out of principle.

    The stack is widely used in computer technology, and out of the LIFO stack having a characteristic based on data stored interrupt break often used to save the subroutine call return point, the Save CPU data field is also used to pass parameters between programs.
    ARM processor typically register R13 as the stack pointer (SP). ARM processors for different modes, a total of six stack pointer (SP), wherein the user mode and a shared mode the SP system, each has its own dedicated abnormal pattern R13 register (SP). They typically points corresponding to each mode dedicated stack, i.e. ARM processor allows the user to program has six different stack space. These were the stack pointer R13, R13_svc, R13_abt, R13_und, R13_irq, R13_fiq, the stack pointer register as shown in Table 2-3. 

    In order to more accurately describe the stack, according to "push" operation of increasing or decreasing direction of the stack pointer, the stack is divided into 'increment stack' (SP direction is changed to a large value) and 'decrements the stack "(small change in the value of SP direction) ; and a storage unit according to whether the SP contains a pointer to the data stack, the stack area in turn is divided into 'a full stack' (SP points to a stack unit contains valid data), and "empty stack" (SP points to the stack unit does not contain valid data).
    There are four such combinations of two stack mode - full increment, increment empty, full and empty diminishing diminishing.
     Stack operations ARM processor has great flexibility, these four types of stacks are supported.
    R13 ARM processor is used as the SP. When not in use the stack, R13 can also be used as general purpose data registers.

Guess you like

Origin www.cnblogs.com/jack-hzm/p/10963793.html