Collection
zero Useful+1
zero

Program counter

A register in a computer processor
The program counter is used to store the address of the unit where the next instruction is located.
When executing an instruction, first fetch the instruction from the memory according to the instruction address stored in the PC Instruction register This process is called "fetch instruction". At the same time, the address in PC will automatically add 1 or the transfer pointer will give the address of the next instruction. After that, the instructions are analyzed and executed. Complete the execution of the first instruction, and then fetch the address of the second instruction according to the PC, and execute each instruction in such a loop.
Chinese name
Program counter
Foreign name
Program Counter
Abbreviation in foreign language
PC

brief introduction

Announce
edit
The program counter is a computer processor In register , which contains the address (location) of the instruction currently being executed. When every instructions Is obtained, and the storage address of the program counter is increased by one. After each instruction is acquired, the program counter points to the next instruction in the sequence. When the computer is restarted or reset, the program counter usually returns to [1] Fatal Frame.
One of the main contents of von Neumann computer architecture is "program pre storage, computer automatic execution"! The program (instruction sequence) to be executed by the processor is pre stored in the computer memory in the form of binary code sequence. The processor takes these codes to the processor one by one and then decodes and executes them to complete the execution of the entire program. In order to ensure that the program can be executed continuously, the CPU must have some means to determine the address of the next fetch instruction. The program counter (PC) plays this role, so it is often called 'instruction counter'.
Before the program is executed, the starting address of the program instruction sequence, that is, the address of the memory unit where the first instruction of the program is located, is sent to the PC, and the CPU reads the first instruction (fetching) from the memory according to the instructions of the PC. When executing instructions, the CPU automatically modifies the contents of the PC, that is, every time an instruction is executed, the PC adds a quantity equal to the number of bytes contained in the instruction (instruction bytes), so that the PC always points to the address of the next instruction to be retrieved. Since most instructions are executed in sequence, the process of modifying PC is usually simply to add "instruction bytes" to PC.
When the program is transferred, the final result of the execution of the transfer instruction is to change the PC value, which is the destination address of the transfer. The processor always fetches, decodes and executes according to the PC direction, thus realizing program transfer.
The ARM processor uses R15 as the PC, which always points to the reference unit, and there is only one PC register in the ARM processor, which is shared by all modes. R15 has a 32-bit width (marked R15 [31:0] below, indicating the '31st bit' to '0th bit' of R15), and ARM processor can directly address 4GB address space (2 ^ 32=4G). [2]

characteristic

Announce
edit
In order to guarantee the procedure (in operating system In process )Can be executed continuously, processor There must be some means to determine the address of the next instruction. The program counter plays this role, so it is usually called instruction counter. Before the program is executed, its starting address, that is, the memory where the first instruction of the program is located, must be Unit address It is sent into the program counter, so the content of the program counter is the address of an instruction extracted from memory. When the command is executed, processor The content of PC will be automatically modified, that is, each instruction PC executes will be increased by a quantity equal to the number of bytes contained in the instruction, so that it always keeps the address of the next instruction to be executed. Since most instructions are executed sequentially, the modification process is usually a simple addition of 1 to the PC. [3]
However, when a branch instruction such as JMP (Jump, Full Foreign Name: JUMP) instruction is encountered, the address of the subsequent instruction (that is, the content of PC) must be obtained from the address field in the instruction register. In this case, the next instruction taken out of memory will be specified by the branch instruction instead of being obtained in sequence as usual. Therefore, the structure of the program counter should have two functions: storing information and counting. [3]