输入两个字符串,比较字符串是否相同
程序运行:
代码:
datas segmentstring1MaxLength db 0ffh,0 string1 db 100h dup(?)string1Number dw 0 string2MaxLength db 0ffh,0 string2 db 100h dup(?) string2Number dw 0input1Prompt db 'input string1:$'input2Prompt db 0dh,0ah,'input string2:$'outputMatch db 0dh,0ah,'MATCH$'outputNoMatch db 0dh,0ah,'NO MATCH$'datas endsstacks segmentdb 100h dup(?)stacks endscodes segmentassume cs:codes,ds:datas,ss:stacks
main proc far
start:push dsmov ax,0hpush axmov ax,datas ;初始化dsmov ds,ax;输出输入string1提示lea dx,input1Promptmov ah,9int 21h;输入string1lea dx,string1MaxLengthmov ah,10int 21h;保存string1的长度和设置结束字符mov bl,string1MaxLength+1mov bh,0 mov string1Number,bxmov string1[bx],'$';输出输入string2提示lea dx,input2Promptmov ah,9int 21h;输入string2lea dx,string2MaxLengthmov ah,10int 21h ;保存string1的长度和设置结束字符mov bl,string2MaxLength+1mov bh,0 mov string2Number,bxmov string2[bx],'$';比较string1和string2的字符串长度cmp bx,string1Numberjne s3 ;不相等,直接跳转s3;相等时,判断字符是否相同mov si,0mov di,0mov cx,string1Numbercompare:mov al,string1[si]cmp al,string2[di]jne s3inc siinc diloop compare;字符完全相同,输出MATCHlea dx,outputMatchmov ah,9int 21hjmp exit ;跳转至退出程序;不相等,输出NO MATCHs3:lea dx,outputNoMatchmov ah,9int 21hexit:retmain endp
codes endsend main