[bx]和loop指令

debug和编译器的区别

例1指令:

mov ax,[0]

debug执行:

mov ax,[0]

编译器执行:

mov ax,0

编译器编写汇编代码时访问内存单元的两种方法如下


;加上段前缀(段前缀:显示指明段地址)

mov
ax,ds[0] ;或者间接给出内存单元的偏移地址 mov bx,0 mov ax,[bx]

LOOP

;将ffff:0~ffff:b的内容复制到0:200~0:20b中

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

改进,使用两个段寄存器

;将ffff:0~ffff:b的内容复制到0:200~0:20b中

assume cs:code
code segment
    mov cx,6
    mov bx,0
    mov ax,0ffffh
    mov ds,ax
    mov ax,0020h
    mov es,ax
    s:    
        mov dx,ds:[bx]
        mov es:[bx],dx
        
        inc bx
        inc bx
        
        loop s
        mov ax,4c00h
        int 21h
    
    code ends
end

向内存0:200~0:23F依次传入数据0~63(3FH)

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

复制程序开始到loop s处的指令到0:200处

assume cs:code
code segment
    mov ax,0020h
    mov ds,ax
    mov ax,cs
    mov es,ax
    mov cx,27
    mov bx,0
    s:mov al,[bx]
      mov ds:[bx],al
      inc bx
      loop s
      mov ax,4c00h
      int 21h
code ends
end

mov ax,4c00h 占3字节

int 21h   占2字节

共复制字节数:CX(程序指令大小)-5(不复制的指令)=23=17H

实验五

1.

assume cs:code,ds:data,ss:stack
data segment 
    dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h;定义8个字型数据
data ends

stack segment
    dw 0,0,0,0,0,0,0,0;定义8个字型数据为栈段开辟空间
stack ends

code segment
start:mov ax ,stack
        mov ss,ax
        mov sp,16
        
        mov ax,data
        mov ds,ax
        
        push ds:[0]
        push ds:[2]
        pop ds:[2]
        pop ds:[0]
        
        mov ax,4c00h
        int 21h
code ends

end start

3.

assume cs:code,ds:data,ss:stack


code segment
start:mov ax ,stack
        mov ss,ax
        mov sp,16
        
        mov ax,data
        mov ds,ax
        
        push ds:[0]
        push ds:[2]
        pop ds:[2]
        pop ds:[0]
        
        mov ax,4c00h
        int 21h
code ends


data segment 
    dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h;定义8个字型数据
data ends

stack segment
    dw 0,0,0,0,0,0,0,0;定义8个字型数据为栈段开辟空间
stack ends

end start

5.

;将a段和b段的数据依次相加,结果存入c段
assume cs:code
a segment
    db 1,2,3,4,5,6,7,8;定义8个字节类型数据
a ends

b segment
    db 1,2,3,4,5,6,7,8
b ends

c segment
    db 0,0,0,0,0,0,0,0
c ends

code segment
start:
    mov ax,a
    mov es,ax
    mov ax,b
    mov ss,ax
    mov ax,c
    mov ds,ax
    mov cx,8
    mov bx,0
    s:mov ah,es:[bx]
    add ah,ss:[bx]
    mov [bx],ah
    inc bx
    loop s
    mov ax,4c00h
    int 21h
    
code ends

end start

注意这里用masmplus编译会失败,因为masmplus不能用c作为标识

6.

;用push指令将a段中的前8个字形数据,逆序存储到b段中
assume cs:code a segment dw 1,2,3,4,5,6,7,8,9,0ah,0bh,0ch,0dh,0eh,0fh a ends b segment dw 0,0,0,0,0,0,0,0,0 b ends code segment start:mov ax,a mov es,ax mov ax,20h mov ss,ax mov sp,30 mov ax,b mov ds,ax mov cx,8 mov bx,0 s:push es:[bx] add bx,2 loop s mov bx,0 s1:pop ds:[bx] add bx,2 loop s1 mov ax,4c00h int 21h code ends end start
原文地址:https://www.cnblogs.com/luocodes/p/11919038.html