1/*
2Copyright (c) 1990 The Regents of the University of California.
3All rights reserved.
4
5Redistribution and use in source and binary forms are permitted
6provided that the above copyright notice and this paragraph are
7duplicated in all such forms and that any documentation,
8and/or other materials related to such
9distribution and use acknowledge that the software was developed
10by the University of California, Berkeley.  The name of the
11University may not be used to endorse or promote products derived
12from this software without specific prior written permission.
13THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16 */
17#include <picolibc.h>
18
19#include "setarch.h"
20
21#include "defines.h"
22
23#if defined (__H8300SX__)
24	.global _strcmp
25_strcmp:
26	mov.l	er0,er2
27loop:
28	mov.b	@er2+,r0l
29	beq	eos
30	sub.b	@er1+,r0l
31	beq	loop
32	exts.l	#2,er0
33	rts
34eos:
35	sub.b	@er1,r0l
36	exts.l	#2,er0
37	rts
38#else
39	.section .text
40	.align 2
41	.global _strcmp
42_strcmp:
43	MOVP	A0P,A2P
44	MOVP	A1P,A3P
45.L5:
46	mov.b	@A2P+,A1L
47	beq	.L3
48	mov.b	@A3P+,A0L
49	cmp.b	A0L,A1L
50	beq	.L5
51#ifdef __NORMAL_MODE__
52	sub	#1,A3P
53#else
54	subs	#1,A3P
55#endif
56.L3:
57	mov.b	@(-1,A2P),A0L
58	mov.b	@A3P,A1L
59	sub.b	A1L,A0L
60	; We have to sign extend the result to 32bits just in case
61	; we are using 32bit integers.
62#ifdef __H8300H__
63	exts.w	r0
64	exts.l	er0
65#else
66#ifdef __H8300S__
67	exts.w	r0
68	exts.l	er0
69#else
70	bld	#7,r0l
71	subx	r0h,r0h
72	subx	r1l,r1l
73	subx	r1h,r1h
74#endif
75#endif
76	rts
77	.end
78#endif
79