Compilation Basics: Addressing Methods

Source: Internet
Author: User

Immediately followed by our logo register, this article I generally summarize the way the computer is addressed, because they do not know a lot of the assembly, it is inevitable that there are mistakes, but also hope that the master shot bricks. I hope this series of articles will provide a platform for you to learn the compilation.

The first or the next instruction operand, Intel 8086/8088cpu instruction system in the following 4 kinds of lock operation number:

(1) Register operand: operand in the CPU's General register or segment register

(2) Immediate operand: the operands are given directly in the instruction

(3) Memory operand: The operand is in the storage cell of the memory

(4) I/O operand: operand in the storage unit of the input output port

Depending on the source of the operands, the instructions are divided into register addressing, immediate number addressing, memory addressing, and I/O addressing four categories, the following is a detail of these four types of methods.

First, register addressing

In register addressing mode, operands are from one or two general-purpose registers or segment registers of the CPU (except CS), the 16-bit register operand can be ax, BX, CX, DX, SI, DL, SP, BP, DS, SS, and es,8 bit registers can be Al, AH, BL, BH, CL, CH, DL, DH. Because the number of access operations within the CPU, do not need to access the memory of the second implementation bus cycle, so the execution speed is very fast, in addition to a small number of general-purpose registers, coding required less bits, so the use of register addressing can effectively reduce the command width.

For example: MOV ax, BX; the contents of the register BX are transmitted to the Register AX.

If the ax=1234h before execution, bx=5678h, the content in AX=5678H,BX will not change after the instruction is finished.

Second, immediate number addressing

The instruction operand is placed directly in the code in the immediate number addressing. It is a signed number that is immediately followed by an available 8-bit or 16-bit binary complement in the command opcode, that is, the operand's address is the next unit of the instruction opcode, and this operation becomes an immediate number.

Example: MOV ax, 1234H immediate number 1234H as source operand into register ax

The result of the instruction execution is that the value of the register ax is 1234H

Third, memory addressing

In the memory addressing mode, the instruction operand is typically a data segment other than the code snippet, a storage unit in the stack segment and an additional segment, and an expression that gives the storage cell address or the storage cell address. In assembly language, a storage cell address is represented using a logical address. That is, the Janki value: offset. Where the Janki value is in a segment register. The offset represents the distance between the storage unit and the Janki value, which is determined and evaluated by the Executive unit of the CPU, the active address ea. When executing the instruction, the CPU first calculates the address information provided by the operation number segment, computes the valid address EA by the Executive Unit union, and then by the bus interface unit Biu according to the formula: Physical Address = Janki Value X16+ea calculates the physical address of the operand, and the effective address EA is composed of 3 address components:

(1) Displacement quantity

(2) Base Address

(3) Change address

In general, the source operand and the destination operand of the dual operand instruction cannot be the memory operand at the same time. The memory addressing modes can be divided into: direct addressing, memory indirection, base address/change addressing, base address addressing, relative base address change addressing, and string-operation addressing, depending on the EA calculation method. 6.

1. Direct addressing

The simplest type of memory addressing in direct addressing, that is, the effective address of the operand is only composed of the displacement, that is, the ea= displacement, the displacement is directly included in the instruction, and the instruction opcode is stored in the Code section, while the operands are stored in the data section, the direct addressing mode does not involve other registers. To use an instance of direct addressing:

mov bx, VAR; equivalent to mov bx, Ds:var

mov ax, [100H]; equivalent to mov ax, ds:[100h]

For example: MOV ax, [1234H]; transfer the contents of the child storage unit with the current Data segment offset 1234H bytes to the register ax.

Set (DS) =2000h, the physical address of the child storage Unit to be accessed is 2000h*16+1234h=21234h,

If the contents of the byte's storage unit is 5678H, the (AX) =5678h.

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.