11、设在数据段中有X,Y两变量(字节单元),试编写程序段计算(只写有关程序功能的指令):Y=X当X=0Y=0当X0解:moval,xcmpa;,0jgeA1moval,0A1:movy,al2在STR单元开始定义了一长度为LEN字节的字符串,统计出其中大写字母的个数并存放到LARGE字节单元中。请编一完整的源程序。DATASEGMENTSTRDB‘……’LENEQU$-STRLARGEDB?DATAENDSCDEGMENTASSUMECS:CD,DSATALARGPROCFARMOVAX,DATAMOVDS,AXLEASI,STRMOVCX,LENMOVBL,0NT:CMPBYTEPTR[SI],‘A’JBNOLARGCMPBYTEPTR[SI],‘Z’JANOLARGINCBLNOLARG:INCSILOOPNTMOVLARGE,BLMOVAH,4CHINT21HLARGENDPCDENDSENDLARG3、已知DAT1字节单元有一个数据,试编制一程序段将该数据的低4位变为1010B,最高位(第7位)置1,其余3位不变,结果送DAT2字节单元。MOVAL,DATA1ANDAL,70HADDAL,8AHMOVDATA2,AL4、在N1和N2两数据区中,分别有10H个带符号数。试编制一源程序,找出对应项中较小的数据,并将这些较小的数据存入N3数据区中(要求:对应项比较时必须用CMPS指令)。DATASEGMENTN1DB××,××,××,……N2DB××,××,××,……N3DB10HDUP(0)DATAENDS解:STACKSEGSEGMENTSTACKDB1024DUP(0)STACKSEGENDSDATASEGMENTN1DB5Ah,6Fh,2Eh,0D8h,0E3h,9Ch,0DBh,0B7h,5Bh,21h,35h,8Eh,4Ah,15h,58h,75hN2DB58h,0FFh,5Eh,38h,0C7h,0A1h,26h,86h,48h,35h,48h,16h,0BAh,0FAh,0DFh,0E9hN3DB10HDUP(0)DATAENDSCODESEGMENTASSUMECS:CODE,DS:DATA,SS:STACKSEGSTART:MOVAX,DATAMOVDS,AXINCAXMOVES,AXMOVSI,0FFFFHMOVDI,0FFFFHMOVCX,10hMOVBX,OFFSETN3CLDAGAIN:CMPSBYTEPTRN1,BYTEPTRN2JLN1LESMOVAL,[SI+10h]MOV[BX][SI],ALJMPCMPAGAINN1LES:MOVAL,[sI]MOV[BX][SI],ALCMPAGAIN:deccxjnzagainMOVAH,4CHINT21HCODEENDSENDSTART25、加密移动字符串,设缓冲区SBUFF中有20个小写字母a,将每个a加上它相对于缓冲区的位移量后传送到缓冲区DBUFF。STACKSEGSEGMENTSTACKDB1024DUP(0)STACKSEGENDSDATASEGMENTSBUFFDB20DUP('a')DBUFFDB20DUP(0)DATAENDSCODESEGMENTASSUMECS:CODE,DS:DATA,SS:STACKSEGSTART:MOVAX,DATAMOVDS,AXMOVCX,20MOVSI,0CLDAGAIN:LODSBMOVBX,SIDECBXADDAX,BXMOVDBUFF[SI-1],ALLOOPAGAINDBUFFINT21HMOVAH,4CHINT21HCODEENDSENDSTART6、在BUF1和BUF2两个数据区中,各定义有10个带符号字数据,试编制一完整的源程序,求它们对应项的和,并将和数存入以SUM为首址的数据区中。DATASEGMENTBUF1DW-56,24,54,-1,89,-8,……BUF2DW45,-23,124,345,-265,……SUMDW10DUP(0)DATAENDSCODESEGMENTASSUMECS:CODE,DS:DATABEGIN:MOVAX,DATAMOVES,AXMOVDS,AXLEASI,BUF1MOVBX,OFFSETBUF2LEADI,SUMMOVCX,10L1:MOVAX,[SI]ROLAX,1JCL2RORAX,1L4:MOVDX,AXMOVAX,[BX]ROLAX,1JCL3RORAX,1L5:ADDAX,DXMOV[DI],AXINCBXINCBXINCSIINCSIINCDIINCDILOOPL1JMPLASTL2:RORAX,1NEGAXJMPL4L3:RORAX,1NEGAXJMPL5LAST:MOVAH,4CHINT21HCODEENDSENDBEGIN7、试编写一个汇编语言程序,要求对键盘输入的小写字母用大写字母显示出来。DATASSEGMENTMSGDB0,0,H,$CRDB13,10,$TAB1DB0123456789ABCDEFDATASENDS3STACKSSEGMENTSTACKSENDSCODESSEGMENTASSUMECS:CODES,DS:DATAS,ES:DATAS,SS:STACKSSTART:MOVAX,DATASMOVDS,AXMOVES,AXMOVCX,127MOVDL,0MOVSI,OFFSETTAB1MOVDI,OFFSETMSGAG:PUSHCXPUSHDXMOVAX,0MOVAL,DLMOVBL,10HDIVBLMOVBX,0MOVBL,AHMOVDH,[SI+BX]MOV[DI+1],DHMOVBL,ALMOVDH,[SI+BX]MOV[DI],DHPUSHDXMOVDX,OFFSETMSGMOVAH,9INT21HPOPDXMOVAH,2INT21HPUSHAXMOVDX,OFFSETCRMOVAH,9INT21HPOPDXPOPDXPOPCXINCDLLOOPAGMOVAH,4CHINT21HCODESENDSENDSTART8、汇编程序,以BUF为首地址的内容存单元中有1~15的平方表。查表求X单元中数(1~15之间)的平方值并送回X单元codesegmentassumecs:code,ds:codeorg100hstart:pushcspopdsleabx,BUF;BX指向表首moval,Xdecal;偏移送ALxlat;查表movX,al;平方值并送回X单元movah,4chint21hBUFdb1,4,9,16,25,36,49,64,81,100,121,144,169,196,225Xdb8codeendsendstart9、已知存储器中有一个首地址为ARRAY的100个字数组,现要求把数组中的每个数加1(不考虑溢出的可能性),试编制完成此功能的程序段。MOVBX,OFFSETARRAYMOVAX,1MOVCX,100LOOP1:ADD[BX],AXLOOPLOOP110、.编写一段程序,如果字节变量TESTONE和TESTTWO相等,则调用子程序,显示‘#’;否则调用NOTSAME子程序,显示‘!’。datasegmentinfondb0dh,0ah,'#$'infon2db0dh,0ah,'!$'TESTONEdb0dh,0ah,'2$'TESTTWOdb0dh,0ah,'1$'dataendsstacksegmentstackdb200dup(0)stackends4codesegmentassumeds:data,ss:stack,cs:codestart:movax,offsetTESTONEmovbx,offsetTESTTWOcmpax,bxjek2jnek1k1:callshowk2:callNOTSAMEexit:movah,4chint21hshowprocnear;leadx,infonmovah,9int21hretshowendpNOTSAMEprocnear;leadx,infon2;在屏幕上显示提示信息movah,9int21hretNOTSAMEendpcodeendsendstart11、已定义了两个整数变量A和B,试编写程序完成下列功能:A.若两个数中有一个是奇数,则将奇数存入A中,偶数存入B中。B.若两个数均为奇数,则将两数均加1后存回原变量。C.若两个数均为偶数,则两个变量均不改变。(要求各段定义完整,并画出程序流程图)datasegmentadb3bdb3dataendscodesegmentassumeds:data,cs:codestart:movax,datamovds,axtesta,1jznext1testb,1jztjincaincbjmptjnext1:testb,1jztjmoval,axchgal,bmova,altj:movah,4chint21hcodeendsendstart12、假设DATAX和DATAX+2单元存放双字P,DATAY和DATAY+2单元中存放双字Q,编程计算2P-Q,差在DX,AX中。若OF=1,程序转OVERFLOW,否则转NOOVER。(只写与试题要求有关的指令语句)DATASEGMENTDATAXDW2321H,3243HDATAYDW1233H,4332HDATAENDSCODESEGMENTASSUMEDS:DATA,CS:CODESTART:MOVAX,DATAMOVDS,AXMOVDX,DATAX+2MOVAX,DATAXSHLAX,1RCLDX,1;求2PSUBAX,DATAYSBBDX,DATAY+2;求2P-QJOOVERFLOWNOFLOW:MOVAH,0JMPEXIT5OVERFLOW:MOVAH,1EXIT:MOVAX,4C00HINT21HCODEENDSENDSTART13、已知在数据区BUF1和BUF2分别存放20个字节数据。编程检查两数据区中的数据是否相同。若完全一致,则将标志单元FLAG置FFH,否则置0,并将第一次出现的不同数据的地址分别存放在ADDR1和ADDR2单元中。要求:源程序格式完整。datasegmentxdw?ydw?msgdb'continue?YesorNo?$'msg1db'Inputfirstnumber:$'msg2db'Inputsecondnumber:$'msg3db'Shangis:$'dataendsdecihexsegmentassumecs:decihex,ds:datamainprocfarmovax,datamovds,axrepeat:leasi,xleadx,msg1movah,9int21hcalldecibincallcrlfleasi,yleadx,msg2movah,9int21hcalldecibincallcrlfmovax,xcwddivwordptr[x+2]pushdxmovbx,axleadx,msg3movah,9int21hcallbinidecmovdl,'.'movah,2int21hpopaxmovcx,10mulcxdivwordptr[x+2]movbx,axmovcx,1calldec_divcallcrlfleadx,msgmovah,9int21hcallcrlfmovah,1int21hcmpal,'Y'jzrepeat14、设X、Y、Z、W为十六位有符号数编程计算:W←(X+Y*Z)/8-Y除法余数丢弃若ZF=1,程序转EQ;否则转NOT_EQ。movax,yimulz;计算y*z,结果在dx和ax中addax,x;ax+xadcdx,0;dx+ax与x相加产生的进位movbx,8divbx;dx、ax除以8,余数在dx中,商在ax中subax,y;商-y,影响标志位ZFmovw,ax;存结果,mov指令不影响标志位jzeq;测试的是sub执行后的标志,zf=1转eqjmpnot_eq;zf不为1,转not_eq15、已知在以ARRAY为首地址的数据区中存放10个带符号字数