Register details, register details
Keywords: processor and register, register classification, PC register, SP register, PC and SP Use Case-function call
1. the processor and register processor (CPU) are
Using registers to run programs and process dataRegisters included by different processors
The quantity and name are different.(Determined by the processor generator vendor), but the Processor register functions are similar.
Changes in the value in the register determine the behavior of the processor.2. Register Classification Based on
Different locationsCategory:
CPU register: Special Command Execution, data operation, variable processing, parameter transfer peripheral register: used to control the behavior and operation mode of peripherals, the configuration of register value needs to be completed according to the chip manual. For example, the microcontroller chip peripherals register
There are no special instructions in the software development process,RegisterIt refersCPU registers
According
Different FunctionsCategory:
General Purpose Register (GPR): used to execute commands, perform integer data, and perform logical operation Floating Point Register (FPR): used to calculate data with decimal points. key registers in the processor
PC register
Real name: Program counter (Program Couner, PC)
Alias 1: Instruction Pointer (IP)
Alias 2: PC pointer
Purpose: store the address of the command to be executed by the CPU, that is, to tell the CPU where the next command is executed in the address space.
Nature:The value in the PC changes every time a command is executed.;The PC always saves the address of the command to be executed by the next CPU.
SP register
Real name: Stack Pointer register (SP)
Purpose: Save the interrupt breakpoint, save the function call return value, and save the CPU field data.
Nature: always pointing to the top of the stack space to implement the LIFO feature
4. Use Cases of PC and SP-function call
Function callIn the process, the PC and SP work together to complete the Cause Analysis:
Prerequisites:
1) prerequisite for normal CPU operation: YesCommands to be executedAndData to be processed by the command
2) Address of the instruction to be executed in PC Storage
3) data to be processed by the stack space storage command
4) when the value of the PC storage changes (that is, the function jump is ),Context informationStored in stack space (in stack)
5) When context information is imported into the stack, the SP storage value is the address value after context information is imported into the stack.
6) BP (Base Pointer) saves the address value before SP changes
Process description:
Status of the stack and code segment before function call:
Status of the stack and code segment after function call:
1) The PC points to the address of function f (n + 1 ).
2) Import PC context information into the stack
3) BP moves to the SP position, SP moves to the top of the stack
After the function is executed (
After return) Status of stack and code segment
1) The context information is output to the stack. The PC obtains the position before the function call.
2) position of SP to BP
3) BP returns the position of the previous BP Based on the context information.