1
/* Copyright (c) 2002, Reiner Patommel
1
/* Copyright (c) 2002, 2007 Reiner Patommel
2
Copyright (c) 2007 Dmitry Xmelkov
4
5
Redistribution and use in source and binary forms, with or without
26
27
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
28
POSSIBILITY OF SUCH DAMAGE. */
29
/* $Id: strncasecmp.S,v 1.5 2005/11/05 16:49:46 aesok Exp $ */
30
/* $Id: strncasecmp.S,v 1.5.2.3 2007/03/31 13:31:03 dmix Exp $ */
36
37
Created by Reiner Patommel
52
41
/** \ingroup avr_string
53
42
\fn int strncasecmp(const char *s1, const char *s2, size_t len)
54
43
\brief Compare two strings ignoring case.
56
The strncasecmp() function is similar to strcasecmp(), except it only
57
compares the first n characters of s1.
45
The strncasecmp() function is similar to strcasecmp(), except it
46
only compares the first \p len characters of \p s1.
59
\returns The strncasecmp() function returns an integer less than, equal to,
60
or greater than zero if s1 (or the first n bytes thereof) is found,
61
respectively, to be less than, to match, or be greater than s2. */
48
\returns The strncasecmp() function returns an integer less than,
49
equal to, or greater than zero if \p s1 (or the first \p len bytes
50
thereof) is found, respectively, to be less than, to match, or be
51
greater than \p s2. A consequence of the ordering used by
52
strncasecmp() is that if \p s1 is an initial substring of \p s2,
53
then \p s1 is considered to be "less than" \p s2. */
63
55
#if !defined(__DOXYGEN__)
66
71
.global _U(strncasecmp)
67
72
.type _U(strncasecmp), @function
75
BRCS .L_strncasecmp_equal
76
LD ret_lo, X+ ; load *s1
78
MOV cht, tmp ; copy of *s2 to cht
79
ORI cht, 0x20 ; make it lower case
80
CPI cht, 'a' ; test on [a .. z]
81
BRLT .L_strncasecmp_tst
83
BRGE .L_strncasecmp_tst
84
ORI tmp, 0x20 ; we got an alpha in s2
85
ORI ret_lo, 0x20 ; make *s1, *s2 lower case
87
SUB ret_lo, tmp ; compare chars
88
BRNE .L_strncasecmp_done
90
BRNE .L_strncasecmp_loop
92
SUB ret_lo, ret_lo ; clear ret_lo and C flag
94
; ret_hi = SREG.C ? 0xFF : 0
98
.size _U(strncasecmp), .L_strncasecmp_end - _U(strncasecmp)
78
1: subi len_lo, lo8(1) ; if (--len == -1) return 0
83
cpi ret_lo, 'A' ; if in [A-Z] then tolower()
90
cpi tmp, 'A' ; if in [A-Z] then tolower()
96
3: sub ret_lo, tmp ; compare
97
cpse tmp, __zero_reg__ ; break, if end of string
99
4: sbc ret_hi, ret_hi ; sign extension
102
5: sub ret_lo, ret_lo ; length limit, return 0
105
.size _U(strncasecmp), . - _U(strncasecmp)
100
107
#endif /* not __DOXYGEN__ */