codesg segment
mov ax,4c00h // ip=0
int 21h
start:
mov ax , 0 // ip=5 ,第一条执行的指令
s: nop // ip=8
nop
mov di, offset s // ip=A
mov si, offset s2
mov ax, cs:[si]
mov cs:[di], ax //上面这四句将 s2处的指令 “jmp short s1"(2个字节复制到s处),特别注意,"jmp short s1"转化为机器码后跳转参数值是一个
//偏移量,仔细看代码可以知道这个偏移量是-8(ip从0020H跳转到0018H), 所以复制到s处后,s处实际的机器码也是跳-8,而s处的ip=8,
// 跳转后就跳到了 ip=0处,也就是codesg段的第一个字节,执行"mov ax, 4c00h" 和 "int 21h"后,程序结束
s0: jmp short s
s1: mov ax, 0 // ip=0018H
int 21h
mov ax, 0
s2: jmp short s1 //ip=0020H
nop
codesg ends
end 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 //跳转到s处
s://此处现在是2个字节的跳转,跳转到了ip=0的地方
mov ax,4c00h
int 21h