source: trunk/libs/newlib/src/newlib/libc/machine/rx/memchr.S @ 444

Last change on this file since 444 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 875 bytes
Line 
1        .file   "memchr.S"
2
3        .section .text
4       
5        .global  _memchr
6        .type    _memchr,@function
7_memchr:
8        ;; R1: string pointer
9        ;; R2: byte sought
10        ;; R3: max number to scan
11#ifdef __RX_DISALLOW_STRING_INSNS__
12        mov.b   r2, r2          ; The mov.b below sign extends as it loads, so make sure that r2 is sign-extended as well.
132:      cmp     #0, r3
14        beq     1f
15        sub     #1, r3
16        mov.b   [r1+], r5
17        cmp     r5, r2
18        bne     2b
19
20        sub     #1, r1          ; We have found a match, bit now R1 points to the byte after the match.
211:      rts
22#else
23        cmp     #0, r3          ; If r3 is 0 suntil.b will do nothing and not set any flags...
24        stz     #1, r1          ; ...so store 1 into r1.  It will be decremented by the SUB later.
25        suntil.b                ; Search until *r1 == r2 or r3 bytes have been examined.
26        stnz    #1, r1          ; If no match was found return NULL.
27        sub     #1, r1          ; suntil.b leaves r1 pointing at the address *after* the match.
28        rts
29#endif
30
31        .size _memchr, . - _memchr
32       
Note: See TracBrowser for help on using the repository browser.