Assembly language learning the eighth chapter-two basic problems in data processing

Source: Internet
Author: User
Tags microsoft dynamics

This blog series reference from << assembly Language >> third edition, author: Wang Shuang


Computer CPU data processing consists of two basic questions: 1. Where is the data?  2. How big is the data? This chapter serves as a summary section of the preceding content, mainly to illustrate these two issues. We define two symbols Reg and Sreg. Where Reg is register, Sreg is segment register

Reg includes: Ax,bx,cx,dx,ah,al,bh,bl,ch,cl,dh,dl,sp,bp,si,di

Sreg includes: ds,ss,sp,es


8.1 bx, Si, Di and bp

1. In 8086CPU only Bx,si,di and BP four registers can be used in ' [...] ' For memory addressing in:

For example, the following instructions are correct:

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

The following instructions are not correct:

mov Ax,[cx]mov Ax,[ax]mov Ax,[dx]mov Ax,[ds]

2.the four registers of Bx,si,di and BP have only the following four combinations. BX and SI,BX and DI,BP and si,bp and di

For example, the following instructions are correct:

mov Ax,[bx]mov ax,[si]mov ax,[di]mov ax,[bp]mov ax,[bx+si]mov ax,[bx+di]mov Ax,[bp+si]mov Ax,[bp+di]mov ax,[bx+si+idata ]mov Ax,[bx+di+idata]mov Ax,[bp+si+idata]mov Ax,[bp+di+idata]


The following instruction is incorrect:

mov Ax,[bx+bp]mov Ax,[si+di]

3. Just again ' [...] ' With register BP addressing, the segment register defaults to SS.

For example, the following command:

mov ax,[bp]            (AX) = ((ss) *16+ (BP)) mov Ax,[bp+idata]      (AX) = ((ss) *16+ (BP) +idata) mov Ax,[bp+si]         (AX) = ((ss) * 16+ (BP) + (SI)) mov ax,[bp+si+idata]   (AX) = ((ss) *16+ (BP) + (SI) +idata)



8.2 Where is the machine instruction processing data?
when executing machine instructions, we are always concerned about where the data required to execute the instruction is stored. Data is often stored in three places: Internal CPU (register), memory, and port.

Explains where the instruction stores the data:



8.3 Expression of data position in assembly language

(1) Immediate number:

The data directly contained in the assembly instruction is called the immediate number (the instruction buffer in the CPU before execution)

For example: mov ax,1

Add bx,2000h


(2) Register

The data required to execute the instruction is in the register:

For example: mov ax,bx

Push BX


(3) Segment address and offset address

The data in the instruction to be processed in memory requires a segment address plus an offset address for addressing

The segment address can be given by default (the default DS):

For example: mov ax,[0](default segment address DS)

mov Ax,[di](default segment address DS)

mov ax,[bp] (default segment address ss)

mov Ax,[bp+si] (default segment address ss)

You can also show the segment address:
For example: mov ax,ds:[0]

mov ax,ds:[bp]



8.4 Addressing Mode

When the data is stored in memory, there are many ways to get its offset address, and the method of obtaining an offset address is called addressing. For the summary of all addressing methods.



8.5 How long will the data be processed by the instruction?

How to specify how much data to work with IS as follows:

1. Indicate the size of the data to be processed by register

such as word operation: mov ax,ds:[0]

such as byte operation: mov al,ds:[0]


2. In the absence of registers, you can use x ptr to indicate the size of the data that needs to be processed. X can be either word or byte

such as word manipulation: mov word ptr ds:[0],1

such as byte operations: mov byte ptr ds:[0],1


3. Some directives access the data size by default

Like the push command.

Push [1000H] defaults to Word manipulation


8.6 Comprehensive application of addressing methods

Suppose a company's data is stored in an area of memory where seg:60h is the starting address, as follows:


Now want a change 137 to 38, change 40 to 70, change ' PDP ' to ' VAX '

We can address this by [Bx+si+idata], and use x ptr to specify the length of the data to change. So the core program is as follows:



8.7 div Instruction

The DIV directive notes the following:

1. Divisor: There are 8-bit and 16-bit two, in a reg and memory unit.

2. Divisor: By default in AX or DX and ax, if the divisor is 8 bits, the divisor is 16 bits, by default in Microsoft Dynamics AX, if the divisor is 16 bits, the divisor is 32 bits, stored in DX and ax, DX is stored high 16 bits, ax is stored 16 bits

3. Result: If the divisor is 8 bits, then the AL Store, ah stores the remainder. If the divisor is 16 bits, then the AX store, DX storage remainder.


The format is as follows:

DIV Reg

div Memory Unit


Like what:

div byte ptr ds:[0]

Meaning: (AL) = remainder of quotient (AH) = (AX)/((DS) *16+0) for (AX)/((DS) *16+0)

div word ptr [bx+si+8]

Meaning:

(AX) =[(DX) *10000h+ (AX)]/((DS) *16+ (BX) + (SI) +8)

(DX) =[(DX) *10000h+ (AX)]/((DS) *16+ (BX) + (SI) +8)



8.8 Pseudo-instruction DD

Dw,db,dd

Where DW defines a word space, DB defines a byte space, and DD defines a two-word space


8.9 dup

The DUP is also a pseudo-directive that is recognized by the compiler. Often the DUP is used with DW,DB,DD to perform data duplication.

Like what:

DB 3 dup (0)

Defines three bytes, each of which has a value of 0, which is equivalent to a DB 0,0,0

DB 3 dup (0,1,2)

Defines nine bytes with a value of 0,1,2,0,1,2,0,1,2 equivalent to DB 0,1,2,0,1,2,0,1,2


Assembly language learning the eighth chapter-two basic problems in data processing

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.