实验3 多个段的汇编源程序编写与调试

实验任务1:

源代码:

assume cs:code, ds:data
data segment
        db 'Nuist'
        db 5 dup(2)
data ends

code segment
start:
        mov ax, data
        mov ds, ax

        mov ax, 0b800H
        mov es, ax

        mov cx, 5
        mov si, 0
        mov di, 0f00h
s:      mov al, [si]
        and al, 0dfh
        mov es:[di], al
        mov al, [5+si]
        mov es:[di+1], al
        inc si
        add di, 2
        loop s

        mov ah, 4ch
        int 21h
code ends
end start

运行结果截图:

 修改后的运行结果:

 debug截图:

 源代码中data段line4的字节数据的用途是控制字符的颜色。

 

实验任务2:

源代码:

assume cs:code, ds:data
data segment
    db 23, 50, 66, 71, 35
data ends

code segment
start:
    mov ax, data
    mov ds, ax    
    
    mov ax, 0b700H
    mov es, ax
    mov di, 0f00h

    mov si, 0
    mov cx, 5
s:    mov al, ds:[si]
    mov ah, 0
    mov bl, 10
    div bl
    add al, 30h
    add ah, 30h
    mov es:[di], al
    mov es:[di+1], ah
    mov ah, 2
    mov dl, es:[di]
    int 21h
    mov ah, 2
    mov dl, es:[di+1]
    int 21h
    inc si
    add di, 2
    mov ah, 2
    mov dl, 32
    int 21h
    loop s

    mov ah, 4ch
    int 21h
code ends
end start

结果截图:

 

实验任务3:

源代码:

assume cs:code, ds:data, ss:stack
data segment
  dw 0123h, 0456h, 0789h, 0abch, 0defh, 0fedh, 0cbah, 0987h
data ends

stack segment
  dw 0, 0, 0, 0, 0, 0, 0, 0
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

问题①:

data数据如下图所示:

问题②:

 cs=076C, ss=076B, ds=076A

问题③:

 data的段地址为X-2,stack的段地址为X-1

data数据与设想一致:

反汇编截图:

 

 实验任务4:

源代码:

assume cs:code, ds:data, ss:stack
data segment
  dw 0123h, 0456h
data ends

stack segment
  dw 0, 0
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

问题①:

data中的数据为:

问题②:

cs=076C, ss=076B, ds=076A

问题③:

 data的段地址为X-2,stack的段地址为X-1

问题④:

我猜测会占16字节的整数倍,是N字节按16的整数倍向上取整。

反汇编截图:

 调试截图:

 

实验任务5:

源代码:

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
data ends

stack segment
  dw 0,0
stack ends
end start

问题①:

data中的数据为:

问题②:

cs=076A, ss=076E, ds=076D

问题③:

 data的段地址为X+3,stack的段地址为X+4

反汇编截图:

 

 

实验任务6:

第(3)个可以正常运行,因为一旦没有指定程序入口,代码将按顺序执行,那前面的data和stack将被错误地认为是代码而执行,从而得不到正确的结果;第(3)个由于data和stack段都位于代码的后面,故不会影响到代码的正常运行。

 

实验任务7:

源代码:

assume cs:code
a segment
  db 1,2,3,4,5,6,7,8
a ends

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

c segment   ;
  db 8 dup(0)
c ends

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

结果截图:

 

实验任务8:

源代码:

assume cs:code
a segment
  dw 1,2,3,4,5,6,7,8,9,0ah,0bh,0ch,0dh,0eh,0fh,0ffh
a ends

b segment
  dw 8 dup(0)
b ends

code segment
start: 
    mov ax, a
    mov ds, ax
    mov ax, b
    mov es, ax
    mov di, 0
    mov cx, 8
s:    push [di]
    pop es:[di]
    add di, 2
    loop s
    
    mov ax, 4c00h
    int 21h
code ends
end start

实验结果截图:

 

实验总结:

(1)通过本次的上机实验,我掌握了数据段,栈段,代码段三者之间的关系,以及多段程序的编写与调试;

(2)学会了字母之间的大小写转化;

(3)对于各种的寻址方式可以更加熟练地使用;

(4)对于div,loop等命令的使用更加熟练;

(5)学会了借助栈实现一个简单的循环的叠加。

 

posted @ 2020-11-21 20:21  gank007  阅读(113)  评论(2)    收藏  举报