1/* Copyright (c) 2006, Carlos Lamas 2 3 based on libc/pmstring/strcasecmp_P.S which is 4 Copyright (c) 2002, Reiner Patommel 5 6 All rights reserved. 7 8 Redistribution and use in source and binary forms, with or without 9 modification, are permitted provided that the following conditions are met: 10 11 * Redistributions of source code must retain the above copyright 12 notice, this list of conditions and the following disclaimer. 13 * Redistributions in binary form must reproduce the above copyright 14 notice, this list of conditions and the following disclaimer in 15 the documentation and/or other materials provided with the 16 distribution. 17 * Neither the name of the copyright holders nor the names of 18 contributors may be used to endorse or promote products derived 19 from this software without specific prior written permission. 20 21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 POSSIBILITY OF SUCH DAMAGE. */ 32 33/* $Id: strcasecmp_PF.S 2503 2016-02-07 22:59:47Z joerg_wunsch $ */ 34 35#if !defined(__AVR_TINY__) 36 37#include "macros.inc" 38 39#define s1_b1 r25 40#define s1_b0 r24 41#define s2_b3 r23 42#define s2_b2 r22 43#define s2_b1 r21 44#define s2_b0 r20 45 46#define ret_b1 r25 47#define ret_b0 r24 48 49#define tmp s2_b1 /* copied to Z pointer */ 50#define cht s2_b0 51 52#if !defined(__DOXYGEN__) 53 54 .text 55 .global _U(strcasecmp_PF) 56 .type _U(strcasecmp_PF), @function 57 58_U(strcasecmp_PF): 59 60 X_movw ZL, s2_b0 61 LPM_R0_ZPLUS_INIT s2_b2 62 X_movw XL, s1_b0 63 64.L_strcasecmp_PF_loop: 65 66 ld ret_b0, X+ ; load *s1 67 LPM_R0_ZPLUS_NEXT s2_b2 ; load *s2 68 mov tmp, r0 ; copy of *s2 to tmp 69 mov cht, r0 ; copy of *s2 to cht 70 ori cht, 0x20 ; make tmp lower case 71 cpi cht, 'a' ; test on [a .. z] 72 brlt .L_strcasecmp_PF_tst 73 cpi cht, 'z'+1 74 brge .L_strcasecmp_PF_tst 75 ori tmp, 0x20 ; we got an aplpha in s2 76 ori ret_b0, 0x20 77 78.L_strcasecmp_PF_tst: ; compare 79 80 sub ret_b0, tmp 81 brne .L_strcasecmp_PF_done 82 tst r0 ; end of s2? 83 brne .L_strcasecmp_PF_loop 84 85.L_strcasecmp_PF_done: 86; ret_hi = SREG.C ? 0xFF : 0 87 88 sbc ret_b1, ret_b1 89 ret 90 91.L_strcasecmp_PF_end: 92 93 .size _U(strcasecmp_PF), .L_strcasecmp_PF_end - _U(strcasecmp_PF) 94 95#endif /* not __DOXYGEN__ */ 96 97#endif /* !defined(__AVR_TINY__) */ 98