实验8

分析下面的程序,在运行前思考:这个程序可以正确返回吗?运行后再思考:为什么是这种结果?通过这个程序加深对相关内容的理解。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
assume cs:codesg
codesg segment
mov ax,4c00h
int 21h
start: mov ax,0
s: nop
nop
mov di,offset s
mov si,offset s2
mov ax,cs:[si]
mov cs:[di],ax
s0: jmp short s
s1: mov ax,0
int 21h
mov ax,0
s2: jmp short s1
nop
codesg ends
end start

分析流程:这一步作用是将[si]的机器码写入到[di]中,而[si]对应的机器码是第16行jmp short s1,正好覆盖掉第6行和第7行的nop
start: mov ax,0 ip:0005
s: nop
nop
mov di,offset s ip:000A
mov si,offset s2 ip:000D
mov ax,cs:[si] ip:0010
mov cs:[di],ax ip:0013

然后开始执行第12行的jmp short s,也就是回到了第6行处,但是第6行和第7行机器码已经被替换成为jmp short s1,而jmp short s1对应着IP = 0020 (IP位移) = 0018H - 0022H = -10D 机器码为EBF6。也就是将IP向前移10个字节即跳转到第三行mov ax,4c00h