Assembly language (Wang Shuang) Chapter V

chapter Five

Preliminaries

[Bx] represents a similar memory unit, the offset in bx, the segment address in ds

We descriptive symbol () to indicate the contents of a register or a memory unit

(Ax) representing the content of ax, (20000H) representing the contents of the memory unit 20000H

((Ds) * 16 + (bx)), the contents of the ds ADR1, ADR2 content in the range bx, it is indicated ADR1: the content unit ADR2

(2000: 0), ((ds): 1000H) is not the correct usage

Some specific applications

mov ax, [2] may be described as (ax) = ((ds) * 16 + 2)

push ax can be described as (sp) = (sp) -2 ((ss) * 16 + (sp)) = (ax)

Data (X) represented by two types: bytes or words, which is determined by the type of operation or specific register names

(Al) (bl) is a byte (ds) (ax) of the font

5.1 [BX]

inc bx	;bx自增
mov [bx],ax	;传入一个字,[bx]后一个单元也被赋值
mov [bx],al	;传入一个字节

5.2 Loop instruction

When the CPU executes an instruction loop, the first (cx) = (cx) -1, then determination value cx is not zero, then go to program execution at the label, is performed down to zero, so the number of cycles stored cx ,

Example: Calculation 2 ^ 12

assume cs:code
code segment
	mov ax,2
	
	mov cx,11
  s:add ax,ax
    loop s
    
    mov ax,4c00H
    int 21H
code ends
end

Frame cycle as follows

	mov cx,循环次数
  s:
  	循环执行的程序段
  	loop s

Implemented by calculating the adder 123 * 236, 123 plus one is 236, and the other is 235 plus 123, which is clearly faster

assume cs:code
code segment

	mov ax,0
	mov cx,123
  s:add ax,236
    loop s
    
    mov ax,4c00H
    int 21H
code ends
end

5.3 tracking loop implemented with a program loop in the instruction Debug

Consider a problem, calculated ffff: 0006 Number of unit 3. multiplied result is stored in the dx

1, whether the result of the operation would exceed the scope dx can be stored?

255 * 3 <65535 not

2, the ffff: 0006 units assigned values ​​ax, dx 3 times with (dx) = (dx) + (ax), but ffff:. 6 is a byte unit, the AX register is 16-bit, length Like, how the assignment?

If mov ax, [6] When the assignment ffff: 0006 content will be transmitted in the low ax, and ffff: 0007 will be transmitted in the content of high ax, ax values ​​in order to make the size = ffff: 0006 units value of the same size, we try to make ah = 0

assume cs:code
code segment
	mov ax,0ffffH
	mov ds,ax
	mov bx,6	;ds:bx
	
	mov al,[bx]
	mov ah,0	;使得大小上相等
	
	mov dx,0
	
	mov cx,3
  s:add dx,ax
    loop s
    
    mov ax,4c00H
    int 21H
code ends
end

Note that the first instruction, the assembler source program, the data not beginning with the letter, so to add a 0 in front , A000H written in assembler source program 0A000H

In the Debug, loop s becomes loop s address referred to as loop 0012

Suppose cycle block from the CS: 0012 start, before the code do not want to perform a step, can be used g 0012, Debug from the current CS: IP to point to the start instruction until the (IP) = 0012H

If too many cycles, can be used again in the event of an instruction loop p command, automatically performs the rest of the loop until cx is 0, can also be used g 1006 (assuming CS: 1006 is the address of the instruction next loop)

5.4 Debug and different processing of instructions masm

Write command in the Debug mov ax, [0], indicates the ds: 0 data into the ax, but in the assembler source program, the instructions mov ax, [0] is treated as a compiler directive mov ax, 0 processing, so If you want to 2000: 0 data into cell Al, by [BX] way to access the memory unit

mov ax,2000H
mov ds,ax
mov bx,0
mov al,[bx]

But this is very troublesome, so we take the show to give the segment registers the segment address where the method

mov ax,2000H
mov ds,ax
mov al,ds:[0]

Summary: [...] as Idata constant, in front of the display needs to be given segment register, or the masm [Idata] construed as Idata, if [...] in a register, the address of the default segment in ds, of course, also have to be displayed segment given segment register address is located

5.5 loop and [bx] of the combination

Calculation ffff: 0 ~ ffff: b unit and the data, the result is stored in dx

Storing the operation result does not exceed the range dx, but can not ffff: 0 ~ ffff: b data directly accumulated into dx, since the former data is 8 bits, the length does not match, but if the accumulated dl of ( dh) = 0, is likely to cause the loss of a carry, it is a 16-bit register with an intermediary to do

assume cs:code
code segment

	mov ax,0ffffH
	mov ds,ax
	mov bx,0
	
	mov dx,0
	
	mov cx,12	;0~b 一共12次
	
  s:mov al,[bx]
    mov ah,0
    add dx,ax
    inc bx
    loop s
    
    mov ax,4c00H
    int 21H
code ends
end

5.6 Segment Prefix

mov ax,ds:[bx]
mov ax,cs:[bx]
mov ax,ss:[bx]
mov ax,es:[bx]
mov ax,ss:[0]
mov ax,cs:[0]

ds: cs: ss: es: Segment Prefix in assembly language

5.7 a safe space

In 8086 mode, random writes to the memory section of memory space is very dangerous, this memory may have important data or code

If we need to write data to the memory space, then the operating system to use the space allocated to us

DOS mode, typically 0: 200 ~ 0: 2ff a space in the system or other program data or code, if necessary data is written to the memory, on the use of this space

5.8 Use segment prefix

Memory ffff: 0 · ffff: b copy data unit to 0: 200 ~ 0: 20b units

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 84 original articles · won praise 7 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_43569916/article/details/104503782