Register

honggarae 01/11/2021 1137

Basic meaning

Registers are some small storage areas used to store data inside the CPU. They are used to temporarily store the data involved in operations and the results of operations. In fact, a register is a commonly used sequential logic circuit, but this sequential logic circuit only contains a storage circuit. The storage circuit of the register is composed of latches or flip-flops. Because a latch or flip-flop can store a 1-bit binary number, N latches or flip-flops can form an N-bit register. The register is an integral part of the central processing unit. Registers are high-speed storage components with limited storage capacity. They can be used to temporarily store instructions, data, and addresses.

In the computer field, registers are internal components of the CPU, including general-purpose registers, special-purpose registers, and control registers. Registers have very high read and write speeds, so data transfer between registers is very fast.

Cortex-M4 has a total of 18 registers. Compared with the 38 registers of traditional ARM (such as ARM7/ARM9/Cortex-A series), it has been reduced a lot, reducing the core area (Die-size).

It is very friendly and easy to use for the compiler. For example, it includes flexible register configuration, single-cycle multiplication can be realized between any registers, and any register can be used as a pointer to data, structure or array. In addition, Cortex-M4 also contains 4 special function registers PRIMASK and FAUI. TMASK, BASEPRI and CONTROL.

Basic concepts

The register has at least the following 4 functions.

①Clear digital: clear the original digital in the register.

②Receive digital: under the action of receiving pulse, store the external input digital in the register.

③Store the number: Before a new write pulse comes, the register can save the original number unchanged.

④Output digital: digital output through the circuit only under the action of output pulse.

Registers with only the above functions are called digital registers; some registers also have shift functions, called shift registers.

The control register of PORT1 (2 photos)

The register has two digital access methods: serial and parallel. The method of storing or reading out the n-bit binary number into the register at a time is called the parallel method. Divide the n-bit binary number into the register and read it from the register in n times with 1 bit at a time. This method is called serial mode. The parallel mode only needs one clock pulse to complete the data operation, and the working speed is fast, but it needs n input and output data lines. The serial mode needs to use several clock pulses to complete the input or output operation, the working speed is slow, but only one input or output data line is needed, and there are few transmission lines, which is suitable for long-distance transmission.

Structure

In digital circuits, the circuits used to store binary data or codes are called registers. The register is composed of a combination of flip-flops with storage function. A flip-flop can store a 1-bit binary code, and the register that stores the binary code of the gate bit needs to be constructed by flip-flops one by one.

For the flip-flops in the register, they only need to have the function of setting 1 and setting 0. Therefore, whether it is a level-triggered trigger, or a pulse-triggered or edge-triggered trigger, both Can be composed of registers.

From the characteristics of level-triggered action, we can see that during the high level of CLK, the state of the Q terminal changes with the change of the state of the D terminal; after CLK becomes low, the Q terminal will keep CLK becoming The state of the D terminal at the time of low level.

74HC175 is a 4-bit register composed of CMOS edge flip-flops. According to the action characteristics of edge-triggered, the state of the flip-flop output terminal only depends on the state of the D terminal when the rising edge of CLK arrives. It can be seen that although 74LS75 and 74HC175 are 4-bit registers, they have different action characteristics due to the use of different structure types of flip-flops.

In order to increase the flexibility of use, some control circuits are added to some register circuits, so that the registers have added functions such as asynchronous zeroing, output tri-state control, and holding. The hold mentioned here means that when the CLK signal arrives, the flip-flop does not change state with the input signal of the D terminal, and keeps the original state unchanged.

In the two register circuits introduced above, all the codes of each bit are input at the same time when receiving data, and the data in the flip-flop appear in parallel at the output end, so this input and output method It is called parallel input and parallel output mode.

Basic register logic diagram (2 sheets)

Type

1. General register set

General The register group includes 4 16-bit registers AX, BX, CX, and DX to store 16-bit data or addresses. It can also be used as an 8-bit register. When used as 8-bit registers, they are marked as AH, AL, BH, BL, CH, CL, DH, DL. Only 8 bits of data can be stored, not addresses. They are the high eight bits and low eight bits of AX, BX, CX, and DX. If AX=1234H, then AH=12H and AL=34H. General-purpose registers are highly versatile, and they have the same function for any instruction. In order to shorten the length of the instruction code, in the 8086, some general-purpose registers are used for special purposes. For example, the CX register must be used as a counting register in the string instruction to store the length of the string, so that the register number of CX does not have to be given in the string operation instruction, which shortens the length of the string operation instruction code. The following are introduced one by one:

