实验8
1. 实践9.1节内容(p176页)
assume cs:codesg
codesg segment
s:mov ax,bx ;要复制的指令,机器码占两个字节
mov si,offset s ;s标记的指令是代码段中的第一条指令,偏移地址为0
mov di,offset s0 ;s0标记要粘贴的地址,相当于mov di,0e
mov ax,cs:[si] ;指令的机器码通过ax传到要粘贴的地址
mov cs:[di],ax
s0:nop
nop
mov ax,4c00h
int 21h
codesg ends
end s
用Debug查看指令
![](https://img-blog.csdnimg.cn/img_convert/caf15d56950602d2ac5f8c41c8196649.png)
![](https://img-blog.csdnimg.cn/img_convert/4ae8a9286f2628bfd3fd45c62765720c.png)
分析并回答下列问题
① s和s0处的指令所在的内存单元的地址是多少?
s: cs:offset s s0: cs:offset s0
② 将s处的指令复制到s0处,就是将cs:offset s处的数据复制到cs:offset s0处吗? √
③ 要复制数据有多长? 2个字节
2. 实践9.3节内容(p177~178页)
(1)编辑、编译、连接程序9.1
assume cs:codesg
codesg segment
start:mov ax,0 ;初始化ax
jmp short s ;指令跳转到s标号对应的指令
add ax,1
s:inc ax
mov ax,4c00h
int 21h
codesg ends
end start
用Debug查看程序9.1指令
![](https://img-blog.csdnimg.cn/img_convert/9558e0fd0d4fdace102112d00d9ffaaa.png)
(2)编辑、编译、连接程序9.2
assume cs:codesg
codesg segment
start:mov ax,0
mov bx,0
jmp short s ;指令跳转到s标号对应的指令
add ax,1
s:inc ax
mov ax,4c00h
int 21h
codesg ends
end start
用Debug查看程序9.2指令
![](https://img-blog.csdnimg.cn/img_convert/73f12e303033ba2bebe5aced85124b8a.png)
3. 实践9.4节内容(p180~181页)
编辑、编译、连接程序9.3
assume cs:codesg
codesg segment
start:mov ax,0
mov bx,0
jmp far ptr s ;远转移指令跳转到s标号对应的指令
db 256 dup(0)
s:add ax,1
inc ax
mov ax,4c00h
int 21h
codesg ends
end start
用Debug查看程序9.3指令
![](https://img-blog.csdnimg.cn/img_convert/7de034084df62a730115d6c5f760751a.png)
4. 实践9.6节内容(p183~184页)
(1)补全检测点9.1中程序1
assume cs:code
data segment
db 8 dup(0)
data ends
code segment
start:mov ax,data
mov ds,ax
mov bx,0
jmp word ptr [bx+1] ;执行后(ip)=(ds:[bx+1])即(ip)=(ds:[1])
code ends
end start
用Debug查看检测点9.1程序1
![](https://img-blog.csdnimg.cn/img_convert/154e411268d72cc25f7f5897ee68e30b.png)
可以看到程序执行完jmp word ptr [bx+1]后ip跳转到0000h,对应的指令为mov ax,076ah
(2)补全检测点9.1中程序2
data segment
dd 12345678H
data ends
code segment
start:
mov ax, data
mov ds, ax
mov bx, 0
mov [bx], bx ;使得(ds:[bx])=(bx),即(ds:[0])=0
mov [bx+2], cs ;使得(ds:[bx+2])=(cs),即(ds:[2])=指令段地址的值
jmp dword ptr ds:[0] ;执行后(ip)=(ds:[0000h])=0,(cs)=(ds:[0002h])
code ends
end start
用Debug查看检测点9.1程序2
![](https://img-blog.csdnimg.cn/img_convert/edbf80120a0ed4d99b82ab4ab40df528.png)
5. 实践9.7节内容(p184~185页)
(1)补全检测点9.2中程序
assume cs:code
code segment
start: mov ax,2000H
mov ds,ax
mov bx,0
s: mov cl,[bx] ;(cl)=(ds:[0])
mov ch,0
jcxz ok ;当cx=0跳转到ok
inc bx ;没有跳转执行下面代码
jmp short s
ok: mov dx,bx
mov ax,4c00h
int 21h
code ends
end start
用Debug查看检查点9.2程序
![](https://img-blog.csdnimg.cn/img_convert/6ec0915dfb258185be62f046279fce37.png)
![](https://img-blog.csdnimg.cn/img_convert/d32bc00d1c09847fc04c96eb8d185a1e.png)
6. 实践9.8节内容(p185~186页)
补全检查点9.3中程序
assume cs:code
code segment
start:
mov ax,2000h
mov ds,ax
mov bx,0
s:mov cl,[bx] ;(cl)=(ds:[bx])
mov ch,0 ;(ch)=0
inc cx ;(cx)+1
inc bx ;偏移地址+1
loop s
ok:dec bx ;(bx)-1,得到2000H段 中第一个值为0的字节
mov dx,bx ;将存在bx中的结果存到dx中
mov ax,4c00h
int 21h
code ends
end start
用Debug查看检查点9.3程序
![](https://img-blog.csdnimg.cn/img_convert/42ec5504c37fc3e3b94a2fc205f10ae8.png)
![](https://img-blog.csdnimg.cn/img_convert/07c7ed819ebfbf7d2ac20fff249bb8a3.png)
7. 实验8 分析一个奇怪的程序(p187页)
用Debug查看程序
![](https://img-blog.csdnimg.cn/img_convert/d238a5612bc611bdb9f727a6424d24e3.png)
执行程序后指令机器码。可见由于复制的是指令的机器码,在cs:[0020],jmp short s1 指令机器码为EBF6,F6指(ip)=(ip)-10,在cs:[0020]跳转到s段,而在cs:[0008]跳转到cs:[0000]直接执行中断指令。
![](https://img-blog.csdnimg.cn/img_convert/b6152ba28335283b0c39d33b9d5dea90.png)
8. 实验9 根据材料编程(p187~p198页)
assume cs:code,ds:data,ss:stack
data segment
db 'welcome to masm!' ;ds:[si]
db 00000010B ;绿色 ds:[bx]
db 00100100B ;绿底红字
db 01110001B ;白底蓝字
data ends
stack segment
db 128 dup(0)
stack ends
code segment
start:mov ax,stack
mov ss,ax
mov sp,128 ;指向空栈栈顶
mov ax,data
mov ds,ax
mov bx,0B830H
mov es,bx ;数据传到显示缓冲区es:[di]
mov si,0 ;定位数据段中字符ASCII码的偏移地址
mov di,160*10+30*2
mov bx,0010h ;定位数据段中字符属性的偏移地址
mov dx,0
mov cx,3 ;三行外循环三次
s0:push cx ;压栈保存
push si
push di
mov cx,16 ;16个字符内循环16次
mov dh,ds:[bx] ;长度为一个字的寄存器暂存字符的ASCII码和属性,高地址存放属性
s:mov dl,ds:[si] ;低地址存放对应ASCII码
mov es:[di],dx ;把暂存在dx中的字符传到显示缓冲区
add di,2 ;移动到下一个字符对应的显示缓冲区
inc si ;移动到数据段下一个字符
loop s
pop di
pop si
pop cx
add di,160 ;移动到下一行字符对应的显示缓冲区
inc bx ;移动到数据段中存放下一行字符属性的内存单元
loop s0
mov ax,4c00h
int 21h
code ends
end start
用Debug查看程序
![](https://img-blog.csdnimg.cn/img_convert/e236f75b8d060f7e3b54c82b41f9b11b.png)