修改下列代码,要求:改为如果字符串2长度大于等于字符串1,则输出字符串1,如果字符串2长度小于字符串1,则补齐字符串2长度到字符串1,补足部分XXXX.DATA SEGMENT TIP1 DB 0DH,0AH, 'PLEASE INPUT STRING1 END BY ENTER:' ,'$' TIP2 DB 0DH,0AH, 'PLEASE INPUT STRING1 END BY ENTER:' ,'$' TIP3 DB 0DH,0AH, 'MATCH','$' TIP4 DB 0DH,0AH, 'NOT MATCH','$' TIP5 DB 0DH,0AH, 'PRESS ENTER TO EXIT ','$' BUFF1 DB 101,0,101 DUP(0) BUFF2 DB 101,0,101 DUP(0) DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START: MOV AX,DATA MOV DS,AX MOV ES,AX;数据段和堆栈段初始化 LEA DX,TIP1 MOV AH,9 INT 21H;DISPLAY TIP1 LEA DX,BUFF1 MOV AH,0AH INT 21H;输入第一个字符串到BUFF1缓冲区 LEA DX,TIP2 MOV AH,9 INT 21H LEA DX,BUFF2 MOV AH,0AH INT 21H;输入第二个字符串到BUFF2缓冲区 LEA SI,BUFF1;第一个字符串首址给SI LEA DI,BUFF2;第二个字符串首址给DI MOV CX,53 CLD;地址递增 REPZ CMPSB;字符串比较 JZ MATCH;相等输出MATCH LEA DX,TIP4 MOV AH,9 INT 21H;不等输出NOT MATCH JMP EXIT MATCH: LEA DX,TIP3 MOV AH,9 INT 21H;DISPLAY TIP1 JMP EXIT EXIT: LEA DX,TIP5 MOV AH,9 INT 21H MOV AH,1 INT 21H CMP AL,13 JZ AA JMP START AA: MOV AH,4CH INT 21H CODE ENDS END START
时间: 2024-02-10 07:06:23 浏览: 151
c语言输出字符串中最大对称子串长度的3种解决方案
修改后的代码如下:
```
DATA SEGMENT
TIP1 DB 0DH,0AH, 'PLEASE INPUT STRING1 END BY ENTER:' ,'$'
TIP2 DB 0DH,0AH, 'PLEASE INPUT STRING2 END BY ENTER:' ,'$'
TIP3 DB 0DH,0AH, 'MATCH','$'
TIP4 DB 0DH,0AH, 'NOT MATCH','$'
TIP5 DB 0DH,0AH, 'PRESS ENTER TO EXIT ','$'
BUFF1 DB 101,0,101 DUP(0)
BUFF2 DB 101,0,101 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV ES,AX;数据段和堆栈段初始化
LEA DX,TIP1
MOV AH,9
INT 21H;DISPLAY TIP1
LEA DX,BUFF1
MOV AH,0AH
INT 21H;输入第一个字符串到BUFF1缓冲区
LEA DX,TIP2
MOV AH,9
INT 21H
LEA DX,BUFF2
MOV AH,0AH
INT 21H;输入第二个字符串到BUFF2缓冲区
;如果字符串2长度大于等于字符串1,则输出字符串1
LEA SI,BUFF1;第一个字符串首址给SI
LEA DI,BUFF2;第二个字符串首址给DI
MOV CX,53
CLD;地址递增
REPZ CMPSB;字符串比较
JNC MATCH;大于等于则相等,输出MATCH
;如果字符串2长度小于字符串1,则补齐字符串2长度到字符串1
LEA SI,BUFF2
LEA DI,BUFF1
MOV CX,53
CLD
REP MOVSB
;比较两个字符串是否相等
LEA SI,BUFF1
LEA DI,BUFF2
MOV CX,53
CLD
REPZ CMPSB
JZ MATCH;相等输出MATCH
LEA DX,TIP4
MOV AH,9
INT 21H;不等输出NOT MATCH
JMP EXIT
MATCH:
LEA DX,TIP3
MOV AH,9
INT 21H;DISPLAY TIP1
JMP EXIT
EXIT:
LEA DX,TIP5
MOV AH,9
INT 21H
MOV AH,1
INT 21H
CMP AL,13
JZ AA
JMP START
AA:
MOV AH,4CH
INT 21H
CODE ENDS
END START
```
阅读全文