Getting started with crazy summer vacation Study Notes (7) -- DP, Div, DUP
Reference: Chapter 8th of Assembly Language
1. bx, Si, Di, and BP
The 8086cpu has only four registers and can use "[...]" for unit addressing.
BP: except that the default segment address is SS, it is the same as that of BX.
All their correct combinations
mov ax,[bx]mov ax,[si]mov ax,[di]mov ax,[dp]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]
Note: Bx and BP cannot be used at the same time. For example, [bx + bp] is incorrect.
2. specify the length of data to be processed
Word PTR
Byte PTR indicates bytes
In this way, the register directly specifies the Data Length:
mov ax,1mov ax,ds:[0]
However, let's look at the following example:
assume cs:code,ds:datadata segmentdw 1111H,1111H,1111H,1111H,1111H,1111H,1111H,1111Hdata ends code segmentstart:mov ax,datamov ds,axmov ds:[0],1 ;Errormov ax,4c00Hint 21Hcode endsend start
In this case, an error is reported because the compiler does not know whether 1 is 8-bit or 16-bit.
Improvement:
assume cs:code,ds:datadata segmentdw 1111H,1111H,1111H,1111H,1111H,1111H,1111H,1111Hdata ends code segmentstart:mov ax,datamov ds,axmov byte ptr ds:[0],1 ;Errormov ax,4c00Hint 21Hcode endsend start
Add byte PTR or word PTR.
When the byte PTR is added, the value in the DS segment is: 0b56: 0000 01 11 11 11 11 11-11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11
When word PTR is added, the value in the DS segment is: 0b56: 0000 01 00 11 11 11 11 11-11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11
Example:
assume cs:code,ds:datadata segmentdw 00FFHdata ends code segmentstart:mov ax,datamov ds,axinc byte ptr ds:[0]mov ax,4c00Hint 21Hcode endsend start
INC byte ptr ds: [0], DS: [0] DS: [1] is 00
If it is changed to INC word ptr ds: [0], after running, DS: [0] DS: [1] bit 00 01
3. pseudocommand DD, div command
The pseudocommand dd indicates 32 bits, DW indicates 16 bits, and DB indicates 8 bits. The example is shown below.
DIV is a division command in the format of divisor Div.
There are two kinds of divisor: If it is 8 bits, the divisor is 16 bits and is stored in ax. Calculation Result: The operator is stored in Al, and the remainder is stored in AH.
If the divisor is 16 bits, the divisor is 32 bits, and the low 16 bits are placed in ax, and the high 16 bits are stored in dx. Calculation Result: The operator is stored in ax, and the remainder is stored in dx.
The dividend number is a 32-bit example:
assume cs:code,ds:datadata segmentdd 100001dw 100dw 0data endscode segmentstart:mov ax,datamov ds,axmov ax,ds:[0]mov dx,ds:[2]div word ptr ds:[4]mov ds:[6],axmov ax,4c00Hint 21Hcode endsend start
After running, ax is 03e8h and DX is 0001 H.
4. DUP
DUP must be used with DD, DW, And dB to repeatedly define data.
Example:
DB 3 DUP (0)
Three bytes are defined. They are all 0, which is equivalent to db 0, 0, and 0.
DB 3 DUP (0, 1, 2)
Nine bytes are defined, which are 0, 1, 2, 0, 1, 2, 0, 1, and 2.
Equivalent to DB, 2
DB 3 DUP ('abc', 'abc ')
Defines 18 characters, which are 'abcabcabcabcabcabc'
Equivalent to DB 'abcabcabcabcabcabc'