资源描述:
《汇编语言-实验四 字符串的匹配与替换程序设计.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实验四字符串的匹配与替换程序设计一、实验目的1)掌握串操作指令的使用方法。2)掌握串处理程序的设计方法。3)熟练使用各种程序结构。二、实验内容1)编制两个字符串比较子程序。2)编制在一个字符串中查找给定字符串的程序。3)编写程序把从键盘输入的以回车为结束符的字符串中的空格去掉并按相反的顺序输出。4)编写程序在字符串STRING1中指定位置插入字符串STRING2。5)编写程序在字符串STRING1中指定位置删除子串。三、源程序EXAM4-1DATASEGMENTSTR1DB'MES'STR2DB'MESS'STR3DB'MATCH$'STR4DB'NOTMATCH$'
2、DATAENDSCODESEGMENTASSUMECS:CODE,DS:DATASTART:MOVAX,DATAMOVDS,AXMOVES,AXMOVCX,4MOVDI,OFFSETSTR1MOVSI,OFFSETSTR2REPZCMPSBJZLAB1JNZLAB2LAB1:MOVDX,OFFSETSTR3MOVAH,09HINT21HMOVAH,4CHINT21HLAB2:MOVDX,OFFSETSTR4MOVAH,09HINT21HMOVAH,4CHINT21HCODEENDSENDSTARTEXAM4-2DATASEGMENTMESS1DB'ENTERKEYWO
3、RD:','$'MESS2DB'ENTERSENTENCE:','$'MESS3DB'NOMATCH!',13,10,'$'MESS4DB'MATCHATLOCATION:','$'MESS5DB'HOFTHESENTENCE.',13,10,'$'CHANGEDB13,10,'$' SEN1LABELBYTE MAX1DB14 ACT1DB? STOKN1DB14DUP(?) SEN2LABELBYTE MAX2DB100 ACT2DB? STOKN2DB100DUP(?)DATAENDSCODESEGMENTMAINPROCF
4、AR ASSUMECS:CODE,DS:DATA,ES:DATASTART: MOVAX,DATA MOVDS,AX MOVES,AX LEADX,MESS1 MOVAH,09H INT21H LEADX,SEN1 MOVAH,0AH INT21H LEADX,CHANGE MOVAH,09H INT21H SUBCX,CXA10: LEADX,MESS2 MOVAH,09H INT21H LEADX,SEN2 MOVAH,0AH INT21H LEADX,CHANGE MOVAH
5、,09H INT21H CMPACT2,0 JEEXIT MOVBX,0A20: MOVCL,[ACT1] LEASI,STOKN1 LEAAX,STOKN2 ADDAL,BL MOVDI,AX CLD REPCMPSB JZA30 INCBL CMPBL,ACT2 JEA40 JMPA20A30: LEADX,MESS4 MOVAH,09H INT21H MOVAH,02H ADDBL,1 MOVCL,4 MOVAL,BL ROLAL,CL MOVCL,2 JMP
6、A50A1: LEADX,MESS5 MOVAH,09H INT21H JMPA10A40: LEADX,MESS3 MOVAH,09H INT21H JMPA10A50: DECCL ANDAL,0FH CMPAL,10 JNBA60 ADDAL,'0'A2: MOVDL,AL MOVAH,02H INT21H CMPCL,0 JEA1 MOVAL,BL JMPA50A60: SUBAL,10 ADDAL,'A' JMPA2EXIT: RETMAINENDPCODEEND
7、S ENDSTART