/*		Q/C V3.2 Utility Library		*/
/*     Copyright (c) 1984 Quality Computer Systems	*/
/*			11/25/84			*/

#include "stdio.h"

#ifdef PORTABLE
/* compare two strings */
strcmp(s1, s2)
register char *s1, *s2;
	{
	while (*s1 == *s2) {
		if (*s1 == '\0')
			return 0;	/* they're equal to the end */
		++s1; ++ s2;
		}
	return (*s1 - *s2);
	}
#else
strcmp() {
#	asm 8080
	LXI	H,2	;get args
	DAD	SP
	MOV	E,M	;s2
	INX	H
	MOV	D,M
	INX	H
	MOV	A,M	;s1
	INX	H
	MOV	H,M
	MOV	L,A
	XCHG		;reverse args
?scmp1: LDAX	D	;current char of s1
	SUB	M	;compute *s1-*s2
	JNZ	?scmp2	;they don't match here
	ORA	M	;end-of-string (0)?
	JZ	?scmp2	;they match to end-to-string
	INX	D	;next char of s1
	INX	H	;same for s2
	JMP	?scmp1	;loop
?scmp2: MOV	L,A	;set return value (*s1-*s2)
	RLC		;sign-extend into H
	SBB	A
	MOV	H,A
	ORA	L	;set Z flag
#	endasm
	}
#endif