AX (AH, AL): accumulator. Some instructions agree to use AX (or AL) as the source or destination register. The input/output instructions must be implemented through AX or AL. For example, the instruction to read the contents of the port address of 43H into the CPU is INAL, 43H or INAX, 43H. The destination operand can only be AL/AX, but not other registers.

BX (BH, BL): Base address register. BX can be used as indirect addressing address register and base address register, BH, BL can be used as 8-bit general-purpose data registers.

CX (CH, CL): counting register. CX acts as a counter in loop and string operations. The content of CX is automatically modified after the instruction is executed, so it is called a counting register.

DX (DH, DL): Data register. In addition to being used as a general register, it can be used as a port address register in I/O instructions, and as an auxiliary accumulator in multiply and divide instructions.

2. Pointer and index register

BP (Base Pointer regilter): Base Pointer register.

SP (Stack Pointer Register): Stack Pointer Register.

SI (Source Index register): source index register.

DI (Destination Index Register): Destination Index Register.

The content of this group of registers is the address offset in a certain segment, which is used to form the operand address, which is mainly used in stack operations and index operations. The BP and SP registers are called pointer registers and are used in conjunction with SS to provide convenience for accessing the current stack segment. Usually the BP register is used in indirect addressing, and the operand is in the stack segment. The operand address is formed by the combination of the SS segment register and BP, that is, the offset of the "base address" of a data area in the current stack segment is stored in BP, so Call the BP register the base pointer.

SP register is used in stack operation. PUSH and POP instructions get the in-segment address offset of the current stack segment from the SP register, so the SP register is called the stack pointer, and SP always points to the top of the stack.

Registers SI and DI are called index registers, and they are usually used together with DS to provide an address offset within the segment for accessing the current data segment. In the string instruction, the offset of the source operand is stored in SI, and the offset of the destination operand is stored in DI. The roles of SI and DI cannot be interchanged, otherwise the transfer address is reversed. In the string instruction, SI and DI are implicit addressing. At this time, SI and DS are used together, and Dl and ES are used together.

3. Segment register

8086/8088CPU can directly address 1MB of memory space, direct addressing requires 20-bit address code, and all internal registers are 16-bit, only It can directly address 6KB, so it uses segmentation technology to solve it. Divide the 1MB storage space into several logical segments, each with a maximum length of 64KB, and these logical segments can float in the entire storage space.

8086/8088CPU sets up 4 16-bit segment registers inside, they are code segment register CS, data segment register DS, stack segment register SS, additional segment register ES, which give the corresponding logic segment The first address is called the "segment base address". The segment base address and the offset address within the segment are combined to form a 20-bit physical address. The offset address within the segment can be stored in a register or in a memory.

For example: the code segment register CS stores the base address of the current code segment, and the IP instruction pointer register stores the offset address within the segment of the next instruction to be executed, where CS=2000H and IP=001AH. Through the combination, the addressing address forming the 20-bit memory cell is 2001AH.

The executable instruction code is stored in the code segment, and the operation data is stored in the data segment and the additional segment. Usually the operand is in the current data segment, and in the string instruction, the destination operand must be in the current Additional paragraph. The stack segment is opened up as a stack area used in program execution, and it is accessed in a first-in-last-out manner. Each segment register indicates a prescribed current segment, and each segment register cannot be used interchangeably. When the program is small, the code segment, data segment, and stack segment can be placed in one segment, that is, contained within 64KB. When the program or data volume exceeds 64KB, then multiple code segments or data segments can be defined , Stack segment, additional segment. The current segment is specified by the segment register, and the content of the segment register can be modified during use to point to other segments. Sometimes, for the sake of clarity, the prefix of segment overrun can be added before the instruction to specify the segment of the operand.

4. Instruction pointer register IP

A 16-bit instruction pointer register IP is set in the 8086/8088CPU to store the offset of the next instruction to be executed in the current code segment Move address. When the program is running, it is automatically modified by the BIU so that the IP always points to the address of the next instruction to be executed, so it is used to control the execution flow of the instruction sequence and is an important register. The 8086 program cannot directly access the IP, but the content of the IP can be modified through certain instructions. For example, when encountering an interrupt instruction or calling a subroutine instruction, the 8086 automatically adjusts the content of the IP, and pushes the address offset of the next instruction to be executed in the IP into the stack for protection. When the interrupt program is executed or the subroutine returns, it can be Pop the protected content from the stack to the IP, so that the main program continues to run. In the case of a jump instruction, the new jump target address is sent to the IP, its content is changed, and the transfer of the program is realized.

