8086 addressing learning

Source: Internet
Author: User

1. Operations in the instruction

Computer commands are

Operation Code and

The operation code is used to indicate the functions to be completed by the command. The operation code is used to indicate the objects to be processed by the command operation.

The operand types in the command are divided as follows:

  1. Process by command: source and target operations.

  2. The number of operations contained in a command: Zero, single, and double.
  3. Region where the operations are stored: immediate operations, register operations, memory operations, and IO port operations.

Source operand: Provides the operand for command execution. The value remains unchanged after the command is executed.

Destination operand: Provides the operand for the execution of the instruction, and stores the result after the instruction is executed. Therefore, the original value of the destination operand is not retained.

Zero operand: No operand is required in the instruction, or the operand is hidden. Usually some processor control commands.

Single operand: a command only needs one operand. Generally, it is both the source operand and the target operand.

Double operands: The instruction contains two operands: one is the source operand and the other is the destination operand. The addressing methods of the two operands can be different.

Immediate operand: This operand appears in the instruction as part of the instruction code. Only source operations can be performed in commands. The immediate operand can be written as binary (B), decimal (d), and hexadecimal (h ).

Register operand: the Register operand stores the operand in the register, which can be either the source operand or the destination operand.

Memory operand: the memory operand stores the operand in a unit in the memory. In assembly instructions, the address of the storage unit is given in some way. The Logical Address of the storage unit is used in the program. The logical address is composed of the base address and offset of the segment. The base address of a segment is generally provided implicitly or in the format of a segment prefix. The offset is also called a valid address, which is expressed by EA.

IO port operands: these operations are stored in the registers of the input and output ports. According to the addressing method, the port address is given in different forms in the assembly instruction.

2 addressing mode

The addressing method of 8086 is as follows:

Instant data addressing, register addressing, and memory addressing.

Memory addressing also includes:

Direct addressing

Indirect register addressing

Register relative addressing mode

Addressing of base address changes

Addressing method of relative base address change

String operation addressing

Port addressing

//////////////////////////////////////// //////////////////////////////////////// //////

Immediate number addressing: the operand of immediate number addressing is an immediate number, which is directly included in the Code, followed by the operation code and stored in the code segment together with the operation code. The immediate operand can only be used as the source operand. Therefore, when the source operand of a command is an immediate operand, the destination operand must be a register or a memory operand.

The assembly instruction format is as follows:

MoV ax, 2000 h

MoV [BX], 10

Immediate number addressing is mainly used to assign an initial value to a register or storage unit. It is an operation number or an address value.

 

Register addressing: The operands required in the instruction are in a register of the CPU. The access to these operands is completely carried out within the CPU, and the bus cycle is not required, so the execution speed is fast. Register addressing directly writes the register name that stores the operands in the assembly instructions.

The Assembly command format is as follows:

MoV ax, BX

MoV Cl, BL

 

Memory addressing mode: The operands in the instruction are in the memory, and there are multiple addressing modes. The addressing mode is different, and the expression of the valid address (EA) is also different. Memory addressing is to determine the valid address of the operand and the hidden segment base address based on different addressing methods, so as to form a physical address to read and write the storage unit.

 

Direct addressing: The valid address of direct addressing is provided directly in the instruction. The default segment base address is the DS segment register. Enclose a valid address in brackets to express the content of the storage unit.

Valid address = 16-bit displacement

The assembly language format is as follows:

MoV ax, [2010 H]; ax <--- DS: [2010 H] // DS: [2010 H] = DS <4 + 2010 H

MoV [1010 H], Al; DS: [1010 H] <--- al

MoV BX, ES: [3020 H]; BX <--- ES: [3020 H]

 

Indirect addressing of registers: The valid addresses of operands are all in the registers of the CPU. Because the valid address is 16 bits, this addressing method must use 16 bits. 8086 the registers used for indirect addressing are Si, Di, BX, and BP. When Si, Di, and BX are used for indirect addressing, the hidden base address is in DS. When BP is used for indirect addressing, the hidden base address is in SS. You can change this implicit relationship by adding a segment prefix.

In fact, this addressing method stores the offset in the indirect addressing register beforehand. You can access different units by modifying the register content in the program.

Valid address = Bx/BP/si/di content

The assembly language format is as follows:

MoV ax, [BX]; physical address of the source operand = DS <4 + bx

