检测点10.1
补全程序,实现从内存1000:0000处开始执行指令。
assume cs:code
stack segment
db 16 dup (0)
stack ends
code segment
start: mov ax,stack
mov ss,ax
mov sp,16
mov ax, 1000h
push ax
mov ax, 0
push ax
retf
code ends
end start
执行reft指令时,相当于进行:
pop ip
pop cs
根据栈先进后出原则,应先将段地址cs入栈,再将偏移地址ip入栈。
检测点10.2
下面的程序执行后,ax中的数值为多少?
内存地址 机器码 汇编指令 执行后情况
1000:0 b8 00 00 mov ax,0 ax=0 ip指向1000:3
1000:3 e8 01 00 call s pop ip ip指向1000:7
1000:6 40 inc ax
1000:7 58 s:pop ax ax=6
用debug进行跟踪确认,“call 标号”是将该指令后的第一个字节偏移地址入栈,再转到标号处执行指令。
assume cs:code
code segment
start: mov ax,0
call s
inc ax
s: pop ax
mov ax,4c00h
int 21h
code ends
end start
检测点10.3
下面的程序执行后,ax中的数值为多少?
内存地址 机器码 汇编指令 执行后情况
1000:0 b8 00 00 mov ax,0 ax=0,ip指向1000:3
1000:3 9a 09 00 00 10 call far ptr s pop cs,pop ip,ip指向1000:9
1000:8 40 inc ax
1000:9 58 s:pop ax ax=8h
add ax,ax ax=10h
pop bx bx=1000h
add ax,bx ax=1010h
用debug进行跟踪确认,“call far ptr s”是先将该指令后的第一个字节段地址cs=1000h入栈,再将偏移地址ip=8h入栈,最后转到标号处执行指令。
出栈时,根据栈先进后出的原则,先出的为ip=8h,后出的为cs=1000h
检测点10.4
下面的程序执行后,ax中的数值为多少?
内存地址 机器码 汇编指令 执行后情况
1
000:0 b8 06 00 mov ax,6 ax=6,ip指向1000:3
1000:3 ff d0 call ax pop ip,ip指向1000:6
1000:5 40 inc ax
1000:6 58 mov bp,sp bp=sp=fffeh
add ax,[bp] ax=[6+ds:(fffeh)]=6+5=0bh
用debug进行跟踪确认,“call ax(16位reg)”是先将该指令后的第一个字节偏移地址ip入栈,再转到偏移地址为ax(16位reg)处执行指令。
检测点10.5
(1)下面的程序执行后,ax中的数值为多少?
assume cs:code
stack segment
dw 8 dup (0)
stack ends
code segment
start: mov ax,stack
mov ss,ax
mov sp,16
mov ds,ax
mov ax,0
call word ptr ds:[0eh]
inc ax
inc ax
inc ax
mov ax,4c00h
int 21h
code ends
end start
推算:
执行call word ptr ds:[0eh]指令时,先cs入栈,再ip=11入栈,最后ip转移到(ds:[0eh])。(ds:[0eh])=11h,执行inc ax……最终ax=3
题中特别关照别用debug跟踪,跟踪结果不一定正确,但还是忍不住去试试,看是什么结果。
根据单步跟踪发现,执行call word ptr ds:[0eh]指令时,显示ds:[0eh]=065D。
ds:0000~ds:0010不是已设置成stack数据段了嘛,不是应该全都是0的嘛。
于是进行了更详细的单步跟踪,发现初始数据段中数据确实为0,但执行完mov ss,ax;mov sp,16这两条指令后,数据段中数据发生改变。这是为什么呢?中断呗~~~~
检测点10.5
(2)下面的程序执行后,ax和bx中的数值为多少?
assume cs:codesg
stack segment
dw 8 dup(0)
stack ends
codesg segment
start:
mov ax,stack
mov ss,ax
mov sp,10h
mov word ptr ss:[0],offset s ;(ss:[0])=1ah
mov ss:[2],cs ;(ss:[2])=cs
call dword ptr ss:[0] ;cs入栈,ip=19h入栈,转到cs:1ah处执行指令
;(ss:[4])=cs,(ss:[6])=ip
nop
s: mov ax,offset s ;ax=1ah
sub ax,ss:[0ch] ;ax=1ah-(ss:[0ch])=1ah-19h=1
mov bx,cs ;bx=cs=0c5bh
sub bx,ss:[0eh] ;bx=cs-cs=0
mov ax,4c00h
int 21h
codesg ends
end start