实验3 多个段的汇编源程序编写与测试
一、实验内容
- 1.实验任务1
汇编程序task1.asm文本内容如下:
assume cs:code, ds:data data segment db 'Nuist' db 5 dup(2);生成字节型数据2 2 2 2 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
使用masm、link对task1.asm进行汇编、链接,得到可执行文件task1.exe,同时屏幕下方出现绿色的‘NUIST'字符

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


修改line4里5个字节单元的值,重新汇编、链接、运行,观察结果。

基于观察,分析、猜测这里的数值作用是什么?
分析:数值的作用是控制字符的颜色。
- 2.实验任务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 di,0;di data index mov cx,5 s: mov ah,0 mov al,ds:[di] mov bl,10; div bl;al存商,ah存余数 mov ds:[10+di],al mov ds:[11+di],ah mov ah,2 mov dl,ds:[10+di] add dl,30h int 21h;ah=2时:DL为输出字符,显示输出 mov ah,2 mov dl,ds:[11+di] add dl,30h int 21h mov ah,2 mov dl," " int 21h inc di loop s mov ax,4c00h int 21h code ends end start
使用masm、link对task2.asm进行汇编、链接,得到可执行文件task2.exe。

该部分代码的作用:显示数据段中的内容 23 50 6 71 35
(ah为2时,int 21h的作用为输出dl内数据对应的字符INT 21H 指令说明及使用方法 - 暧鹅 - 博客园 (cnblogs.com))
- 3.实验任务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
使用masm、link对task3.asm进行汇编、链接,得到可执行文件task3.exe。

反汇编查看data段中数据及反汇编调试的截图

回答问题:
Question①:返回程序前data中数据:0123H 0456H 0789H 0ABCH 0DEFH 0FEDH 0CBAH 0987H
Question②:CS=076CH,SS=076BH,DS=076AH
Question③:设程code段的段地址为X,那么data段的段地址为X-2,stack段的段地址为X-1
- 4.实验任务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
使用masm、link对task4.asm进行汇编、链接,得到可执行文件task4.exe。

Debug反汇编截图

回答问题:
Question①:data段中的数据为:0123H 0456H
Question②:CS=076CH,SS=076BH,DS=076AH
Question③:设code段的段地址为X,那么data段的段地址为X-2,stack段的段地址为X-1
Question④:设段中的数据占N个字节,那么程序加载后,这段实际占有的空间为([N/16]+1)*16个字节,中括号代表向下取整(段地址必须为16的倍数)
- 5.实验任务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
使用masm、link对task5.asm进行汇编、链接,得到可执行文件task5.exe。

使用Debug调试截图

回答问题:
Question①:data段中的数据为:0123H 0456H
Question②:CS=076AH,SS=076EH,DS=076DH
Question③:设code段的段地址为X,则data段的段地址为X+3,stack段的段地址为X+4
- 6.实验任务6
- 7.实验任务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 c1 segment db 8 dup(0) c1 ends code segment start: mov ax,a mov ds,ax mov ax,b mov es,ax mov ax,c1 mov ss,ax mov sp,8 mov cx,4 mov bx,6 s: mov al,ds:[bx] add al, es:[bx] mov ah,ds:[bx+1] add ah,es:[bx+1] push ax sub bx,2 loop s mov ax,4c00h int 21h code ends end start
使用masm、link对task7.asm进行汇编、链接,得到可执行文件task7.exe。

使用Debug调试截图


由上述部分图片可以说明所编写的程序正确实现了题目的要求;
- 8.实验任务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 di,0 mov ax,b mov ss,ax mov sp,10h mov cx,8 s: push [di] add di,2 loop s mov ax,4c00h int 21h code ends end start
使用masm、link对task8.asm进行汇编、链接,得到可执行文件task8.exe。

使用Debug调试截图


由上述部分图片可以说明所编写的程序正确实现了题目的要求;

浙公网安备 33010602011771号