;比较两个字符串STRING1和STRING2中的字符是否相等,相等则显示MATCH,
;不相等则显示NO MATCH。
DATA SEGMENT
STRING1 DB 'STRING1MATCH'
COUNT1 DW $-STRING1
STRING2 DB 'STRING1MATCH'
COUNT2 DW $-STRING2
MATCH DB "MATCH!",'$'
NOMATCH DB "NO MATCH!",'$'
DATA ENDS
STACK SEGMENT PARA STACK
DW 128 DUP(?)
TOP LABEL WORD
STACK ENDS
CODE SEGMENT
ASSUME CS:CODE,SS:STACK,DS:DATA
MAIN PROC FAR
START:
MOV AX,DATA
MOV DS,AX
MOV ES,AX
MOV AX,STACK
MOV SS,AX
LEA SP,TOP
MOV AX,COUNT1 ;字符串长度不相等则直接显示NO MATCH!
MOV BX,COUNT2
CMP AX,BX
JNE L2
LEA SI,STRING1 ;DS:SI ED:DI
LEA DI,STRING2
CLD ;设置方向为正,则DI、SI自增
MOV CX,7 ;需要比较的字符串长度
REPE CMPSB
JE L1
JNE L2
L1: MOV AH,9
LEA DX,MATCH
INT 21H
JMP L3
L2: MOV AH,9
LEA DX,NOMATCH
INT 21H
JMP L3
L3: MOV AH,4CH
INT 21H
CODE ENDS
MAIN ENDP
END START