Home технология General register

General register



Introduction

General-purpose registers can be used to transfer and temporarily store data, and can also participate in arithmetic and logic operations and save the results of operations. In addition, they each have some special functions. The length of general-purpose registers depends on the word length of the machine. Assembly language programmers must be familiar with the general and special uses of each register. Only in this way can they be used correctly and reasonably in the program.

A total of 8 16-bit CPU general registers: AX, BX, CX, DX, BP, SP, SI, DI.

Eight registers can be used as ordinary data registers .

But some have special purposes: AX is an accumulator, CX is a counter, BX and BP are base address registers, SI and DI are index registers, and BP can also be a base

< p> pointer, SP is the stack pointer.

There are 8 general-purpose registers for 32-bit cpu: EAX, EBX, ECX, EDX, EBP, ESP, ESI, EDI functions are similar to the above

Classification

Data register

The data register is mainly used to save information such as operands and operation results, thereby saving the time required to read the operands and access the memory. 32-bit CPU has four 32-bit general registers EAX, EBX, ECX and EDX. The access to the low 16-bit data will not affect the high 16-bit data. These low 16-bit registers are respectively named: AX, BX, CX and DX, which are consistent with the previous registers in the CPU.

4 16-bit registers can be divided into 8 independent 8-bit registers (AX: AH-AL, BX: BH-BL, CX: CH-CL, DX: DH-DL), each Each register has its own name and can be accessed independently. Programmers can use this "dividable and combinable" feature of data registers to flexibly process word/byte information.

Registers AX and AL are usually called accumulators, and operations with accumulators may take less time. Accumulators can be used for operations such as multiplication, division, and input/output, and they are frequently used; the register BX is called the Base Register. It can be used as a memory pointer; the register CX is called the Count Register. In loop and string operations, use it to control the number of loops; in bit manipulation, when shifting multiple bits, use CL to indicate the number of bits to shift; the register DX is called the data register (Data Register). In the multiplication and division operations, it can be used as the default operand to participate in the operation, and can also be used to store the I/O port address.

In a 16-bit CPU, AX, BX, CX, and DX cannot be used as base address and index registers to store the address of the storage unit, but in a 32-bit CPU, its 32-bit registers EAX, EBX, ECX and EDX can not only transmit data and temporarily store data to save the results of arithmetic and logic operations, but also can be used as pointer registers. Therefore, these 32-bit registers are more versatile. For details, see section 3.8-32-bit address addressing mode.

Index register

A 32-bit CPU has two 32-bit general-purpose registers ESI and EDI. The lower 16 bits correspond to the SI and DI in the previous CPU. The access to the lower 16 bits of data does not affect the upper 16 bits of data.

The registers ESI, EDI, SI, and DI are called Index Registers. They are mainly used to store the offset of the storage unit in the segment. They can be used to implement a variety of memory operands The addressing mode (described in detail in Chapter 3) provides convenience for accessing storage units in different address forms. The index register cannot be divided into 8-bit registers. As a general-purpose register, it can also store the operands and results of arithmetic and logic operations.

They can be used as general memory pointers. In the execution of string manipulation instructions, there are specific requirements for them, and they also have special functions.

Pointer register

32-bit CPU has two 32-bit general-purpose registers EBP and ESP. The lower 16 bits correspond to the SBP and SP in the previous CPU. The access to the lower 16 bits of data does not affect the upper 16 bits of data. The registers EBP, ESP, BP, and SP are called Pointer Registers, which are mainly used to store the offset of the storage unit in the stack. They can be used to achieve a variety of memory operand addressing methods (detailed in Chapter 3) Introduction), to provide convenience for accessing storage units in different address forms. The pointer register cannot be divided into 8-bit registers. As a general-purpose register, it can also store the operands and results of arithmetic and logic operations.

Segment register

The segment register is set according to the management mode of memory segmentation. The physical address of the memory unit is composed of the value of the segment register and an offset, so that two values ​​with a smaller number of bits can be combined to form a memory address that can access a larger physical space.

Instruction Pointer Register

The 32-bit CPU expands the instruction pointer to 32 bits and marks it as EIP. The lower 16 bits of EIP have the same function as the IP in the previous CPU. The instruction pointers EIP and IP (Instruction Pointer) store the offset of the instruction to be executed next time in the code segment. In a system with a prefetch instruction function, the instruction to be executed next time is usually prefetched into the instruction queue, unless a branch occurs. Therefore, when understanding their functions, do not consider the existence of instruction queues. In the real mode, since the maximum range of each segment is 64K, the upper 16 bits of EIP must be 0. At this time, it is equivalent to only using the lower 16 bits of IP to reflect the order of execution of instructions in the program.

Main purpose

General register data

Register AX multiplication and division operations, word input and output, intermediate result buffering

AL Multiplication and division of bytes, input and output of bytes, decimal arithmetic operations

Multiplication and division of AH bytes, storage of interrupted function numbers

BX memory pointer

p>

CX string operation, loop control counter

CL shift operation counter

DX word multiplication and division operations, indirect input and output

< p>Index

Register SI memory pointer, source operand pointer in string instructions

DI memory pointer, destination operand pointer in string instructions

Index register BP memory pointer, pointer to access stack

Top pointer of SP stack

Instruction pointer IP/EIP

Flag/EFlag

32-bit

CPU's

Segment register 16-bit CPU

Segment register ES Additional segment register

CS Code Segment Register

SS Stack Segment Register

DS Data Segment Register

Newly Added

Segment Register FS Additional Segment Register

GS additional segment register

Related information

Register is an important data storage resource inside the CPU. It is used to temporarily store data and addresses. It can be used by assembly programmers. One of the hardware resources used directly. Because the access speed of the register is faster than that of the memory, when writing a program in assembly language, it is necessary to make full use of the storage function of the register as much as possible. Registers are generally used to store the intermediate results of the program, and quickly provide operands for subsequent instructions, so as to avoid the operation of storing the intermediate results in the memory and then reading the memory. In high-level languages ​​(such as: C/C++ language), there are also definitions of variables as register types. This is a feasible way to improve register utilization.

In addition, due to the limited number and capacity of registers, it is impossible to store all intermediate results in the registers. Therefore, the registers must be properly scheduled. According to the requirements of instructions, how to arrange appropriate registers to avoid transfer operations with too many operands is a meticulous and thorough work.

This article is from the network, does not represent the position of this station. Please indicate the origin of reprint
TOP