Assembly language notes 04_80x86 addressing mode (summary of small turtle notes)

Physical address

  • The memory stores information in bytes.
  • Each byte unit has a unique memory address, called the physical address .
  • A word is stored in the memory to occupy two consecutive bytes. When storing, the low byte is stored in the low address, and the high byte is stored in the high address.
  • The address of the word unit is represented by its lower address.
  • When drawing memory, the lower side is the high address, and the upper side is the high address. The bottom of the stack is the high address.
  • Each storage unit has a unique physical address, but it can be composed of different segment addresses and different offset addresses.

Logical address = segment address: offset address logical address = segment address: offset address Logic series to address=Section of the site : the partial shift to address

Physical address = segment address left shifted by four bits + offset address physical address = segment address left shifted by four bits + offset address Was reason to address=Section of the site left shift Si Wei+Partial shift to address

Data-related addressing mode

Immediate addressing

The operands are stored directly in the instruction, and such operands are called immediates .
Operand = immediate operand = immediateOperation for several=Li That number

  • mov ax,3

Note :

  • The immediate addressing mode can only be used in the source operand field.
  • The length of the source operand should be the same as the length of the destination operand.

Register addressing mode

The operand is stored in the register, and the instruction specifies the register number .

  • mov ax,bx

Operand = content in the specified register Operand = content in the specified register Operation for several=It refers to a specified register memory device in the inner container


The above two addressing modes do not involve memory.


The operands of the following various addressing modes are stored in the storage area.

In 80x86, the operand offset address is called the effective address , EA(Effective Address).

The following various addressing modes obtain the effective address of the operand through different ways , and then obtain the operand.
Effective address = base address + index × scale factor + displacement effective address = base address + index \times scale factor + displacementThere are efficient to address=Base address+Change address×Than patients due to sub+Bit shift amount
effective address may have the following four components:

  • Displacement

    (Displacement) is the number stored in the instruction , but it is not an immediate number, but an address.

  • Base address

    (Base) is the content stored in the base register (BP, BX) , usually used to point to the first address of the array or string in the data segment.

  • Index

    (Index) is the content stored in the index register (SI, DI) , usually used to access an element in an array or a character in a string.

  • Scale Factor

    (Scale factor), its value can be 1, 2, 4, 8. (The scale factor is only available for 386 and later models)

    Table 1 The composition of the three components of the effective address in 16-bit addressing
ingredient 16-bit addressing
Displacement 0,8,16th
Base register BX,BP
Index register YES, OF
Table 2 Default segment selection rules
Fetch type Segments and segment registers used Default rule
instruction Code snippet CS Used to fetch instructions
Stack Stack segment SS In and out of the stack, ESP, BP or ESP as the base address register
Local data Data segment DS Except for the destination string of stack and string instructions
Purpose string Additional data segment ES Destination string

Three situations where the use of segment spanning prefixes is prohibited :

  • The destination string of the string processing instruction must use the ES segment
  • The source of PUSH and POP instructions must use the SS segment
  • The instruction must be stored in the CS section

Direct addressing

Effective address = displacement effective address = displacement There are efficient to address=Bit shift amount

  • mov ax,[0]

The displacement can be represented by a symbolic address (variable).

  • mov ax,table
  • mov ax,[table]

The default segment register is DS .

This addressing mode is suitable for handling single variables.

Register indirect addressing mode

Effective address = content of base address register or index register Effective address = content of base address register or index register There are efficient to address=Base address register memory device or variable address register memory device of the content

  • mov ax,[bp]
  • mov ax,[bx]

The effective address is in a register **(BX,BP,SI,DI)**. (AX, CX, DX are not allowed)

The default segment register of BP is SS, and the default segment of the other three registers is DS.

Register relative addressing mode

Also known as direct indexed addressing mode.
Effective address = content of a base address register or index register + displacement effective address = content of a base address register or index register + displacementThere are efficient to address=A th base address register memory device or variable address register memory device of the content+Bit shift amount of
the default case where the same segment register indirect addressing mode.

  • mov ax,count[si]
  • mov ax,[count+si]

Base address indexed addressing mode

Effective address = the contents of a base register + the contents of an index register Effective address = the contents of a base register + the contents of an index register There are efficient to address=A th base address register memory device of the content+A th variable address register memory device of the content

Refer to Table 1 and Table 2 for the default segment situation.

  • mov ax,[bx][di]
  • mov ax,[bp][si]
  • mov ax,[bx+di]

Relative base address indexed addressing mode

Effective address = the content of a base register + the content of an index register + the displacement effective address = the content of a base register + the content of an index register + the displacement There are efficient to address=A th base address register memory device of the content+A th variable address register memory device of the content+Bit shift amount

  • mov ax,mask[bx][si]

Addressing mode related to branch address

This addressing mode is used to determine the branch instruction and CALLthe redirection address of the instruction.

Direct addressing within the segment

Effective address = (IP) + displacement

Commonly used, jmp nextetc. are all this addressing method.

Near transfer :

The displacement size is 16bit, such as jmp near ptr next.

Short transfer :

The displacement is 8bit. For example jmp short next, if you look at other addressing methods related to the transfer address, you will find that there is only shortno ptr.

Indirect addressing

Effective address = register or storage unit content .

The content can use all addressing modes related to data except the immediate addressing mode.

  • jmp bx

  • jmp word ptr[bp+table]

    word ptrThe description is a word , so it is transferred within a segment .

Direct addressing between segments

The steering segment address and offset address are directly provided in the instruction .

  • jmp far ptr next

Inter-segment indirect addressing

Take two consecutive words in the memory to replace the original content in IP and CS to achieve the purpose of transferring between segments.

The storage unit address can be except the immediate data mode and the register mode.

  • jmp dowrd ptr[table+bx]

    dwordThe description is a double word, so it is a transfer between segments .

Guess you like

Origin blog.csdn.net/david2000999/article/details/115231973