IAA32 process call register protection rules, iaa32 register

Source: Internet
Author: User

IAA32 process call register protection rules, iaa32 register

Because of the shared nature in the operating system, registers become a type of resource sharing for various processes or processes. When a process call occurs, if the caller needs to use the value in a register, but the content of this register is likely to be modified during the invocation of the caller, therefore, we need to protect the content in the register before the call process is executed, so that there will be no errors. The register protection rules also exist because of the unavailability of the program.


On IA32, a unified register protection rule is implemented. First, let's look at the number of important registers in the computer.

(I will not write the percentage sign in front of the register if I am secretly lazy. O (register _ register) O)

The eax register is used by the caller to store the returned values of some functions.

Edx ecx also belongs to the caller's storage register and belongs to the General Register. It can store data at will without any specific restrictions.

The three registers ebx edi esi belong to the registers saved by the caller. Generally, edi and esi may save parameters of called functions.

I am confused about the next concept: What is the caller's storage register and what is the caller's storage register.

The difference between the two is shown in the following figure.


As shown in the preceding figure, the registers are classified according to the rules. The three registers on the left are saved by the caller, and the three registers on the right are saved by the caller. That is to say, during the process call, if the caller program overwrites the content of the three registers on the left, if the three registers need to use the value before the call process after the process call is completed, someone needs to save the value in the register before the process call occurs, but who will save it? The caller can only store the data. That is to say, the caller does not care about any important data in the data. The caller can use the data if it needs the data, you need to save it in advance. To put it bluntly, the register can be used by any program, but the data storage work in it is owned by the owner. The owner of the three registers on the left is the caller, and the owner of the three registers on the right is the caller.

I think this is correct. If I happen to understand it, I hope you can give it to me.



There are two more important registers:

Esp is the register of the stack top pointer.

Ebp is the base address register


Those who have learned the Assembly will know that during process calling, the program stack is mainly used to support process calling, and the machine will also use the stack to store some parameters. In this way, the data in the above two registers becomes very important in the process call. When calling a process, you must save the data in the old ebp, and initialize the data using commands such as movl ebp esp to initialize the two stack pointers, esp will expand with the call of the process. At the end of the process call, some commands should be executed to restore and clean up the stack. Then we need to execute the following two Commands: mov ebp esppopl ebp. The first command is to clean up, that is, to release the stack space and move the top pointer of the stack to the base pointer, this is because when the call command is executed, the caller will push the address of the next instruction after the call process is completed into the stack. Therefore, after popl restores the old base address, esp moves down to the stack to the address where the next command is executed. In this way, after the call is completed, the recovery and cleaning work will be completed.
What registers are used to pass parameters when C language calls assembler programs?

ABCD is used

The meaning of each register in general-purpose registers

32-bit CPUs contain the following registers:

4 data registers (EAX, EBX, ECX, and EDX) 2 address changes and pointer registers (ESI and EDI) 2 pointer registers (ESP and EBP) 6 segment registers (ES, CS, SS, DS, FS, and GS) 1 Instruction Pointer register (EIP) 1 sign register (EFlags)

1. Data Register data registers are mainly used to save information such as the operands and operation results, thus saving the time required to read the operands to occupy the bus and access memory. The 32-bit CPU has four 32-bit General registers EAX, EBX, ECX, and EDX. Access to low 16-bit data does not affect high 16-bit data. These 16-bit low registers are named AX, BX, CX, and DX respectively, which are consistent with the registers in the previous 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 register has its own name and can be accessed independently. Programmers can flexibly process the word/byte information by taking advantage of the "severable" feature of data registers.

The register EAX is generally called an Accumulator. operations performed with the accumulators may take less time. It can be used for multiplication, division, input/output, and other operations. It is frequently used. The Register EBX is called Base Register ). It can be used as a memory pointer; Register ECX is called Count Register ). During loop and string operations, use it to control the number of loops. during in-place operations, use CL to specify the number of shifts when multiple bits are moved; register EDX is called a Data Register ). During multiplication and division operations, it can be used as the default operand for calculation, or it can be used to store the port address of I/O.

In a 16-bit CPU, AX, BX, CX, and DX cannot be used as the base address and address change register to store the address of the storage unit. In a 32-bit CPU, its 32-bit registers, EAX, EBX, ECX, and EDX, can not only transmit data, temporarily store data to save Arithmetic Logic calculation results, but also serve as a pointer register, these 32-bit registers are more universal.

2. The address change register 32-bit CPU has two 32-bit General registers ESI and EDI. Its Low 16 bits correspond to the SI and DI in the previous CPU, and its access to low 16 bits of data does not affect the high 16 bits of data.

Registers ESI, EDI, SI, and DI are called Index Register. They are mainly used to store the offsets of storage units in segments. They can be used to address multiple memory operands, it is convenient to access the storage unit in different addresses. The address change register cannot be divided into eight-bit registers. As a general-purpose register, you can also store the operands and results of arithmetic logic operations. They can be used as general memory pointers. In the execution of string operation commands, they have specific requirements and special features.

3. The low 16-bit pointer register corresponds to the BP and SP in the previous CPU, and the access to the low 16-bit data does not affect the high 16-bit data. The 32-bit CPU has two 32-bit General registers, EBP and ESP. They are mainly used to access the storage units in the Stack and stipulate that EBP can be used to directly access data in the Stack as the Base Pointer register. ESP is the Stack Pointer) register, which can only access the top of the stack.

Registers EBP, ESP, BP, and SP are known as Pointer Register. They are mainly used to store the offset of storage units in the stack. They can be used to address multiple storage operations, it is convenient to access the storage unit in different addresses. Pointer registers cannot be divided into eight-bit registers. As a general-purpose register, you can also store the operands and results of arithmetic logic operations.

4. segment register

Segment registers are set based on the management mode of memory segments. The physical address of the Memory Unit is composed of the value of the segment register and an offset. In this way, two smaller-digit values can be combined to form an accessible large object ...... remaining full text>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.