;	kcmpstr.a - KCmpStr implementation
;	$VER: kcmpstr.a 37.1 (10.5.96)
;	Copyright © 1996 Michael Letowski
;
;	37.1 (10.5.96) - initial version


	xdef	_KCmpStr
	xdef	@KCmpStr

; Some aliases

	xdef	_KStrCmp
	xdef	@KStrCmp
	xdef	_kstrcmp
	xdef	@kstrcmp
	xdef	KCmpStr

	section	text,code


******* debug.lib/KCmpStr ***************************************************
*
*   NAME
*       KCmpStr -- compare two NULL-terminated strings. (V37)
*
*   SYNOPSIS
*       mismatch = KCmpStr(string1, string2)
*       D0                 A0       A1
*
*       LONG KCmpStr(STRPTR, STRPTR);
*
*   FUNCTION
*       string1 is compared to string2 using the ASCII collating sequence.
*       If the strirngs have different lengths, the shorter is treated as if
*       it were extended with zeros.
*
*   INPUTS
*       string1, string2 - strings to be compared.
*
*   RESULT
*       result - value representing relationship between string1 and string2:
*                    <0 means string1 < string2
*                    =0 means string1 = string2
*                    >0 means string1 > string2
*
*   NOTES
*       @KCmpStr, @KStrCmp, @kstrcmp, KStrCmp are identical assembly
*       interfaces that want two pointers in registers. _KCmpStr, _KStrCmp,
*       _kstrcmp are C interfaces that expect the parameters on the stack.
*
*   SEE ALSO
*       locale.library/StrnCmp(),
*       utility.library/Stricmp(), utility.library/Strnicmp().
*
*****************************************************************************
*
* _KCmpStr(string1, string2)
* @KCmpStr(R_A0 string1, R_A1 string2)
*
_KCmpStr:
_KStrCmp:
_kstrcmp:
	move.l	1*4(sp),a0		; Load parameters from stack
	move.l	2*4(sp),a1

@KCmpStr:
@KStrCmp:
@kstrcmp:
KCmpStr:
CSLoop:
	moveq.l	#0,d0			; Clear d0
	move.b	(a0)+,d0		; Get char of first string
	beq.b	TestSecond		; If NULL check if second NULL too
	sub.b	(a1)+,d0		; Compare with char of second string
	beq.b	CSLoop			; Loop if equal
	ext.w	d0
	ext.l	d0
	rts				; Return

TestSecond:
	sub.b	(a1)+,d0		; Check if char of second string NULL
	ext.w	d0
	ext.l	d0
	rts				; Return

	end