MoV [BP], BL; physical address of the destination operand = SS <4 + bp

MoV Cl, SS: [Si]; physical address of the source operand = SS <4 + Si

 

Register relative addressing: The valid address of the operand is obtained by adding the content of a register specified in the instruction and the displacement (E) of an 8-or 16-bit given in the instruction.

Valid address = Bx/BP/si/di content + 8/16-bit displacement

The relative addressing of registers is in the following format:

E [BX/BP/si/di

], [BX/BP/si/di

] E, [BX/BP/si/di + E

]

The assembly language format is as follows:

MoV ax, 5 [BX]

MoV BL, Val [Si]

MoV 10 H [BP], 10 h

MoV DS: 2 [BP], Al; DS <4 + bp + 2

 

Base Address addressing: The valid address of an operand is the content of a base address register (BX/BP) specified by the instruction plus the content of an address register (Si/di.

Valid address = Bx/BP + Si/di

The address change addressing format is as follows:

[BX/BP

] [Si/di

], [BX/BP + Si/di

]

Note: In one instruction, only one base address register (BX/BP) can appear, and only one base address register (Si/di) can appear. The implicit designation of the segment base address is only related to the base address register. When BX is selected, the segment base address is DS. When BP is selected, the segment base address is ss.

The assembly instruction format is as follows:

MoV ax, [BX] [di]

MoV Al, [BP] [Si]

 

The addressing method is similar to that of the register:

Valid address = Bx/BP + Si/di +

8/16-bit displacement

 

 

String operation addressing: String operation addressing is specifically used for string operation commands. A string refers to a string or a group of data, which is stored in a continuous memory unit. Special string operation commands are used for consecutive data operations on string addresses. The address change register Si and Di are implicitly used for addressing.

Use Si as the source string address pointer to store the offset of the source data string address. The base segment address is hidden in DS.

Use di as the source string address pointer to store the offset of the source data string address. The base segment address is hidden in Es.

The string operation command can automatically modify the content of Si and Di in the address change register during execution to make it the next data address in the data string. Whether the address is modified according to the increment or decrement depends on the Direction Flag DF in the flag register. When df = 0, the increment value is modified, and when df = 1, the increment value is modified.

Because a string uses an implicit addressing method, only the operator code is supported in the string operation instructions, and no operands exist. For example, the serial operation command: movsb

There is no operand in the command, but the operations are actually performed on the source operand of the address DS: [Si] and ES: [di] as the destination operand of the address.

Movsb: string transmission command, which transfers data in bytes. The source address and target address of the string are controlled through the Si and DI registers. For example, the n Bytes of the DS: Si address are copied to the address pointed to by ES: Di. After the replication, the DS: the content of Si remains unchanged.

 

Port addressing: This is a way for the CPU to address peripheral ports. This addressing method is only used for input and output commands. The connection between the CPU and external devices must be through the input and output interfaces. The CPU can receive information from the input device or send information to the output device. The external device is directly connected to the port in the interface. When the CPU needs to exchange information with the peripherals or control the peripherals, the access port is used. Port addressing is how to determine the port address during input/output operations.

8086 there are two port addressing methods:

(1) Direct port address: In this addressing mode, the port address is directly given in the form of an 8-bit immediate number in the command, and the addressing range is 0 ~ 255.

In assembly instructions, the format is:

Input command:

In Al, 24 h; send the 24 h port content to Al

In ax, 20 h; send the 20 h port content to ax

Output command:

Out 21 h, Al; output the content of Al to the port of 21h

Out 23 h, ax; Output ax content to the 23h Port

Note: 1) the direct address of the port in the input and output commands is not in parentheses;

2) 8086 only the Al/ax accumulators can be used to exchange information with the port;

3) The port width can be 8 or 16 bits. When 8 bits are used, information is exchanged with Al, and when 16 bits are used, information is exchanged with ax.

 

(2) Indirect port addressing: the indirect port addressing sends the port address to the Register dx in advance, and the input and output command port address is provided by dx. Because dx is a 16-bit register, the range of indirect port addressing is 0 ~ 65535.

In the assembly, the format is as follows:

Input command:

In Al, DX

In ax, DX

Output command:

Out dx, Al

Out dx, ax

8086 provides a wide range of addressing methods. When programming, selecting an appropriate addressing method will increase the flexibility of programming and improve program quality and programming efficiency.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


 


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.