Registers and seven addressing methods

Source: Internet
Author: User

I. Registers

A total of 14 16-bit registers and 8 8-bit registers

 

General registers:

Data register:

AH (8-bit) AL (8-bit) AX (16-bit) (AX and AL are also called accumulators)

BH (8-bit) BL (8-bit) BX (16-bit) (BX, also known as base address register, unique as memory pointer using register)

CH (8-bit) CL (8-bit) CX (16-bit) (CX is used for string operations to control the number of cycles, CL is used for shift)

DH (8-bit) DL (8-bit) DX (16-bit) (DX is generally used for 32-bit multiplication and division to store the dividend or retain the remainder)

 

Pointer register:

SP Stack pointer (store the top stack address)

BP base address pointer (storing stack base address offset)

 

Address Change register: used to store the offset of a storage unit address or the offset of the starting address of a group of storage units,

It is used as a memory (short) pointer. As General registers, they can save operations in 16-bit arithmetic logic operations.

The operation result is the offset of the storage unit address.

 

SI source address (source address change register)

DI Destination Address (Destination Address Change register)

Control register:

IP instruction pointer

FLAG register

① Carry mark CF, which records the carry value generated by the highest valid bit during operation.

② Symbol: SF, the symbol that records the operation result. If the result is negative, set 1; otherwise, set 0.

③ ZF indicates zero. If the calculation result is 0, ZF is at 1. Otherwise, 0 is set.

④ Overflow flag OF. During the operation, if the operand exceeds the range that the machine can represent, it is called overflow. If overflow occurs, the value OF Position 1 is used; otherwise, the value 0 is used.

⑤ The secondary carry mark AF records the carry value generated by 3rd bits (half bytes) During computation.

⑥ The parity mark PF is used to provide test conditions for code errors that may occur when information is transmitted on the machine. If the number of 1 in the result operand is an even number, set it to 1. Otherwise, set it to 0.

 

Segment register

CS code segment IP

DS Data Segment

SS stack segment SP BP

Elasticsearch additional segment

 

2. Seven addressing methods:

1. Immediate addressing:

The operands are included in the instruction. As part of the instruction, it is stored in the code segment after the operation code.

This operand becomes the immediate number. The immediate number can be 8 or 16 bits.

For example:

Command: mov ax, 1234 H

Then: AX = 1234 H

 

2. Register addressing:

The operand is in the internal registers of the CPU, and the instruction specifies the Register number.

For 16-bit operands, the registers can be AX, BX, CX, DX, SI, DI, SP, and BP.

For 8-bit operands, the registers can be AL, AH, BL, BH, CL, CH, DL, and DH.

This addressing method is implemented because the operands are in the registers and you do not need to access the memory to obtain the operands.

Therefore, a high computing degree can be obtained.

 

3. Direct addressing:

The operand is in the register, and the instruction directly contains the valid address (offset address) of the operand)

Note: The operands are generally stored in the data segment.

Therefore, the operand address is obtained by the 16-bit offset directly given in the DS command. If

Segment beyond the prefix, the operand can also be included in other segments outside the data segment.

For example:

Mov ax, [8054]

For example, (DS) = 2000 H,

The execution result is (AX) = 3050 H.

(Physical address = 20000 + 8054 = 28054 H)

The content in 28054H is 3050 H.

 

In assembly language instructions, you can use a symbolic address instead of a numerical address.

For example, mov ax and VALUE

At this time, VALUE is the symbolic address that stores the operand unit.

For example, if it is written as mov ax, [VALUE], it is also possible, and the two are equivalent.

For example, if VALUE is in an additional segment, you must specify the segment prefix as follows:

Mov ax, ES: VALUE or mov ax, ES: [VALUE]

 

4. Indirect addressing of registers:

The operand is in the register, and the valid address of the operand is SI, DI, BX, and BP.

Of the four registers. In general, if the valid address is

In SI, DI, and BX, the content in the DS segment register is the segment value. If

If the valid address is in BP, the content in the SS segment register is used as the segment value.

For example:

Mov ax, [SI]

