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

实验结论

1. 实验任务1

  task1.asm源代码文件:

 1 assume cs:code, ds:data
 2 data segment
 3         db 'Nuist'
 4         db 5 dup(2)
 5 data ends
 6 
 7 code segment
 8 start:
 9         mov ax, data
10         mov ds, ax
11 
12         mov ax, 0b800H
13         mov es, ax
14 
15         mov cx, 5      ;设置循环次数
16         mov si, 0
17         mov di, 0f00h
18 s:      mov al, [si]
19         and al, 0dfh    ;0dfh=11011111b,将al的第五个字符变成大写字母
20         mov es:[di], al
21         mov al, [5+si]
22         mov es:[di+1], al
23         inc si
24         add di, 2
25         loop s
26 
27         mov ah, 4ch
28         int 21h
29 code ends
30 end start

  运行结果截图: 

  

  debug调试至程序返回前:

  

   修改line4里5个字节的单元值,重新编译运行程序:

  

   字节内容分析:此处通过对于值的修改,可以更改显示字符的颜色。

2. 实验任务2

  task2.asm源代码:

 1 assume cs:code, ds:data
 2 data segment
 3     db 23,50,66,71,35
 4 data ends
 5 
 6 code segment
 7 start:
 8     mov ax,data
 9     mov ds,ax
10 
11     mov cx,5
12     mov bx,0
13 s:
14     mov ax,ds:[bx]
15     mov bl,10
16     div bl
17     
18     mov ah,2
19     mov dl,ah
20     int 21h
21 
22     add bx,1
23     
24     mov ax,ds:[bx]
25     mov bl,10
26     div bl
27     
28     mov ah,2
29     mov dl,ah
30     int 21h
31 
32     mov dl,20h
33     int 21h
34 
35     add bx,1
36     loop s
37 
38     mov ax,4c00h
39     int 21h
40 code ends
41 end start

  运行结果:

  

 3. 实验任务3

  task3.asm源代码

 1 assume cs:code, ds:data, ss:stack
 2 data segment
 3   dw 0123h, 0456h, 0789h, 0abch, 0defh, 0fedh, 0cbah, 0987h
 4 data ends
 5 
 6 stack segment
 7   dw 0, 0, 0, 0, 0, 0, 0, 0
 8 stack ends
 9 
10 code segment
11 start:  mov ax,stack
12         mov ss, ax
13         mov sp,16
14         
15         mov ax, data
16         mov ds, ax
17         
18         push ds:[0]
19         push ds:[2]
20         pop ds:[2]
21         pop ds:[0]
22         
23         mov ax,4c00h
24         int 21h
25 
26 code ends
27 end start

  ① CPU执行程序,程序返回前,data段中的数据为:0123h、0456h、0789h、0abch、0defh、0fedh、0cbah、0987h;

  ② CPU执行程序,程序返回前,cs=076c、ss=076b、ds=075a。

  ③ 设程序加载后,code段的段地址为X,则data段的段地址为 X-2 ,stack段的段地址为 X-1 。

  

4. 实验任务4

  task4.asm源代码:

 1 assume cs:code, ds:data, ss:stack
 2 data segment
 3   dw 0123h, 0456h
 4 data ends
 5 
 6 stack segment
 7   dw 0, 0
 8 stack ends
 9 
10 code segment
11 start:  mov ax,stack
12         mov ss, ax
13         mov sp,16
14         
15         mov ax, data
16         mov ds, ax
17         
18         push ds:[0]
19         push ds:[2]
20         pop ds:[2]
21         pop ds:[0]
22         
23         mov ax,4c00h
24         int 21h
25 
26 code ends
27 end start

  ① CPU执行程序,程序返回前,data段中的数据为0123h、0456h。

  ② CPU执行程序,程序返回前,cs=076ch、ss=076bh、ds=076ah。

  

  ③ 设程序加载后,code段的段地址为X,则data段的段地址为 X-2 ,stack段的段地址为 X-1 。

  ④ 对于如下定义的段:

1 name segment
2 .......
3 .......
4 name ends

       如果段中的数据占N个字节,则程序加载后,该段实际占有的空间为((N/16)+1)*16个字节。

 5. 实验任务5

  task5.asm的源代码:

 1 assume cs:code, ds:data, ss:stack
 2 
 3 code segment
 4 start:  mov ax,stack
 5         mov ss, ax
 6         mov sp,16
 7         
 8         mov ax, data
 9         mov ds, ax
10         
11         push ds:[0]
12         push ds:[2]
13         pop ds:[2]
14         pop ds:[0]
15         
16         mov ax,4c00h
17         int 21h
18 
19 code ends
20 data segment
21   dw 0123h, 0456h
22 data ends
23 
24 stack segment
25   dw 0,0
26 stack ends
27 end start

  ① CPU执行程序,程序返回前,data段中的数据为:0123h、0456h;

  ② CPU执行程序,程序返回前,cs=076a、ss=076e、ds=075d。

  ③ 设程序加载后,code段的段地址为X,则data段的段地址为 X+3 ,stack段的段地址为 X+4。

  

 6. 实验任务6   

  ① 如果将(1)、(2)、(3)题中最后一条伪指令“end start”改为“end”(也就是说,不指明程序的入口),则哪个程序仍然可以正确执行?请说明原因。

  答:第(3)题可以正确执行。在不指明开始地址的情况下,程序默认从code段开始执行,而程序(3)的stack段和data段都在code段后面,所有可以正常被识别执行。而程序(1)和(2)的data段会被跳过,无法正确执行。

7. 实验任务7

  task7.asm源代码:

 1 assume cs:code, ds:a, ss:b ,es:c
 2 a segment
 3   db 1,2,3,4,5,6,7,8
 4 a ends
 5 
 6 b segment
 7   db 1,2,3,4,5,6,7,8
 8 b ends
 9 
10 c segment  
11   db 8 dup(0)
12 c ends
13 
14 code segment
15 start:
16     mov ax,a
17     mov ds,ax
18     
19     mov ax,b
20     mov ss,ax
21 
22     mov ax,c
23     mov es,ax
24 
25     mov si,0
26     mov cx,8
27 
28 s:  mov al,ds:[si]
29     add al,ss:[si]
30     mov es:[si],al
31     inc si
32     loop s
33 
34     mov ah,4ch
35     int 21h
36 code ends
37 end start

  实验结果截图:

  

 

8. 实验任务8

  task8.asm的源代码:

assume cs:code, ds:a, ss:b
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 ss,ax
    mov sp,010h
    
    mov si,0
    mov cx,8

s:    push [si]
    add si,2
    loop s

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

  实验结果截图:

   

 实验总结

   

posted @ 2020-11-27 12:19  Lvatsit  阅读(115)  评论(2编辑  收藏  举报