Compilation of learning - Day Four

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

Hexadecimal data in the assembler, data not beginning with the letter, so larger than the 9FFFH be preceded by a 0

 

 

Because DS = 075AH, so we can know the program address in DS + 10H = 076AH

The first instruction instruction program for CS: IP

 

Shows DS: 0006H address data stored

 

 

g "offset"

The offset address prior to execution of instructions

 

When entering the loop, a p-instruction, Debug be performed until (cx) = 0 until the

 

5.4 Debug and assembler instructions of different treatments masm

Debug in

mov ax,2000
mov ds,ax
mov al,[0]
mov bl,[1]
mov cl,[2]

Debug will be in the [0] is processed (al) = ((ds) * 16 + 0) ...

 

masm compiler

assume code
code segment
        mov ax,2000
        mov ds,ax
        mov al,[0]
        mov bl,[1]

        mov ax,4c00h
        int 21h
code ends
ends

Will [0] processing is 00, will not add segment address

 

Solution: Use mov al, ds: [0]

 

5.5 loop and [bx] of the combination

计算ffff:0~ffff:b的数据总和,结果储存在dx中

1.不能直接将ds:[0]~ds:[0bh]中的数据放入dx中,因为前者是一个字节,8位寄存器,后者是一个字,两字节,16位寄存器。

2.不能使用dl累加ds:[0]~ds:[0bh]中数据,因为dl位8位寄存器,最大存储的数据为255,ds:[0]~ds:[0bh]每个都是8位寄存器,累加容易越界。

 

因此,我们使用一个中介ax的16位寄存器中的低位储存ds:[0]~ds:[0bh],再累加到dx

assume cs:code
code segment
        mov ax,0ffffh
        mov ds,ax
        
        mov al,ds:[0]
        mov ah,0
        mov dx,ax
        
        mov al,ds:[1]
        mov ah,0
        mov dx,ax
        
        ...
    
        mov al,ds:[0bh]
        mov ah,0
        add dx,ax
        
        mov ax,4c00h
        int 21h
        
code ends
end

 

使用循环优化上面程序

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

 

 

 

5.6 段前缀

出现在访问内存单元的指令中,用于显示地指明内存单元的段地址的"ds:","cs:","ss:","es:",在汇编语言中称为段前缀

 

5.7 一段安全的空间

DOS和其他合法程序一般都不会使用0:200~0:2ff(00200hh~002ffh)的256个字节空间。因此我们需要写入数据就往0:200~0:2ff中写入。

 

5.8 段前缀的使用

assume cs:code
code segment
        mov ax,0ffffh
        mov ds,ax    ;ds段寄存器

        mov ax,20h
        mov es,ax    ;es段寄存器
        
        mov bx,0
        mov cx,12
        
s:        mov al,ds:[bx]
        mov es:[bx],al
        inc bx
        loop s
        
        mov ax,4c00h
        int 21h
        
code ends
end

 

实验4 [bx]和loop的使用

 (1)

assume cs:code
code segment
    mov ax,20h
    mov ds,ax
    
    mov bx,0
    mov cx,64
s:    mov [bx],bl
    inc bl
    loop s
    
    mov ax,4c00h
    int 21h
    
code ends
end

 

(2)没变,刚好9条,第一题应该地址和传递数据是分开的,所以第二题要求9条

 1 assume cs:code
 2 code segment
 3     mov ax,20h
 4     mov ds,ax
 5     
 6     mov bx,0
 7     mov cx,64
 8 s:    mov [bx],bl
 9     inc bl
10     loop s
11     
12     mov ax,4c00h
13     int 21h
14     
15 code ends
16 end

 

(3)

1) 复制的是存放程序代码的数据,从076a:0~076a:11

 

0~10h一共需要执行17次

所以第一个空填076ah,第二个空填17

Guess you like

Origin www.cnblogs.com/Mayfly-nymph/p/11066323.html