1、汇编语言程序设计汇编语言程序设计上次课后作业上次课后作业n4.6 假设数据项定义如下:nDATA1 DB HELLO!GOOD MORNING!nDATA2 DB 20 DUP(?)n用串操作指令编写程序段,使其分别完成以下功能:n(1)从左到右将DATA1中的字符串传送到DATA2中。n(2)传送完后,比较DATA1和DATA2中的内容是否相同。n(3)把DATA1中的第3和第4个字节装入AX。n(4)将AX的内容存入DATA2+5开始的字节单元中。n解:(1)nMOV AX,SEG DATA1nMOV DS,AXnMOV AX,SEG DATA2nMOV ES,AXnLEA SI,DATA
2、1nLEA DI,DATA2nMOV CX,20nCLDnREP MOVSBn(2)nLEA SI,DATA1nLEA DI,DATA2nMOV CX,20nCLD nREPE CMPSBn。n(3)nLEA SI,DATA1nADD SI,2nLODSWn(4)LEA DI,DATA2n ADD DI,5n STOSWn n编写循环结构程序,进行下列计算,结果存入RESULT内存单元n n1+2+3+4+5+6+100n n1+3+5+7+9+11+99n n2+4+6+8+10+100n n1+4+7+10+13+100n n11+22+33+44+99n n(1 1)CODE SEGME
3、NTCODE SEGMENTn nASSUMEASSUMECS:CODECS:CODEn nSTART:START:XORXORAX,AXAX,AXn nMOVMOV CX,100CX,100n nAGAIN:AGAIN:ADDADDAX,CXAX,CXn nLOOPLOOP AGAINAGAINn nMOVMOV RESULT,AXRESULT,AXn nMOVMOV AX,4C00HAX,4C00Hn nINTINT21H21Hn nCODECODE ENDS ENDSn nENDENDSTARTSTARTn n(2 2)CODECODE SEGMENT SEGMENTn nASSUMEA
4、SSUMECS:CODECS:CODEn n START:XOR START:XORAX,AXAX,AXn nMOVMOVCX,50CX,50n nMOVMOVBX,1BX,1n nAGAIN:AGAIN:ADD ADDAX,BXAX,BXn nADDADDBX,2BX,2n nLOOPLOOPAGAINAGAINn nMOVMOVRESULT,AXRESULT,AXn nMOVMOVAX,4C00HAX,4C00Hn nINTINT21H21Hn nCODECODEENDSENDSn nENDENDSTARTSTARTn n(3 3)CODECODESEGMENTSEGMENTn nASSU
5、MEASSUMECS:CODECS:CODEn nSTART:XORSTART:XORAX,AXAX,AXn nMOVMOVCX,50CX,50n nMOVMOVBX,2BX,2n nAGAIN:AGAIN:ADD ADDAX,BXAX,BXn nADDADDBX,2BX,2n nLOOPLOOPAGAINAGAINn nMOVMOVRESULT,AXRESULT,AXn nMOVMOVAX,4C00HAX,4C00Hn nINTINT21H21Hn nCODECODE ENDS ENDSn nENDENDSTART START n n(4 4)CODECODESEGMENTSEGMENTn
6、nASSUMEASSUMECS:CODECS:CODEn nSTART:XORSTART:XORAX,AXAX,AXn nMOVMOVCX,34CX,34n nMOVMOVBX,1BX,1n nAGAIN:AGAIN:ADDADDAX,BXAX,BXn nADDADDBX,3BX,3n nLOOPLOOPAGAINAGAINn nMOVMOVRESULT,AXRESULT,AXn nMOVMOVAX,4C00HAX,4C00Hn nINTINT21H21Hn nCODECODEENDSENDSn nENDENDSTARTSTARTn n(5 5)CODECODESEGMENTSEGMENTn
7、nASSUMEASSUMECS:CODECS:CODEn nSTART:XORSTART:XORAX,AXAX,AXn nMOVMOVCX,9CX,9n nMOVMOVBX,11BX,11n nAGAIN:AGAIN:ADD ADD AX,BXAX,BXn nADDADDBX,11BX,11n nLOOPLOOPAGAINAGAINn nMOVMOVRESULT,AXRESULT,AXn nMOVMOVAX,4C00HAX,4C00Hn nINTINT21H21Hn nCODECODEENDSENDSn nENDENDSTARTSTARTn n4.17 4.17 数组数组SCORESCORE中
8、存有一个班级中存有一个班级4040名学生的英语名学生的英语课程成绩。按照课程成绩。按照059059,60746074,75847584,8510085100统统计各分数段人数,存入计各分数段人数,存入N0N0,N1,N2,N3N1,N2,N3变量内。变量内。n nDATADATASEGEMNTSEGEMNTn nSCORESCOREDWDW4040 DUP(?)DUP(?);运行前置入具体数据;运行前置入具体数据n nN0N0DWDW?n nN1N1DWDW?n nN2N2DWDW?n nN3N3DWDW?n n DATA DATA ENDS ENDSn nCODECODESEGMENTSEG
9、MENTn nASSUMEASSUME CS:CODE,DS:DATACS:CODE,DS:DATAn nSTART:MOVSTART:MOVAX,DATAAX,DATA MOV MOVDS,AXDS,AXn nMOVMOVN0,0N0,0;各计数器清零;各计数器清零n n MOVMOVN1,0N1,0n n MOV MOVN2,0N2,0n n MOV MOVN3,0N3,0n n LEA LEASI,SCORESI,SCOREn n MOV MOVCX,40CX,40n nAGAINAGAIN:MOVMOVAX,SIAX,SIn n CMP CMPAX,59AX,59;分段测试;分段测试n
10、 n JAJAL1 L1 n n L0:L0:INC INCN0N0n n JMP JMPNEXTNEXTn nL1:L1:CMP CMPAX,74AX,74n n JA JAL2L2n nINCINCN1N1n nJMPJMPNEXTNEXTnnn nL2:CMPL2:CMP AX,84AX,84n n JA JAL3L3n nINCINCN2N2n nJMPJMPNEXTNEXTn nL3:L3:CMPCMPAX,100AX,100n nJAJANEXTNEXTn nINCINCN3N3n nNEXT:ADDNEXT:ADD SI,2SI,2LOOPLOOPAGAINAGAINn nEXI
11、T:MOVEXIT:MOVAX,4C00HAX,4C00Hn nINTINT21H21Hn nCODECODEENDSENDSn nENDENDSTARTSTARTn n数组数组ARRAYARRAY中存有中存有1010个无符号字整数(元素序号个无符号字整数(元素序号0909),现在要删除其中的),现在要删除其中的第第5 5个元素。编写程序,把第个元素。编写程序,把第6969个元素移到第个元素移到第5858个元素的位置上,并把第个元素的位置上,并把第9 9个元素清零。个元素清零。n n答:答:DATADATASEGEMNTSEGEMNTn n ARRAY DW -386,97,213,21,77
12、,-91,56,7,123,65 ARRAY DW -386,97,213,21,77,-91,56,7,123,65n nDATADATAENDSENDSn nCODECODESEGMENTSEGMENTn nASSUMEASSUME CS:CODE,DS:DATACS:CODE,DS:DATAn nSTART:MOVSTART:MOVAX,DATAAX,DATAn n MOV MOVDS,AXDS,AXn n MOV MOVBX,6*2 BX,6*2;第六个元素在数组内的位移;第六个元素在数组内的位移n n MOVMOVCX,4CX,4;循环计数器置初值;循环计数器置初值n nAGAIN:
13、AGAIN:MOV MOVAX,ARRAYBX AX,ARRAYBX;取出一个元素;取出一个元素n n MOVMOVARRAYBX-2,AXARRAYBX-2,AX;向前移动一个位置;向前移动一个位置n nADDADDBX,2BX,2;修改指针;修改指针n nLOOPLOOPAGAINAGAIN;循环;循环4 4次次n nMOVMOVARRAYBX,0ARRAYBX,0;最后一个元素清零;最后一个元素清零n nMOVMOVAX,4C00HAX,4C00Hn nINTINT21H21Hn nCODECODEENDSENDSn nENDENDSTARTSTARTn n假设下列指令中的所有标识符均为
14、类型属性为字假设下列指令中的所有标识符均为类型属性为字的变量,请指出下列指令中哪些是非法的的变量,请指出下列指令中哪些是非法的?它们的它们的错误是什么错误是什么?n n (1)MOV BP (1)MOV BP,ALALn n (2)MOV WORD_OPBX+4*3DI (2)MOV WORD_OPBX+4*3DI,SPSPn n (3)MOV WORD_OPl (3)MOV WORD_OPl,WORD_OP2WORD_OP2n n (4)MOV AX (4)MOV AX,WORD_OPlDXWORD_OPlDXn n (5)MOV SP (5)MOV SP,SSSS:DATA_WORDBXSIDATA_WORDBXSIn n (7)MOV BXSI (7)MOV BXSI,2 2n n (8)MOV AX (8)MOV AX,WORD_ OPl+WORD_OP2WORD_ OPl+WORD_OP2