TITLE EX3_2
;-----------------------------------------------------
DSEG1	SEGMENT	'DATA'		;define data segment 1
L1	EQU	100		;length of STR1
STR1	DB	L1 DUP(?)
ASTR2	DB	5 DUP(?)	;For storing STR2
DSEG1	ENDS
;------------------------------------------------------
DSEG2	SEGMENT	'DATA'		;define data segment 2
L2	EQU	5		;Length of STR2
STR2	DB	L2 DUP(?)
COUNT	EQU	L1-L2+1
DSEG2 	END
;------------------------------------------------------
CSEG	SEGMENT
MAIN	PROC	FAR
	ASSUME CS:CSEG, DS:DSEG2, ES:DSEG1
START:
	PUSH	DS		;for return to DOS
	SUB	AX,AX
	PUSH	AX
	MOV	AX,DSEG1	;put dseg2 in DS
	MOV	DS,AX
	MOV	AX,DSEG1	;put dseg2 in ES
	MOV	ES,AX

	CLD	;set direction flag to forward
	MOV	CX,COUNT	;put count in CX
	MOV	BX,OFFSET STR1
NEXT:	MOV	DI,BX		;dest addr in DI
	MOV	SI,OFFSET STR2  ;source string addr
	PUSH	CX
	MOV	CX,L2
	REP	CMPSB		;compare STR2 in STR1
	POP	CX
	JE	MATCH		;STR1 contain STR2
	INC	BX	  ;nomatch,point next addr
	LOOP	NEXT   		;compare again
NO_MATCH:
	LEA	DI,ASTR2	;STR1 not contain STR2
	LEA	SI,STR2
	MOV	CX,L2
	REP	MOVSB		;mov STR2 at after STR1
MATCH:	RET			;return to DOS	
MAIN	ENDP
CSEG	ENDS
;------------------------------------------------------
	END	START
