Usage of Si and DI registers

Source: Internet
Author: User

 

Sidi is a register with similar functions between 8086cpu and BX. Sidi cannot be divided into two 8-bit registers.

The following three sets of commands implement the same functions:

(1) mov BX, 0

MoV ax, [BX]

(2) mov Si, 0

MoV ax, [Si]

(3) mov Di, 0

MoV ax, [di]

The following three sets of commands also implement the same function:

(1) mov BX, 0

MoV ax, [bx + 123]

(2) mov Si, 0

MoV ax, [Si + 123]

(3) mov Di, 0

MoV ax, [di + 123]

Use the Si and DI registers to implement the 'Welcome to MASM! 'string! 'Copy to the data area behind it.

Assume Cs: codesg, DS: datasg

Datasg segment

DB 'Welcome to MASM! '

DB '............................'

Datasg ends

Analysis:

Most of the programs we write process data, and the data is stored in the memory. Therefore, before processing the data, we must first figure out where the data is stored, that is, the data memory address. now we need to copy the data in the datasg segment. Let's first look at the following data to be copied,

Datasg: 0. This is the address of the data to be copied. So what if I copy it there? The data zone behind it. 'Welcome to MASM! 'The offset address is stored from 0 and the length is 16 bytes. Therefore, the offset address of the Data zone behind them is 16, which is the space to store the string. After knowing the address, we can proceed. our DS: Si points to the original string to be copied, uses DS: Di to point to the destination space for replication, and then completes replication in a loop,

The Code is as follows:

Codesg segment

Start: mov ax, datasg

MoV ds, ax

MoV Si, 0

MoV Di, 16

MoV CX, 8

S: mov ax, [Si]

MoV [di], ax

Add Si, 2

Add Di, 2

Loop s

MoV ax, 4c00h

Int 21 h

Codesg ends

End start

Note that in the program, we use 16-bit registers for data transmission between memory units. Two bytes are copied at a time, and a total of 8 cycles are performed (SI and Di are added with 2 at a time)

 

Use less code to implement:

Analysis:

We can use [Bx (Si or DI) + idata] to simplify the program as follows:

Codesg segment

Start: mov ax, datasg

MoV ds, ax

MoV Si, 0

MoV CX, 8

S: mov ax, 0 [Si]

MoV 16 [ax], ax

Add Si, 2

Loop s

MoV ax, 4c00h

Int 21 h

Codesg ends

End start

[Bx + Si] and [bx + DI]

Previously, we used [Bx (Si or DI)] and [Bx (Si or DI) + idata] to specify a memory unit. We can also use a more flexible approach: [bx + Si] and [bx + DI].

[Bx + Si] and [bx + DI] have similar meanings. We use [bx + Si] as an example.

[Bx + Si] indicates a memory unit. Its offset address is (BX) + (SI) (that is, the value in BX plus the value in Si ).

Let's take a look at the meaning of the mov AX command [bx + Si:

The content of a memory unit is sent to ax. The length of the memory unit is 2 bytes (word unit) and one word is stored. After the offset address is used, the value in Si is added to the value in the BX, the segment address is in DS.

Mathematical Description: (ax) = (DS) * 16 + (BX) + (SI ))

This command can also be written in the following format (commonly used ):

MoV ax, [BX] [Si]

Use DEBUG to view memory:

D 2000:1000

Write the following content in ax, BX, and CX after the program is executed.

MoV ax, 2000 h

MoV ds, ax

MoV BX, 1000 h

MoV Si, 0

MoV ax, [bx + Si]

INC Si

MoV CX, [bx + Si]

INC Si

MoV Di, Si

Add CX, [bx + DI]

Analysis

MoV ax, [bx + Si]

The segment address of the accessed cell is in DS, (DS) = 2000 h; offset address = (BX) + (SI) = 1000 h; after the command is executed (ax) = 00beh

MoV CX, [bx + Si]

The segment address of the accessed cell is in DS, (DS) = 2000 h; offset address = (BX) + (SI) = 1002 h; after the command is executed (CX) = 0600 H

Add CX, [bx + DI]

The segment address of the accessed cell is in DS, (DS) = 2000 h; offset address = (BX) + (DI) = 1002 h; after the command is executed (CX) = 0606 H

[Bx + Si + idata] and [bx + DI + idata]

[Bx + Si + idata] and [bx + DI + idata] have similar meanings. We use [bx + Si + idata] as an example.

[Bx + Si + idata] indicates a memory unit. Its offset address is (BX) + (SI) + idata (that is, the value in BX plus the value in Si ).

Add idata ).

Let's take a look at the meaning of the mov AX command [bx + Si + idata:

The content of a memory unit is sent to ax. The memory unit is 2 bytes in length and stores one word. The offset address is a value in BX and the value in Si is added to idata, the segment address is in DS.

Mathematical Description: (ax) = (DS) * 16 + (BX) + (SI) + idata)

This command can also be written in the following format (commonly used ):

MoV ax, [bx + 200 + Si]

MoV ax, [200 + bx + Si]

MoV ax, 200 [BX] [Si]

Movax, [BX]. 200 [Si]

MoV ax, [BX] [Si]. 200

Use DEBUG to view memory:

D 2000:1000

Write the following content in ax, BX, and CX after the program is executed.

MoV ax, 2000 h

MoV ds, ax

MoV BX, 1000 h

MoV Si, 0

MoV ax, [bx + 2 + Si]

INC Si

MoV CX, [bx + 2 + Si]

INC Si

MoV Di, Si

MoV BX, [bx + 2 + DI]

Analysis:

MoV ax, [bx + 2 + Si]

The segment address of the accessed cell is in DS, (DS) = 2000 h; the offset address is (BX) + (SI) + 2 = 1002 h; after the instruction is executed (ax) = 0006 H

MoV CX, [bx + 2 + Si]

The segment address of the accessed cell is in DS, (DS) = 2000 h; the offset address is (BX) + (SI) + 2 = 1003 h; after the instruction is executed (CX) = 6a00h

MoV BX, [bx + 2 + DI]

The segment address of the accessed cell is in DS, (DS) = 2000 h; the offset address is (BX) + (DI) + 2 = 1004 h; after the instruction is executed (BX) = 226ah

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.