x86指令系統(tǒng)習(xí)題解答.ppt
第三章習(xí)題講評(píng),3.1 已知DS=091DH,SS=1E4AH,AX=1234H,BX=0024H,CX=5678H,BP=0024H SI=0012H,DI=0032H,(09226H)=00F6H,(09228H)=1E40H,(1E4F6H)=091DH。 在以上給出的環(huán)境下,試問下列指令或指令段執(zhí)行后的結(jié)果如何?,(1)MOV CL,BX+20HSI 解:EA= BX+20H+SI=56H PA=DS*16+EA=91D0H+56H=9226H CL=(09226H)=F6H (2)MOVBPDI,CX 解: EA= BP+DI=56H PA=SS*16+EA=1E4F6H (1E4F6H)= 5678H,(3)LEA BX,BX+20HSI MOV AX,BX+2 解:BX= BX+20H+ SI=0056H EA= BX+2=58H PA=DS*16+EA=91D0H+58H=9228H AX=(09228H)=1E40H (4) LDS SI,BXDI MOVSI,BX 解:EA= BX+DI=56H, PA=DS*16+EA=91D0H+56H =9226H SI=(09226H)=00F6H, DS=(09228H)=1E40H EA= SI=00F6H, PA=DS*16+EA=1E400H+00F6H=1E4F6H (1E4F6H)= BX=0024H,(5) XCHG CX,BX+32H XCHGBX+20HSI,AX 解:EA= BX+32H=56H, PA=DS*16+EA=91D0H+56H =9226H (09226H)= CX=5678H , CX=(09226H)=00F6H EA= BX+20H+SI=56H,PA=DS*16+EA=91D0H+56H =9226H AX=(09226H)=5678H ,(09226H) = AX=1234H,3.2設(shè)DS=1000H,SS=2000H,AX=1A2BH,BX=1200H,CX=339AH,BP=1200H,SP=1350H,SI=1354H,(11350H)=0A5H,(11351H)=3CH,(11352H)=0FFH,(11353H)=26H,(11354H)=52H,(11355H)=OE7H,(126A4H)=9DH,(126A5H)=16H,(21350H)=88H, (21351H)=51H 下列各指令都在此環(huán)境下執(zhí)行,在下列各小題的空格中填入相應(yīng)各指令的執(zhí)行結(jié)果。 (1)MOV AX,1352H AX= 解:AX=1352H,(2)MOV AX,1352H ;AX= 解:PA=DS*16+EA=10000H+1352H=11352H (11352H)=0FFH,(11353H)=26H AX=26FFH (3)MOV 0150HBX,CH (11350H)= (11351H)= 解: EA=BX+0150H=1350H PA=DS*16+EA=10000H+1350H=11350H, CH=33H (11350H)=33H, (11351H)的值不變 ,(11351H)=3CH,(4) MOV AX,0150HBP AX=_ 解:EA= BP0150H1350H PA=SS*16+EA=20000H+1350H=21350H AX=5188H,(5)POP AX ; AX=_,SP=_ 解:EA= SP=1350H PA=SS*16+EA=20000H+1350H=21350H AX=5188H, SP=1350H+2H=1352H,(6)ADDSI,CX (11354H)=_,(11355H)=_,SF=_ ZF=_, PF=_, CF=_, OF=_ 解:EA=SI=1354H, PA=DS*16+EA=10000H+1354H=11354H CX=339AH, (11354H)=52H,(11355H)=OE7H 0E752H+339AH=11AECH-(11355H): (11354H) (11354H) =0ECH, (11355H)= 1AH,(11354H) =0ECH, (11355H)= 1AH CF=1,ZF=0, PF(低八位奇偶校驗(yàn)):0ECH= 11101100BPF=0 SF(最高位狀態(tài)),1H=0001BSF=0 OF(溢出標(biāo)志) 0E752H1110011101010010B 339AH=11001110011010B 1110011101010010 + 11001110011010 10001101011101100,(7)SUB BH,0150HBXSI BH=_,SF=_,ZF=_,PF=_,CF=_,0F=_ 解:EA=0150H+BX+SI=26A4H;PA=DS*16+EA=10000H+26A4H=126A4H; (126A4H)=9DH,BH=12H BH=75H, SF=0,ZF=0,PF=0, CF=1 ,OF=0,(8)INC BYTE PTR 0152HBX (11352H)=_,(11353H)=_,CF=_ 解:EA=0152H+ BX= 1352H,PA=DS*16+EA=11352, (11352H)=0FFH, (11352H)=00H, (11353H)= 26H, 不影響CF (9)INC WORD PTR 0152HBX (11352H)=_,(11353H)=_,CF=_ 解:EA=0152H+ BX= 1352H, PA=DS*16+EA=11532, (11352H)=0FFH, (11353H)= 26H (11352H)=00H, (11353H)= 27H, 不影響CF,(10)SAR BYTE PTR 0150HBX,1 (11350H) =_, CF=_, OF=_ 解:EA=BX+0150H=1350H PADS*16+EA=11350H, (11350H)=0A5H= 10100101B 11010010B=0D2H, CF=1,OF=0 (當(dāng)移位數(shù)為1是,最高位不變則OF=0) (11)SAL BYTE PTR 0150HBX,1 (11350H)=_,CF=_,OF=_ 解:EA=BX+0150H=1350H,PA=DS*16+EA=11350, (11350H)=0A5H= 10100101B 01001010B=4AH, CF=1,OF=1,3、3 設(shè)下列各轉(zhuǎn)移指令的第一字節(jié)在內(nèi)存中的地址為CS=2000H和IP=016EH,且環(huán)境均為DS=6000H,BX=16C0H,(616C0H)=46H,(616C1H)=01H,(616C2H)=00H,(616C3H)=30H,(61732H)=70H,(61733H)=17H。寫出下列各無條件轉(zhuǎn)移指令執(zhí)行后CS和IP值。個(gè)指令左首的16進(jìn)制編碼是該指令的機(jī)器碼。指令中的目的地址用相應(yīng)的標(biāo)號(hào)表示。 (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補(bǔ)碼為-19,IP目標(biāo)=IP源+2+EA(即-19) =016EH+2-19=0157H 因?yàn)槎蝺?nèi)尋址,所以cs=2000H不變 (2)IP目標(biāo)=IP源+3 +EA=016EH+3+1600H=1771H 因?yàn)槎蝺?nèi)尋址 所以cs=2000H不變 (3) IP=16C0H, 因?yàn)槎蝺?nèi)尋址 所以cs=2000H不變 (4)段間尋址,有機(jī)器碼可看出IP=0146H CS=3000H (5)段內(nèi)尋址,所以CS=2000H不變 DS*16+0072H+BX=61732H (61732H)=70H,(61733H)=17H IP=1770H (6)PA=DS*16+BX=60000H+16C0H=616C0H (616C0H)=46H (616C1H)=01H IP=0146H (616C2H)=00H (616C3H)=30H CS=3000H,34 閱讀下列各小題的指令序列,在后面空格中填入 該指令序列的執(zhí)行結(jié)果。 (1) MOV BL,85H MOV AL,17H ADD AL,BL DAA AL=_, BL=_, CF=_ 解:17H+85H9CHAL DAA 壓縮的BCD碼加法十進(jìn)制調(diào)整指令。 (AL的低4位9或AF=1,ALAL+06H,AF1; AF是輔助進(jìn)位標(biāo)志用以標(biāo)志D3向D4的進(jìn)位 AL的高4位9或CF=1,ALAL+60H,CF1;) AL=9CH+ 06H=0A2H AL=0A2H+60H=02H, BL=85H CF=1,(2) MOV AX,BX;NOT AX; ADD AX,BX; lNC AX AX=_,CF=_ 解:INC不影響標(biāo)志位 AX=0000H, CF=0 (3)MOV AX,0FF60H ; STC ; MOV DX,96 XOR DH,0FFH ; SBB AX DX AX=_,CF=_ 解:XOR 命令 會(huì)使 CF0,OF0 96=60H,AX=0000H, CF=0 (4)MOV BX,0FFFEH ; MOV CL,2;SAR BX,CL BX=_,CF=_ 解:0FFFEH=1111111111111110B 1111111111111111B,CF=0 1111 1111 1111 1111B,CF=1,35 閱讀分析下列指令序列 ADD AX,BX JNO Ll JNO L2 SUB AX,BX JNC L3 JNO L4 JMP L5,(1)AX=14C6H,BX=80DCH 解: ADD AX,BX OF=0,CF=0; L1 (2)AX=0B568H,BX=5487H 解: ADD AX,BX OF=0,CF=1; L1,(3)AX=42C8H,BX=608DH 解:ADD AX,BX CF=0 ,OF=1, AX=0AC55H SUB AX,BX;CF=0,OF=0;L3 (4) AX=0D023H,BX=9FDOH 解:ADD AX,BX OF=1,CF=1,AX=6FF3H SUB AX,BX ;CF=1,OF=1;L5 (5)AX=9FDOH,BX=0D023H 解:ADD AX,BX OF=1,CF=1,AX=6FF3H SUB AX,BX ;CF=1,OF=1;L5,3.6 AND AL,AL JZ BRCHl RCR AL,1 JZ BRCH2 RCL AL,1 INC AL JZ BRCH3 上述程序運(yùn)行后,試回答:,(1)當(dāng)AL =00H時(shí), 程序轉(zhuǎn)向BRCHl (2)當(dāng)AL =01H時(shí), 程序轉(zhuǎn)向BRCH2 (3)當(dāng)AL =0FFH時(shí), 程序轉(zhuǎn)向BRCH3,37完成下列操作,選用什么指令: (1)將AX的內(nèi)容減去0520H,和上次運(yùn)算的借位; SBB AX,0520H (2)將變量名TABL的段地址送AX。 MOV AX SEG TABL 3.8 D1 DB 20H DUP(?) D2 DW D1 請(qǐng)寫出用一條指令實(shí)現(xiàn)取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 上述兩個(gè)程序段執(zhí)行后,分別轉(zhuǎn)移到哪里? 解:1) L1 2) L3,3.10 MOV BX , 0FFH AND BX , 0FFFH OR BX , 0F0FH XOR BX , 00FFH 上述程序段運(yùn)行后,BX= 0F00H,CF= 0 (注意:對(duì)于8086 的加法和減法操作,使用CF 來標(biāo)識(shí)將兩個(gè)操作數(shù)看成無符號(hào)數(shù)時(shí)計(jì)算是否發(fā)生了溢出,而OF 則標(biāo)識(shí)將兩個(gè)操作數(shù)看成有符號(hào)數(shù)時(shí)的情況。計(jì)算CF 位時(shí),加法操作是直接將最高位的進(jìn)位賦給CF,而對(duì)于減法操作而言,轉(zhuǎn)換后的補(bǔ)碼加法有進(jìn)位表示實(shí)際進(jìn)行的減法沒有借位(即沒有溢出),因此需要將最高位進(jìn)位取反以后賦給CF;對(duì)于OF 位的計(jì)算則是相同的,通過將最高位的進(jìn)位和次高位的進(jìn)位進(jìn)行異或運(yùn)算,結(jié)果賦給OF(當(dāng)然也可以使用雙符號(hào)位來進(jìn)行計(jì)算)。當(dāng)然對(duì)于減法操作而言,我們也可以簡(jiǎn)單地認(rèn)為:對(duì)于CF 位,將減數(shù)與被減數(shù)都看成無符號(hào)數(shù),如果減數(shù)被減數(shù),則CF=1,否則CF 為0;對(duì)于OF 位,若兩個(gè)數(shù)的符號(hào)相反,而結(jié)果的符號(hào)與減數(shù)相同則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)上述程序段執(zhí)行后,原有AX 、BX 、CX中最大數(shù)存放在哪個(gè)寄存器中? 最大數(shù)在AX中 (2)這3個(gè)數(shù)是帶符號(hào)數(shù)還是無符號(hào)數(shù)? 是帶符號(hào)數(shù),