***************************************************
* Address of Str1 and Str2 in stack
*
*return value in D0 (whole 32 bits):
* 	0 if two strings equal
* 	1 if Str1 > Str2
* 	-1 if Str2 > Str1
***************************************************
	ORG 	$1000
StrCmp:
*
*	move.l	(a7),a6
*	move.l	(a6)+,a5
*	move.l	(a6)+,a5	;use a5 to store the value of str2
*	move.l	(a6)+,a4	;use a4 to store the value of str1

	move.l	#Str2,a2
*
Compare:
	clr.l	d2
	move.b	(a1)+,d3
	move.b	(a2)+,d4
	add.b	d3,d2
	add.b	d4,d2
	cmp.b	d4,d3
	blt	Small
	bgt	Large
	tst.b	d2
	bne	Compare
	
Equal:
	move.l	#0,d0
	rts
Small:
	move.l	#-1,d0
	rts
Large:
	move.l	#1,d0
	rts
*###########################################################################
PrintStr:
* 				For Demo only, changes D0,D1
	move.w 	#-1,d1
NextChar:
	add.w 	#1,d1
	tst.b 	(a1,d1.w)
	bne 	NextChar
	move.b 	#1,d0 		;Print Str (Addr=A1, Len=D1)
	trap 	#15
	rts
*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
MainProg:
* 				Sample main program, shows whether
* 				Str1 is larger than Str2
	move.l 	#Str1,a1
	bsr 	PrintStr 	;Print first string
	move.l 	#Str1,-(a7)
	move.l 	#Str2,-(a7)
	jsr 	StrCmp 		;Call String Comparison function
	adda 	#8,a7
	move.l 	#EQ,a1
	tst.l 	d0
	beq 	PrintCMP
	bgt 	isLT
	move.l 	#ST,a1
	bra 	PrintCMP
isLT:
	move.l 	#LT,a1
PrintCMP:
	bsr 	PrintStr 	;Print comparison result
	move.l 	#Str2,a1
	bsr 	PrintStr 	;Print second string
	move.b 	#9,d0
	trap 	#15 		;Terminate program
*#######################################################################
Str1 	dc.b 	'ABCDE',0
Str2 	dc.b 	'ABCAE',0
LT 	dc.b 	' is larger than ',0
EQ 	dc.b 	' is equal to ',0
ST 	dc.b 	' is smaller than ',0
	end 	MainProg

    Source: geocities.com/hk/tings_garden/CS2113

               ( geocities.com/hk/tings_garden)                   ( geocities.com/hk)