4.2指出下列指令是否有错,并说明理由。(1)MOV[DI],[SI];两个内存单元之间不能直接传送数据(2)MOVCS,AX;CS段寄存器不能作为目的操作数(3)MOV1200,AX;立即数不能作为目的操作数(4)MOVDS,CS;段寄存器之间不能直接传送(5)POPCS;CS不能作为弹栈指令的目标(6)MOVCL,AX;两个操作数的类型必须相同(7)MOV[5000H],[1000H];两个内存单元之间不能直接传送数据4.3在8086中,堆栈操作是字操作还是字节操作?已知SS=1050H,SP=0006H,AX=1234H,若对AX执行压栈操作(即执行PUSHAX);试问AX的内容存放在何处?答:是字操作;AX的内容存放到10504H字单元,即:12H→(10505H);34H→(10504H)数据传送指令能够完成下列操作数的传送任务。立即数存储器段寄存器CS,DS,ES,SS通用寄存器组AX,BX,CX,DXBP,SP,SI,DI(CS不能作目的寄存器)4.5编程求AX累加器和BX寄存器中两个无符号数之差的绝对值,结果放内存(2800H)单元中。解法二:SUBAX,BXJNCOKADDAX,BX;原AXSUBBX,AX;反相减MOVAX,BXOK:MOV[2800H],AX解法一:SUBAX,BXJNCOKNEGAXOK:MOV[2800H],AX4.6若有两个4字节的无符号数相加,这两个数分别存放在2000H和3000H开始的存储单元,将所求的和存放在2000H开始的内存单元中,试编制程序。解法一:MOVBX,3000HMOVDI,2000HMOVAX,[BX]MOVDX,[BX+2]ADD[DI],AX;低字相加ADC[DI+2],DX解法二:MOVAX,[3000H]MOVDX,[3002H]ADD[2000H],AXADC[2002H],DX解法三:MOVSI,3000HMOVDI,2000HMOVAX,[DI]MOVDX,[DI+2]ADDAX,[SI]ADCDX,[SI+2]MOV[DI],AXMOV[DI+2],DX4.7用两种方法写出从88H端口读入信息的指令,再用两种方法写出从44H端口输出数据56H的指令。解:从88H端口读入信息(1)INAL,88H(2)MOVDX,88HINAL,DX解:从44H端口输出56H(1)MOVAL,56HOUT44H,AL(2)MOVAL,56HMOVDX,44HOUTDX,AL4.19指出以下四条指令的作用(HEX为数据段的一个变量名)⑴MOVBX,HEX;取变量HEX的内容→BX⑵LEABX,HEX;取变量HEX的有效地址→BX⑶MOVBX,OFFSETHEX;取变量HEX的偏移量→BX⑷MOVBX,SEGHEX;取变量HEX的段地址→BX4.20下面是变量定义伪指令,DATASEGMENTBUFDW3DUP(5,2DUP(8))CEDDB‘Welcometoyou’,0DH,0AH,‘$’ADDRDWBUFCOUNTEQU$-CEDDATAENDS问:⑴按内存单元存放的先后次序,按字节写出数据段中的数据⑵说明对BUF,CED,ADDR等变量施行TYPE,LENGTH,SIZE运算后,其结果分别为多少?⑶COUNT的值为多少?解:按内存单元存放的先后次序,按字节写出数据段中的数据:05H,00H,08H,00H,08H,00H,05H,00H,08H,00H,08H,00H,05H,00H,08H,00H,08H,00H,57H,65H,6CH,63H,6FH,6DH,65H,20H,74H,6FH,20H,79H,6FH,75H,0DH,0AH,24H,00H,00HBUFCEDADDRTYPE212LENGTH311SIZE612(2)(1)COUNT=$-CED=19(3)4.22编写一个将16位二进制数转换成BCD码数的程序。DATASEGMENT;解法一HEXDW9A48HBCDDB5DUP(?)DATAENDSSTACKSEGMENTDB256DUP(?)TOPEQU$-STACKSTACKENDSCODESEGMENTASSUMECS:CODE,DS:DATA,SS:STACKSTART:MOVAX,DATAMOVDS,AXMOVAX,STACKMOVSS,AXMOVSP,TOPMOVBX,OFFSETBCDMOVAX,HEXMOVDX,0MOVCX,10000DIVCX;DX:AX÷CX→AX,;余数→DXMOV[BX+4],AL;万位数(AH必为0)MOVAX,DXMOVDX,0MOVCX,1000DIVCX;DX:AX÷CX→AX,;余数→DXMOV[BX+3],AL;千位数MOVAX,DXMOVCL,100DIVCL;AX÷CL→AL,余数→AHMOV[BX+2],AL;百位数MOVAL,AHMOVAH,0MOVCL,10DIVCLMOV[BX+1],AL;十位数MOV[BX],AH;个位数HLTCODEENDSENDSTARTDATASEGMENT;解法二HEXDW9A48HBCDDB5DUP(?)DATAENDSSTACKSEGMENTDB256DUP(?)TOPLABELWORDSTACKENDSCODESEGMENTASSUMECS:CODE,DS:DATA,SS:STACKSTART:MOVAX,DATAMOVDS,AXMOVAX,STACKMOVSS,AXMOVSP,OFFSETTOPMOVBX,OFFSETBCDMOVAX,HEXMOVSI,10MOVCX,5LP1:MOVDX,0DIVSI;DX:AX÷SI→AX,余数→DXMOV[BX],DL;第一次保存的是个位数INCBXLOOPLP1HLTCODEENDSENDSTART4.23编写一个将5位BCD码数(小于65536)转换成二进制数的程序。DATASEGMENTBCDDB7,4,3,0,5;BCD=50347HEXDW0DATAENDSCODESEGMENTASSUMECS:CODE,DS:DATASTART:MOVAX,DATAMOVDS,AXLEABX,BCDMOVAL,[BX+4];万位数MOVAH,0MOVCX,10000MULCX;AX*CX→DX:AX,DX必为0ADDHEX,AX;HEX+AX→AX,CF必为0MOVAL,[BX+3];千位数MOVAH,0MOVCX,1000MULCXADDHEX,AXMOVAL,[BX+2];百位数MOVCL,100MULCL;AL*CL→AXADDHEX,AXMOVAL,[BX+1];十位数MOVCL,10MULCLADDHEX,AXMOVAL,[BX];个位数ADDHEX,AXHLTCODEENDSENDSTART4.25编写一个带符号数四则运算的程序,完成(Z-(X*Y+100))/1000的运算,商送V单元,余数送W单元。X,Y,Z均为带符号数,设:X=FFF0H=-16,Y=0008H=8,Z=007F=127。DATASEGMENTXDW0FFF0HYDW8ZDW7FHVDW?WDW?DATAENDSCODESEGMENTASSUMECS:CODE,DS:DATASTART:MOVAX,DATAMOVDS,AXMOVAX,XIMULY;AX*Y→DX:AXADDAX,100ADCDX,0;DX:AX与32位字长的100相加MOVCX,AX;(X*Y+100)→BX:CXMOVBX,DXMOVAX,ZCWD;将AX(即:Z)的符号位扩展到DXSUBAX,CX;计算Z-(X*Y+100)SBBDX,BXMOVBX,1000IDIVBX;DX:AX÷SI→AX,余数→DXMOVV,AX;保存商MOVW,DX;保存余数HLTCODEENDSENDSTART4.26从BUF单元开始有10个带符号数:-1,3,248,90,42,9042,-4539,0,-28,792。试找出它们的最大值、最小值和平均值,并分别送MAX、MIN和AVG单元。试编写完整的汇编语言程序DATASEGMENTBUFDW-1,3,248,90,42,9042,-4539,0,-28,792MAXDW-32768MINDW32767AVGDW0DATAENDSCODESEGMENTASSUMECS:CODE,DS:DATA,SS:STACKSTART:MOVAX,DATAMOVDS,AXMOVBX,OFFSETBUFMOVCX,10MOVSI,0MOVDI,0NEXT:MOVAX,[BX];取一个数CMPAX,MAX;是当前较大JNGL1;的数吗?MOVMAX,AXL1:CMPAX,MIN;是当前较小JNLL2;的数吗?MOVMIN,AXL2:CWD;将AX符号扩展到DXADDSI,AX;求累加和ADCDI,DXADDBX,2;指向下一个数LOOPNEXTMOVBX,10;计算平均值MOVAX,SIMOVDX,DIIDIVBXMOVAVG,AXHLTCODEENDSENDSTART程序阅读题---例1:MOVCL,4MOVAX,[2000H]SHLAL,CLSHRAX,CLMOV[2000H],AX试问:(1)若执行前(2000H)=05H,(2001H)=07H,则执行后有:(2000H)=__H(2)本程序的功能是:•将(2000H)、(2001H)单元中的非组合型BCD码压缩成组合型BCD码,并存放到(2000H)单元•75H例2:子程序嵌套(递归调用)程序设计----计算n!入口条件:n已在AX中,且0<n≤8出口条件:n!放在AX中FACTORPROCPUSHAXSUBAX,1;n-1→nJNZCOUNTPOPAXJMPRETURNCOUNT:CALLFACTORPOPCXMULCXRETURN:RET若执行前AX=8,则程序执行后有:AX=___40320例3:某班有7个同学英语成绩低于80分,分数存在ARRAY数组中,试编程完成以下工作:(1)给每人加5分,结果存到NEW数组中(2)把总分存到SUM单元中DATASEGMENTARRAYDB?,?,?,?,?,?,?NEWDB7DUP(?)SUMDW0DATAENDSCODESEGMENTMOVAX,DATAMOVDS,AXLEASI,ARRAYLEADI,NEWMOVCX,7NEXT:MOVAL,[SI]ADDAL,5MOV[DI],ALINCSIINCDILOOPNEXTCODEENDSCODESEGMENTLEASI,ARRAYCLCMOVCX,7NEXT1:MOVAL,[SI]MOVAH,0ADCSUM,AXINCSILOOPNEXT1CODEENDSY0ABCG2AG2B74LS138G1Y6Y7···A13~A1CE27641#偶体CE27642#偶体CE27641#奇体CE27642#奇体ABCG2AG2B74LS138G1Y6Y7···Y0RDRDA13~A1A13~A1A13~A1RDRDD7~D0D15~D8习题3.8参考答案A14A15A16A0M/IOA14A15A16BHE&&A17A18A19A17A18A19要组成32KBROM,则需要4片2764(8K×8);芯片的选择分别由2片74LS138译码器输出的Y0、Y1完成;A17~A19、A0、BHE作为偶体/奇体存储器的体选控制信号CBAG2AG2BA15A14A13BHE≥1A19A18A17A16G1M/IOY2CED7D0~D15D8A11~A0A12~A174LS1382732CBAG2AG2BA15A14A13A0≥1A19A18A17A16G1M/IOY4CED7D0~D7D0A10~A0A11~A174LS1386116CBAG2AG2BA15A14A13BHE≥1A19A18A17A16G1M/IOY2CED7D0~D7D0~D15D8A11~A0A12~A174LS1382732CBAG2AG2BA15A14A13A0≥1A19A18A17A16G1M/I