data segment
string1 db 50,50 dup(?)
string2 db 50,50 dup(?)
show1 db 'please input the first string: (press enter to end) ',0ah,0dh,'$'
show2 db 0ah,0dh,'please input the second string: (press enter to end) ',0ah,0dh,'$'
result1 db 'match!!!$'
result2 db 'notmatch!!!$'
data ends
stack segment
db 100 dup(?)
stack ends
code segment
ASSUME CS:CODE,DS:DATA,SS:STACK
start:
push ds
sub ax,ax
push ax
mov ax,data
mov ds,ax
mov ah,9
mov dx,offset show1
int 21h
mov cx,-1
for1: ;键盘输入字符存入string1中
mov ah,1
int 21h
mov di,offset string1
mov [di],al
inc di
inc cx
cmp al,0dh
jne for1
push cx ;保存string1的长度
mov ah,9
mov dx,offset show2
int 21h
mov cx,-1
for3: ;键盘输入字符存入string2中
mov ah,1
int 21h
mov di,offset string2
mov [di],al
inc di
inc cx
cmp al,0dh
jne for3
push cx ;保存string2的长度
mov ah,2
mov dl,0dh
int 21h
mov ah,2
mov dl,0ah
int 21h
pop cx ;second string length
pop bx ;first string length
cmp bx,cx
je substring
notmatch:
mov ah,9
lea dx,result2
int 21h
jmp ended
substring:
mov si,offset string1
mov di,offset string2
lop:
mov al,[si]
mov bl,[di]
cmp bl,al
jnz notmatch
inc si
inc di
loop lop
mov ah,9
lea dx,result1
int 21h
ended:
mov ah,4ch
int 21h
code ends
end
string1 db 50,50 dup(?)
string2 db 50,50 dup(?)
show1 db 'please input the first string: (press enter to end) ',0ah,0dh,'$'
show2 db 0ah,0dh,'please input the second string: (press enter to end) ',0ah,0dh,'$'
result1 db 'match!!!$'
result2 db 'notmatch!!!$'
data ends
stack segment
db 100 dup(?)
stack ends
code segment
ASSUME CS:CODE,DS:DATA,SS:STACK
start:
push ds
sub ax,ax
push ax
mov ax,data
mov ds,ax
mov ah,9
mov dx,offset show1
int 21h
mov cx,-1
for1: ;键盘输入字符存入string1中
mov ah,1
int 21h
mov di,offset string1
mov [di],al
inc di
inc cx
cmp al,0dh
jne for1
push cx ;保存string1的长度
mov ah,9
mov dx,offset show2
int 21h
mov cx,-1
for3: ;键盘输入字符存入string2中
mov ah,1
int 21h
mov di,offset string2
mov [di],al
inc di
inc cx
cmp al,0dh
jne for3
push cx ;保存string2的长度
mov ah,2
mov dl,0dh
int 21h
mov ah,2
mov dl,0ah
int 21h
pop cx ;second string length
pop bx ;first string length
cmp bx,cx
je substring
notmatch:
mov ah,9
lea dx,result2
int 21h
jmp ended
substring:
mov si,offset string1
mov di,offset string2
lop:
mov al,[si]
mov bl,[di]
cmp bl,al
jnz notmatch
inc si
inc di
loop lop
mov ah,9
lea dx,result1
int 21h
ended:
mov ah,4ch
int 21h
code ends
end