If (DS) = 5000 H (SI) = 1234 H

Physical address = 50000 + 1234 = 51234 H

The content in the 51234H address is: 6789 H

After the command is executed, (AX) = 6789 H

 

5. Register relative addressing:

In memory, the valid address of an operand is a base address register (BX, BP)

Or add the content of the address change register (SI, DI) plus the sum of the given 8-or 16-bit displacement in the instruction

 

BX 8-bit displacement

EA (valid address) = BP +

SI 16-bit displacement

DI

In general, if the content in SI, DI, or BX is part of the valid address

The referenced segment register is DS. If the content in BP is part of the valid address, the referenced

The segment register is SS.

 

Physical address = 16d × (DS) + (BX) + 8

Or (SI) or 16-bit displacement

Or (DI)

Physical address = 16d × (SS) + (BP) + 8-bit displacement

Or 16-bit displacement

The given 8-or 16-bit displacement in the command is indicated by a complement. When calculating a valid address, such

If the displacement is 8 bits, It is signed as 16 bits.

For example:

Mov ax, [DI + 1223 H]

Assume that (DS) = 5000 H, (DI) = 3678 H

Physical address = 50000 + 3678 + 1233 = 5489BH

Content in 5489BH address: 55AAH

After executing this command, AX = 55AAH

In the following command, the source operand uses register relative addressing and the referenced segment register is SS: mov bx, [BP-4]

In the following command, the destination operand uses register relative addressing. The referenced segment register is ES: mov es: [BX + 5], AL

Command: mov ax, [SI + 3] and mov ax, 3 [SI] are equivalent

 

6. base address and address change addressing:

The operands are in registers, and the valid address of the operands is:

The content of one of the base address registers is added to the content of one of the base address registers.

BX SI

That is, EA = +

BP DI

In general, if the content of BP is part of the valid address, the content of SS is the segment value; otherwise, DS

Segment value.

For example:

Mov ax, [BX] [DI]

Example: (DS) = 2100 H,

(BX) = 0158 H,

(DI) = 10A5H

Then EA = 0158 + 10A5 = 11FD

Physical address = 21000 + 11FD = 221FDH

Content in 221FDH address: 1234 H

After executing this command, AX = 1234 H

 

In the following command, the destination operand uses base address plus address change addressing,

The referenced segment register is DS: mov ds: [BP + SI], AL

 

In the following command, the source operand uses base address plus address change addressing,

Referenced segment register ES: mov ax, ES: [BX + SI]

 

This addressing method is used with arrays or tables. Use base address registers to store the first address of the array, and use the location change register.

To locate the elements in the array, or vice versa. Because both registers can be changed, the number of registers can be more flexible.

Group or table element.

The following two representation methods are equivalent:

Mov ax, [BX + DI]

Mov ax, [DI] [BX]

 

7. Add address change addressing mode to the base address:

In memory, the valid address of an operand is determined by the content of one of the base register and

Content and the given 8-or 16-bit displacement in the command are summed up.

Bx si 8-bit

That is, EA = ++ displacement

Bp di 16-bit

In general, if the content in BP is part of the valid address, the content in the SS segment register is

Value. Otherwise, the content in the DS segment register is used as the segment value.

The given 8-or 16-bit displacement in the command is indicated by a complement.

When calculating a valid address, if the displacement is 8 bits, it is expanded to 16 bits by symbol.

When the obtained valid address is used to operate FFFFH, the 64 K modulo is used.

For example:

Mov ax, [BX + DI-2]

Suppose (DS) = 5000 H, (BX) = 1223 H, DI = 54 H, (51275) = 54 H, (51276) = 76 H

Physical address = 50000 + 1223 + 0054 + FFFE (-2 take the last digit and add one) = 51275 H

After executing this command (AX) = 7654 H

 

Compared with base address addition and address change, this addressing method has a variety of representation methods. The following four methods are equivalent:

Mov ax, [BX + DI + 1234 H], mov ax, 1234 H [BX] [DI]

Mov ax 1234 H [BX + DI], mov ax, 1234 H [DI] [BX]

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.