5. Flag register FR

The flag register FR is also called the program status word register.

Register (2 photos)

FR is a 16-bit register, of which there are 9 valid bits used to store status flags and control flags. There are 6 status flags, CF, PF, AF, ZF, SF, and OF, which are used to register the status information of program operation. These flags are often used as the basis for subsequent instruction judgment. The control flag has 3 bits, IF, DF and TF, which are used to control the operation of the CPU and are artificially set.

Working principle

In computers and other computing systems, registers are a very important and indispensable digital circuit critical component, which is usually composed of flip-flops (D flip-flops). The function is to temporarily store numbers or instructions. A flip-flop can store a binary code. If you want to store an N-bit binary code, you need N flip-flops.

The register should have the functions of receiving data, storing data and outputting data. It is composed of flip-flops and gate circuits. The register can receive data only when it gets the "stored pulse" (also called "stored command" or "write command"); when it gets the "read out" command, the register can output data.

There are two ways to store numbers in registers: parallel and serial. Parallel mode is that the number is input into the register from each corresponding bit input terminal at the same time; the serial mode is that the number is input into the register bit by bit from one input terminal.

There are also parallel and serial ways to read out numbers from registers. In the parallel mode, the read-out digits appear on the output terminals of each position at the same time; in the serial mode, the read-out digits appear on an output terminal bit by bit.

Register (3 sheets)

The storage code meets the conditions

(1) The code must be saved;

(2) The code must be remembered;

(3) The code must be obtained.

The register is composed of a combination of flip-flops with storage functions. A flip-flop can store a 1-digit binary code, and a register that stores n-digit binary codes requires n flip-flops to form. The flip-flop in the register is only required to have the function of setting 1, and setting 0, so no matter what type of flip-flop is used, it can form a register.

According to different functions, registers can be divided into two categories: basic registers and shift registers. Basic registers can only send data in parallel, and can only output in parallel when needed. The data in the shift register can be shifted right or left bit by bit under the action of the shift pulse. The data can be input in parallel, output in parallel, serial input, serial output, parallel input, serial output, or Serial input and parallel output are very flexible and have a wide range of uses.

Register organization

The ARM microprocessor has 37 32-bit registers, 31 of which are general-purpose registers and 6 are status registers. However, these registers cannot be accessed at the same time. Which registers are programmable to access depends on the working status of the microprocessor and the specific operating mode. But at any time, general registers R14~R0, program counter PC, one or two status registers are all accessible.

The ARM9 processor has 37 32-bit long registers. These registers include:

(1) RO~R12: All are 32-bit general-purpose registers, used for data manipulation. But note: Most 16-bit Thumb instructions can only access R0~R7, while 32-bit Thumb-2 instructions can access all registers.

(2) Stack pointer: The lowest two bits of the stack pointer are always O, which means that the stack is always aligned with 4 bytes.

(3) Link register: When calling a subroutine, R14 stores the return address.

(4) Program counter: points to the current program address, if you modify its value, you can change the execution flow of the program.

(5) Six status registers (1 CPSR, 5 SPSR), used to identify the working status of the CPU and the running status of the program, are 32 bits, and only a part of them are currently used.

Cortex-A8 processor has 40 32-bit long registers, more registers in monitor mode, such as RO~R12, R15, CPSR general, R13_mon, R14_mon, SPSR_mon three special registers.

Register addressing

Register addressing is to use the value in the register as the operand. This addressing method is often used by various types of microprocessors. An addressing method with higher execution efficiency.

Register addressing means that the operand is stored in a register inside the CPU, and the name of the register where the operand is located is given in the instruction. Register operands can be 8-bit registers AH, AL, BH, BL, CH, CL, DH, DL, or 16-bit registers AX, BX, CX, DX, SP, BP, SI, DI, etc. Because register addressing does not require access to memory through bus operations, the instruction execution speed is relatively fast.

Register Addressing is an addressing mode in which the contents of general registers are used as operands. In this addressing mode, the operands are stored in registers. The addressing objects of register addressing mode are: A, B, DPTR, RO~R7. Among them, B is only register addressing in multiplication and division instructions, and direct addressing in other instructions. A can be addressed by register or directly, and it is written as ACC for direct addressing.

Latest: Control register

Next: Sample Holder