80386ASM programming foundation (2)

zhaozj2021-02-16  47

80386 processor addressing method

In the form of form, the maximum addressing space of the 80386 processor is still 1M, and 8086/8088 is similar. That is, the offset address in the 10h segment is formed to form a 20-bit address. In this mode, the segment base is a multiple of 16, and the length is up to 64K.

In protection mode, the 80386 processor can use all physical memory. The segment base can be 32 bits, or may not be 16 times, and its maximum length is 4G, which is completely different from 8086, and uses the segment base address directly to the block at the end of the segment, but not Segment base address is left 4 bits (multiplied by 16). Normally, in addition to accessing the stack, the default segment is DS, and there is a cross-bouquet prefix. When using BP, EBP, ESP as a base register, the default segment register should be SS, and a few simple examples:

MOV EAX, [Si]; section registers here are DS

MOV EAX, FS: [ESI]; the segment register here is FS because the command is displayed in the instruction.

MOV EAX, [BP]; the segment register here is SS because BP is used as the base register in the instruction.

MOV EAX, GS: [BP]; Here section register is GS because the cross-segment prefix is ​​displayed in the instruction.

The order of the 32-digit operation in 80386 is "high and low", ie, high 16- "high 16, high 8-" high 8, low 16- "low 16, low 8-" low 8, this and 8086 similar. At the same time, 80386 microprocessor is compatible with all 8086 addressing methods, and there is a big improvement and extension of the 8086 addressing mode. Under 8086, only BP, BX, Si, DI is allowed to be a address register, but under 80386, 8 universal registers can be used as a address register. However, it should be noted that in the base address register addressing method or relative base address address address, the segment register is determined by the base register, rather than being determined by the index register, while other ESPs The seven general registers can be used as an index register, with code is:

MOV EAX, [EBP ESP 2]; this instruction is wrong, because it is not possible to use ESP as an index register

MOV EAX, [EBP ESI 10h]; segment registers here should have a base register to determine. The base register is BP, then the paragraphs here are SS

MOV EAX, GS: [EBP EDI 100H]; don't look, the segment register here should be GS because the instruction is displayed by the cross-block prefix.

80386 Supported base site transmissive addressing further satisfies the data type supported by advanced languages. For C language, ordinary variables, arrays, structures, structural arrays, arrays of arrays we can store both in the stack (static definition -static definition), or in the heap (Dynamic Definition - Dynamic Definition ), Can be implemented using ASM. The base address register provides two parts that can be changed, and the displacement is static. Look at the example below:

// Variables in C Programming-Language, The Corresponding ASM WILL LIST BELOW

void main ()

{

INT A; // Normal variable, use the ASM addressing DS: [one shift], such as DS: [2000], belongs to the direct addressing method

INT Array [24]; // array, use DS: [BX Si * 4], 4 to represent the length of the integer, belonging to the base address Addressing with the ASM addressing

Struct ABC

{

INT A, B, C;

Float D;

}

Struct ABC AA; // Structural, DS: [BX Shift], Shift represents the relative addressing method of the register when adding by ASM addressing, and SHIFT

Struct ABC AA [100]; // Structural array, using DS: [BX Si * SizeOf (ABC) Shift] with ASM Addressing, belongs to the relative base address address address

Struct CDE

{

Int arch [100];

Float E, F, G;

}

Struct CDE CCC; // A array structure, use DS: [BX Si * 4 Shift] with ASM, belongs to the relative base address address address

}

80386 is almost exactly the same as 8086, but only 80386 is more flexible, its operands have 32, 16, 8 bits.

Let's take a revisit: 8086's addressing method:

a. Immediate addressing, so-called immediate addressing is in the order, such as: Mov AX, 5678H

b. Direct addressing, that is, the effective address of the operands, such as MOV AX, [1234]

c. Register address addressing, with the content of the register as the effective address of the operand, such as Si = 1234, MOV AX, [Si], 8086, available, only 4: BX, BP, Si, Di, 80386 The 8 universal registers can be used.

d. The register is relatively addressed, i.e., on the basis of register address addressing, the displacement amount can be 8 bits or 16 bits, such as MOV AX, [BX 90H].

e. Extracy address address, that is, the effective address of the operand is generated by an entry register and an indeached register, such as MOV AX, [BX Si]. So under 8086, only Si, DI can be used as an index register, other seven general registers other than ESP outside 80386 can be used as an index register, such as MOV AX, [BX Si].

f. Relative base address address, add one shift on the basis of the E address, such as MOV AX, [BX Si 100H].

Under 8086, we often add pseudo-instruction Word PTR or Byte Ptr. Do not display the specified in 80386, the processor will automatically process, when the discovery operation is 8 bits, the processor will perform 8-bit operation, which is the same as 16 bits, the processor will do 16-bit operation, 80386 The following simple transfer commands are subject to the length of the target operand.

MOV Al, CS: [EAX]; 8-bit operation, segment register is CS, addressing method is register address addressing

MOV Al, ES: [BX]; 8-bit operation, segment register is ES, addressing method is register address addressing

MOV EDX, [EDX EBX 1234H]; 32-bit operation, segment register is DS, addressing method is a relative base address address

MOV AX, [EBX ESI * 4]; 16-bit operation, segment register is DS, addressing method is based addressing

MOV BH, ES: [EBX EDI 900H]; 8-bit operation, segment register is ES, addressing method is a relative base address address

MOV DL, [EBP ESI 1900H]; 8-bit operation, segment storage is SS because EBP is used as the base register. Addressing method is a relative base address address address

转载请注明原文地址:https://www.9cbs.com/read-27092.html

New Post(0)