The use of assembly language design cycle program | assembly language (Wang Shuang edition) learning chapter notes [BX] and loop instruction (2)

5.4 Debug and assembler instructions of different treatments Masm

我们在Debug中写过类似的指令:
mov ax,[0]
表示将ds:0处的数据送入al中
但是再汇编源程序中,"mov ax,[0]"指令被编译器当作"mov ax,0"处理

Task: the memory 2000: 0,2000: 1,2000: 2,2000: incoming data unit 3 al, bl, cl, dl in.

debug realization:
Here Insert Picture Description
Here Insert Picture Description
Compiler Implementation:
Here Insert Picture Description
Here Insert Picture Description
Summary:

 - masm编译器中,[idata]被解释为idata。
 - 可以用寄存器bx来实现,mov bx,1;mov bl,[bx]即可
 - 还可以把段地址显式的表现出来,如mov bl,ds:[1]

5.5 loop and [bx] of the combination

Consider a problem: Calculated ffff: 0-ffff: b of data unit and the result is stored in the dx.
(1) storing the operation result will exceed the scope of dx?

ffff:0~ffff:b是字节单元,范围为0~255,12个累加不会超出范围。

(2) Can ffff: 0 ~ ffff: b directly accumulated data to the DX?

不行,因为ffff:0~ffff:b中的数据是8位的,不能直接累加到16位寄存器dx中。

(3) Can ffff: 0 ~ ffff: b is accumulated into data dl, and dh is set to 0?

不行,dl也是8位寄存器,累加可能造成进位丢失

Solution:

mov al,ds:[0]
mov ah,0
add dx,ax
使用以上结构用ax作为中介进行累加

5.4 The procedures used to achieve the above instruction loop

assume cs:code
code segment
	mov ax,0ffffh
	mov ds,ax
	mov bx,0
	mov dx,0
	mov cx,12
	
s:	mov al,[bx]
	mov ah,0
	add dx,ax
	inc bx
	loop s
	mov ax,4c00h
	int 21h
	
code ends
end

Here Insert Picture Description


5.6 Segment Prefix

Instruction "mov ax, [bx]", the offset address of the memory cell is given by bx, and the segment address of the default ds. These instructions appear in the memory access unit, a segment address explicitly specifies the memory unit "ds:", "cs: ", "ss:" or "es:", Segment Prefix in assembly language .


5.7 a safe space

In 8086 mode, just write to some memory space is very dangerous, because this space can store important system data or code.

In general the PC, DOS mode, DOS and other legitimate programs generally do not use 0: 256 bytes of space 2FF: 200 to 0. So, we use this space to be safe.
Here Insert Picture Description


5.8 Use segment prefix

Tasks: ffff: 0 ~ ffff: b copy data unit to 0: 200-0: 20b units

assume cs:code
code segment
	mov bx,0
	mov cx,12
	
s:	mov ax,0ffffh
	mov ds,ax
	mov dl,[ax]	;(dl)=((ds)*16+(bx)),将ffff:bx中的数据送入dl
	
	mov ax,0020h
	mov ds,ax ;每次循环设置两次ds,代码效率低下
	mov [bx],dl
	
	inc bx
	loop s
	
	mov ax,4c00h
	int 21h
	
code ends
end

Code optimization:

assume cs:code
code segment
	mov ax,0ffffh
	mov ds,ax
	mov ax,0020h
	mov es,ax ;使用两个段寄存器
	mov bx,0
	mov cx,12
	
s:	mov dl,[bx]
	mov es:[bx],dl
	inc bx
	loop s
	
	mov ax,4c00h
	int 21h
code ends
end
Published 107 original articles · won praise 68 · views 7767

Guess you like

Origin blog.csdn.net/weixin_43092232/article/details/105063496