《x86指令系统习题解答.ppt》由会员分享,可在线阅读,更多相关《x86指令系统习题解答.ppt(18页珍藏版)》请在金锄头文库上搜索。
1、第三章习题讲评3.1 已知DS=091DH,SS=1E4AH,AX=1234H,BX=0024H,CX=5678H,BP=0024HSI=0012H,DI=0032H,(09226H)=00F6H,(09228H)=1E40H,(1E4F6H)=091DH。在以上给出的环境下,试问下列指令或指令段执行后的结果如何?(1)MOV CL(1)MOV CL,BX+20HSIBX+20HSI解:解:EA= BX+20H+SI=56HEA= BX+20H+SI=56HPA=PA=DS*16+EA=91D0H+56H=9226HEA=91D0H+56H=9226HCLCL= =(09226H)=F6H(2
2、)MOVBPDI(2)MOVBPDI,CXCX解:解: EA= BP+DI=56HEA= BP+DI=56HPA=PA=SS*16+EA=1E4F6HEA=1E4F6H(1E4F6H)=(1E4F6H)= 5678H(3)LEA BX(3)LEA BX,BX+20HSIBX+20HSIMOV AXMOV AX,BX+2BX+2解:解:BX= BX+20H+ SI=0056HBX= BX+20H+ SI=0056HEA= BX+2=58HEA= BX+2=58HPA=PA=DS*16+EA=91D0H+58H=9228HEA=91D0H+58H=9228HAX=(09228H)=AX=(0922
3、8H)=1E40H(4) LDS SI,BXDI(4) LDS SI,BXDIMOVSIMOVSI,BXBX解:解:EA= BX+DI=56H, PA=EA= BX+DI=56H, PA=DS*16+EA=91D0H+56H =9226HEA=91D0H+56H =9226HSISI= =(09226H)=00F6H, DS=(09228H)=1E40HEA= SI=EA= SI=00F6H, PA= PA=DS*16+EA=EA=1E400H+00F6H=1E4F6H(1E4F6H)= BX=0024H(5)(5)XCHG CXXCHG CX,BX+32HBX+32HXCHGBX+20HSI
4、XCHGBX+20HSI,AXAX解:解:EA= BX+32H=56H, EA= BX+32H=56H, PA=PA=DS*16+EA=91D0H+56H =9226HEA=91D0H+56H =9226H(09226H)= CX=(09226H)= CX=5678H , CX=(09226H)=00F6HEA= BX+20H+SI=56H,PA=EA= BX+20H+SI=56H,PA=DS*16+EA=91D0H+56H =9226HEA=91D0H+56H =9226HAX=(09226H)=AX=(09226H)=5678H ,(09226H) = ,(09226H) = AX=AX=
5、1234H3.23.2设设DS=1000HDS=1000H,SS=2000HSS=2000H,AX=1A2BHAX=1A2BH,BX=1200HBX=1200H,CX=339AHCX=339AH,BP=1200HBP=1200H,SP=1350HSP=1350H,SI=1354HSI=1354H,(11350H)=0A5H(11350H)=0A5H,(11351H)=3CH(11351H)=3CH,(11352H)=0FFH(11352H)=0FFH,(11353H)=26H(11353H)=26H,(11354H)=52H(11354H)=52H,(11355H)=OE7H(11355H)=
6、OE7H,(126A4H)=9DH(126A4H)=9DH,(126A5H)=16H(126A5H)=16H,(21350H)=88H(21350H)=88H,(21351H)=51H(21351H)=51H下列各指令都在此下列各指令都在此环环境下境下执执行,在下列各小行,在下列各小题题的空格中填入相的空格中填入相应应各指令的各指令的执执行行结结果。果。(1)MOV AX(1)MOV AX,1352H 1352H AX=AX=解:解:AX=1352HAX=1352H(2)MOV AX(2)MOV AX,1352H 1352H ;AX=AX=解:解:PA=PA=DS*16+EA=10000HEA
7、=10000H+1352H=11352H1352H=11352H(11352H)=0FFH(11352H)=0FFH,(11353H)=26H(11353H)=26HAX=26FFHAX=26FFH(3)MOV 0150HBX(3)MOV 0150HBX,CHCH(11350H)= (11351H)=(11350H)= (11351H)=解:解: EA=BX+0150H=1350HEA=BX+0150H=1350HPA=PA=DS*16+EA=10000HEA=10000H+1350H=11350H, CH=33H1350H=11350H, CH=33H(11350H)=33H, (11351
8、H)(11350H)=33H, (11351H)的的值值不不变变 ,(11351H)=3CH(11351H)=3CH(4)(4)MOV AXMOV AX,0150HBP 0150HBP AX=_AX=_解:解:EA= BPEA= BP0150H0150H1350H1350HPA=PA=SS*16+EA=20000H+1350H=21350HEA=20000H+1350H=21350HAX=5188HAX=5188H(5)POP AX (5)POP AX ; AX=_AX=_,SP=_SP=_解:解:EA= SP=1350HEA= SP=1350HPA=PA=SS*16+EA=20000H+13
9、50H=21350HEA=20000H+1350H=21350HAX=5188H, SP=1350H+2H=1352HAX=5188H, SP=1350H+2H=1352H(6)ADDSI(6)ADDSI,CXCX(11354H)=_(11354H)=_,(11355H)=_(11355H)=_,SF=_SF=_ZF=_ZF=_, PF=_PF=_, CF=_CF=_, OF=_OF=_解:解:EA=SI=1354H, PA=DS*16+EA=10000H+1354H=11354HEA=SI=1354H, PA=DS*16+EA=10000H+1354H=11354HCX=339AH, (11
10、354H)=52HCX=339AH, (11354H)=52H,(11355H)=OE7H(11355H)=OE7H0E752H+339AH=0E752H+339AH=1 11AECH-(11355H): (11354H)1AECH-(11355H): (11354H)(11354H) =0ECH, (11355H)= 1AH(11354H) =0ECH, (11355H)= 1AH(11354H) =0ECH, (11355H)= 1AHCF=1,ZF=0,CF=1,ZF=0,PF(PF(低八位奇偶校低八位奇偶校验验) ):0ECH= 11101100B0ECH= 11101100BPF=0
11、PF=0SF(SF(最高位状最高位状态态) ),1H=0001B1H=0001BSF=0SF=0OF(OF(溢出溢出标标志志) )0E752H0E752H1110011101010010B1110011101010010B339AH=11001110011010B339AH=11001110011010B 11111001110101001010011101010010+ 11001110011010+ 11001110011010 10001101011101100 10001101011101100(7)SUB BH(7)SUB BH,0150HBXSI0150HBXSIBH=_BH=_,
12、SF=_SF=_,ZF=_ZF=_,PF=_PF=_,CF=_CF=_,0F=_0F=_解:解:EA=0150H+BX+SI=26A4HEA=0150H+BX+SI=26A4H;PA=DS*16+EA=10000H+26A4H=126A4HPA=DS*16+EA=10000H+26A4H=126A4H;(126A4H)=9DH,BH=12H(126A4H)=9DH,BH=12HBH=75H, SF=0,ZF=0,PF=0, CF=1 ,OF=0BH=75H, SF=0,ZF=0,PF=0, CF=1 ,OF=0(8)INC BYTE PTR 0152HBX(8)INC BYTE PTR 015
13、2HBX(11352H)=_(11352H)=_,(11353H)=_(11353H)=_,CF=_CF=_解:解:EA=0152H+ BX= 1352H,PA=DS*16+EA=11352,EA=0152H+ BX= 1352H,PA=DS*16+EA=11352, (11352H)=0FFH, (11352H)=0FFH, (11352H)=00H, (11353H)= 26H, (11352H)=00H, (11353H)= 26H, 不影响不影响CFCF(9)INC WORD PTR 0152HBX(9)INC WORD PTR 0152HBX(11352H)=_(11352H)=_,
14、(11353H)=_(11353H)=_,CF=_CF=_解:解:EA=0152H+ BX= 1352H, PA=DS*16+EA=11532,EA=0152H+ BX= 1352H, PA=DS*16+EA=11532, (11352H)=0FFH, (11353H)= 26H (11352H)=0FFH, (11353H)= 26H(11352H)=00H, (11353H)= 27H, 不影响不影响CF (10)SAR BYTE PTR 0150HBX(10)SAR BYTE PTR 0150HBX,1 1(11350H) =_(11350H) =_, CF=_CF=_, OF=_OF=
15、_解:解:EA=BX+0150H=1350HEA=BX+0150H=1350HPAPADS*16+EA=11350H,DS*16+EA=11350H, (11350H)=0A5H= 10100101B (11350H)=0A5H= 10100101B11010010B=0D2H, CF=1,OF=011010010B=0D2H, CF=1,OF=0( (当移位数当移位数为为1 1是,最高位不是,最高位不变则变则OF=0)OF=0)(11)SAL BYTE PTR 0150HBX(11)SAL BYTE PTR 0150HBX,1 1(11350H)=_(11350H)=_,CF=_CF=_,O
16、F=_OF=_解:解:EA=BX+0150H=1350H,PA=DS*16+EA=11350,EA=BX+0150H=1350H,PA=DS*16+EA=11350,(11350H)=0A5H= 10100101B(11350H)=0A5H= 10100101B 01001010B=4AH, CF=1,OF=1 01001010B=4AH, CF=1,OF=13、3 设下列各转移指令的第一字节在内存中的地址为CS=2000H和IP=016EH,且环境均为DS=6000H,BX=16C0H,(616C0H)=46H,(616C1H)=01H,(616C2H)=00H,(616C3H)=30H,(
17、61732H)=70H,(61733H)=17H。写出下列各无条件转移指令执行后CS和IP值。个指令左首的16进制编码是该指令的机器码。指令中的目的地址用相应的标号表示。(1)EBE7 JMP SHOURT AGAIN(2)E90016 JMP NEARPTR OTHER(3)E3 JMP BX(4)EA46010010 JMP FAR PROB(5)FF67 JMP WORD PTR 0072HBX (6)FFEB JMP DWORD PTR BX解:解:(1)E7补码为补码为-19,IP目标目标=IP源源+2+EA(即(即-19) =016EH+2-19=0157H 因为段内寻址,所以因为
18、段内寻址,所以cs=2000H不变不变(2)IP目标目标=IP源源+3 +EA=016EH+3+1600H=1771H 因为段内寻址因为段内寻址 所以所以cs=2000H不变不变(3) IP=16C0H, 因为段内寻址因为段内寻址 所以所以cs=2000H不变不变(4)段间寻址,有机器码可看出)段间寻址,有机器码可看出IP=0146H CS=3000H(5)段内寻址,所以)段内寻址,所以CS=2000H不变不变 DS*16+0072H+BX=61732H (61732H)=70H,(,(61733H)=17H IP=1770H(6)PA=DS*16+BX=60000H+16C0H=616C0H
19、 (616C0H)=46H (616C1H)=01H IP=0146H (616C2H)=00H (616C3H)=30H CS=3000H3 34 4 阅读阅读下列各小下列各小题题的指令序列,在后面空格中填入的指令序列,在后面空格中填入 该该指令序列的指令序列的执执行行结结果。果。(1) MOV BL(1) MOV BL,85H85H MOV AL MOV AL,17H17H ADD AL ADD AL,BLBL DAA DAAAL=_AL=_, BL=_BL=_, CF=_CF=_解:解:17H+85H17H+85H9CH9CHALALDAA DAA 压缩压缩的的BCDBCD码码加法十加法
20、十进进制制调调整指令。整指令。(AL(AL的低的低4 4位位99或或AF=1AF=1,ALALAL+06H,AFAL+06H,AF1;1;AFAF是是辅辅助助进进位位标标志志用以用以标标志志D3D3向向D4D4的的进进位位ALAL的高的高4 4位位99或或CF=1CF=1,ALALAL+60H,CFAL+60H,CF1;1;)AL=9CH+ 06H=0A2HAL=9CH+ 06H=0A2HAL=0A2H+60H=AL=0A2H+60H=02H02H, , BL=85HBL=85H CF=1 CF=1(2) MOV AX(2) MOV AX,BXBX;NOT AXNOT AX; ADD AXAD
21、D AX,BXBX; lNClNC AX AXAX=_AX=_,CF=_CF=_解:解:INCINC不影响不影响标标志位志位 AX=0000HAX=0000H, CF=0CF=0(3)MOV AX(3)MOV AX,0FF60H 0FF60H ; STC STC ; MOV DXMOV DX,96 96 XOR DH XOR DH,0FFH 0FFH ; SBB AX DXSBB AX DXAX=_AX=_,CF=_CF=_解:解:XOR XOR 命令命令 会使会使 CFCF0,OF0,OF0 096=60H96=60H,AX=0000H, CF=0AX=0000H, CF=0(4)MOV B
22、X(4)MOV BX,0FFFEH 0FFFEH ; MOV CL,2MOV CL,2;SAR BX,CLSAR BX,CLBX=_BX=_,CF=_CF=_解:解:0FFFEH=1111111111111110B0FFFEH=1111111111111110B1111111111111111B,CF=01111111111111111B,CF=01111 1111 11111111 11111111 1111B,CF=1 1111B,CF=13 35 5 阅读阅读分析下列指分析下列指令序列令序列ADD AXADD AX,BXBXJNO JNO LlLlJNO L2JNO L2SUB AXSU
23、B AX,BXBXJNC L3JNC L3JNO L4JNO L4JMP L5 JMP L5 (1)AX=14C6H(1)AX=14C6H,BX=80DCH BX=80DCH 解:解:ADD AXADD AX,BXBXOF=0,CF=0OF=0,CF=0; L1L1(2)AX=0B568H(2)AX=0B568H,BX=5487HBX=5487H解:解:ADD AXADD AX,BXBXOF=0,CF=1OF=0,CF=1; L1L1(3)AX=42C8H(3)AX=42C8H,BX=608DHBX=608DH解:解:ADD AXADD AX,BX BX CF=0 CF=0 ,OF=1, AX
24、=0AC55HOF=1, AX=0AC55HSUB AXSUB AX,BXBX;CF=0CF=0,OF=0OF=0;L3L3(4) AX=0D023H(4) AX=0D023H,BX=9FDOHBX=9FDOH解:解:ADD AXADD AX,BX BX OF=1,CF=1OF=1,CF=1,AX=6FF3HAX=6FF3HSUB AXSUB AX,BX BX ;CF=1,OF=1CF=1,OF=1;L5L5(5)AX=9FDOH(5)AX=9FDOH,BX=0D023HBX=0D023H解:解:ADD AXADD AX,BX BX OF=1,CF=1OF=1,CF=1,AX=6FF3HAX=
25、6FF3HSUB AXSUB AX,BX BX ;CF=1,OF=1CF=1,OF=1;L5L53.6 AND AL,AL JZ BRCHl RCR AL,1 JZ BRCH2 RCL AL,1 INC AL JZ BRCH3上述程序运行后,试回答:(1)当AL =00H时, 程序转向BRCHl(2)当AL =01H时, 程序转向BRCH2(3)当AL =0FFH时, 程序转向BRCH337完成下列操作,选用什么指令: (1)将AX的内容减去0520H,和上次运算的借位; SBB AX,0520H (2)将变量名TABL的段地址送AX。 MOV AX SEG TABL3.8 D1 DB 20H
26、 DUP(?) D2 DW D1请写出用一条指令实现取D1的偏移地址 SI中的三种方法。 (A) LEA SI,D1 (B) MOV SI,OFFSET D1 (C) MOV SI,D2 3.9 程序段1 程序段2 MOV AX , 147BH MOV AX , 99D8H MOV BX , 80DCH MOV BX , 9847H ADD AX , BX SUB AX , BX JNO L1 JNC L3 JNC L2 JNO L4上述两个程序段执行后,分别转移到哪里?解:1) L1 2) L33.10 MOV BX , 0FFH AND BX , 0FFFH OR BX , 0F0FH X
27、OR BX , 00FFH上述程序段运行后,BX= 0F00H,CF= 0 (注意:对于8086 的加法和减法操作,使用CF 来标识将两个操作数看成无符号数时计算是否发生了溢出,而OF 则标识将两个操作数看成有符号数时的情况。计算CF 位时,加法操作是直接将最高位的进位赋给CF,而对于减法操作而言,转换后的补码加法有进位表示实际进行的减法没有借位(即没有溢出),因此需要将最高位进位取反以后赋给CF;对于OF 位的计算则是相同的,通过将最高位的进位和次高位的进位进行异或运算,结果赋给OF(当然也可以使用双符号位来进行计算)。当然对于减法操作而言,我们也可以简单地认为:对于CF 位,将减数与被减数都看成无符号数,如果减数被减数,则CF=1,否则CF 为0;对于OF 位,若两个数的符号相反,而结果的符号与减数相同则OF=1,其他情况OF=0。)3.11 CMP AX , BX JGE NEXT XCHG AX , BX NEXT: CMP AX , CX JGE DONE XCHG AX , CX DONE: . 试回答:试回答:(1)上述程序段执行后,原有)上述程序段执行后,原有AX 、BX 、CX中最大数存放中最大数存放在哪个寄存器中?在哪个寄存器中? 最大数在最大数在AX中中(2)这)这3个数是带符号数还是无符号数?个数是带符号数还是无符号数? 是带符号数是带符号数