aboutsummaryrefslogtreecommitdiff
path: root/newlib/libc/machine/h8300/strcmp.S
blob: c16bc1cfd1220b78751ae8ffe101695dc55b0680 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "setarch.h"

#include "defines.h"

#if defined (__H8300SX__)
	.section .text
	.global _strcmp
_strcmp:
	mov.l	er0,er2
loop:
	mov.b	@er2+,r0l
	extu.w	r0
	beq	eos
	mov.b	@er1+,r3l
	extu.w	r3
	sub.w	r3,r0
	beq	loop
#if (__INT_MAX__ > 32767)
	exts.l	er0
#endif
	rts
eos:
	mov.b	@er1,r3l
	extu.w	r3
	sub.w	r3,r0
#if (__INT_MAX__ > 32767)
	exts.l	er0
#endif
	rts
	.end
#else
	.section .text
	.align 2
	.global _strcmp
_strcmp:
	MOVP	A0P,A2P
	MOVP	A1P,A3P
.L5:
	mov.b	@A2P+,A1L
	beq	.L3
	mov.b	@A3P+,A0L
	cmp.b	A0L,A1L
	beq	.L5
#ifdef __NORMAL_MODE__
	sub	#1,A3P
#else
	subs	#1,A3P
#endif
.L3:
	mov.b	@(-1,A2P),A0L
	mov.b	@A3P,A1L
	sub.b	A0H,A0H ; H8/300 does not have EXTU.W instruction
	sub.b	A1H,A1H ; so we just zero higher byte of the word
	sub.w	A1,A0
	; We have to sign extend the result to 32bits just in case
	; we are using 32bit integers. H8/300 does not support 32bit
	; integers (-mint32), so we can just use EXTS.L here.
#if (__INT_MAX__ > 32767)
	exts.l	er0
#endif
	rts
	.end
#endif