一、实验内容
1. 实验任务1
- 使用任意文本编辑器,录入汇编源程序task1.asm。
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
阅读源程序,从理论上分析源代码的功能,尤其是line15-25,循环实现的功能是什么,逐行理解每条指
令的功能。
-
使用masm、link对task1.asm进行汇编、链接,得到可执行文件task1.exe,运行并观察结果。

-
使用debug工具对程序进行调试,执行到程序返回前,即line27之前,观察结果。

-
修改line4里5个字节单元的值,重新汇编、链接、运行,观察结果。
db 5 dup(2) --> 改成: db 2,3,4,5,6

- 基于观察,分析、猜测这里的数值作用是什么。
- 答:这里的数字作用用来控制字符颜色,数值是ASCII值对应相应的颜色。
2. 实验任务2
- 已知数据段data中定义字节数据如下:
data segments db 23, 50, 66, 71, 35 data ends
- 编写程序,在屏幕上以十进制整数形式打印输出这5个两位数。
assume cs:code, ds:data data segment db 23, 50, 66, 71, 35 db 10 dup(0) data ends code segment start: mov ax, data mov ds, ax mov cx,5 mov si,0 s: mov ah,0 mov al, ds:[si] mov bl, 10 div bl mov ds:[si+5],al mov ds:[si+6],ah mov ah, 2 mov dl,ds:[si+5] add dl, 30h int 21h mov ah, 2 mov dl, ds:[si+6] add dl, 30h int 21h inc si mov ah, 2 mov dl, 32 int 21h loop s mov ah, 4ch int 21h code ends end start
-
结合可执行文件中寄存器CX的值,使用u命令对task2.exe进行精确反汇编
- 运行结果如下:

3. 实验任务3
- 使用任意文本编辑器,录入汇编源程序task3.asm。
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
回答教材中①②③三个问题。
- ①cpu执行程序返回前,data段中的数据为多少:
- 答:仍然是原先的值,0123h, 0456h, 0789h, 0abch, 0defh, 0fedh, 0cbah, 0987h。

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


- ③设程序加载后,code段的段地址为x,则data段的段地址为x-2,stack段的段地址为x-1
4. 实验任务4
- 使用任意文本编辑器,录入汇编源程序task4.asm。
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
回答教材中①②③④四个问题。
- ①cpu执行程序返回前,data段中的数据为多少:
- 答:仍然是原先的值,0123h,0456h

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


- ③设程序加载后,code段的段地址为x,则data段的段地址为x-2,stack段的段地址为x-1。
- ④对于如下定义的段:
name segment
...
name ends
如果段中的数据占N个字节,则程序加载后,该段实际占有的空间为:((N+15)/16),结果取整。

分析:通过与任务3的实验对比,对于段系统会分配以16个字节为单位的数据空间,如果段中的数据不足16个字节的倍数,不足的部分默认填充0。
5. 实验任务5
- 使用任意文本编辑器,录入汇编源程序task5.asm。
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
回答教材中①②③三个问题。
- ①cpu执行程序返回前,data段中的数据为多少:
- 答:仍然是原先的值,0123h,0456h。

- ②cpu执行程序返回前,cs=076ah,ss=076eh,ds=076dh。


- ③设程序加载后,code段的段地址为x,则data段的段地址为x+3,stack段的段地址为x+4。
6. 实验任务6
- 如果将实验任务3,任务4,任务5中的最后一条伪指令“end start”改为“end”(也就是说,不指明程序的入口),则哪个仍然可以正确执行?请说明原因。
- 答:三个程序都可运行,但前两个运行结果无法正确实现,后一个程序可以正确执行。



7. 实验任务7
- 使用任意文本编辑器,录入汇编源程序task7.asm。
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,c mov es,ax mov bx,0 mov cx,8 s: mov ax,0 mov al,ds:[bx] add al,ds:[bx+16] mov es:[bx],al inc bx loop s mov ax,4c00h int 21 code ends end start
- 附上在debug环境中,执行到程序返回前,查看逻辑段的数据的截图如下:


8. 实验任务
- 使用任意文本编辑器,录入汇编源程序task8.asm。
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,b mov ss,ax mov sp,16 mov ax,a mov ds,ax mov bx,0 s: push ds:[bx] add bx,2 loop s mov ax,4c00h int 21h code ends end start
- 附上在debug环境中,执行到程序返回前,查看逻辑段的数据的截图如下:




posted on
浙公网安备 33010602011771号