OSDN Git Service

* libc/machine/rx/strncat.S (_strncat): Replace use of r6
[pf3gnuchains/pf3gnuchains3x.git] / newlib / libc / machine / rx / strncat.S
1         .file   "strncat.S"
2
3         .section .text
4         .global  _strncat
5         .type    _strncat,@function
6 _strncat:
7         ;; On entry: r1 => Destination
8         ;;           r2 => Source
9         ;;           r3 => Max number of bytes to copy
10         
11         mov     r1, r4          ; Save a copy of the dest pointer.
12         mov     r2, r5          ; Save a copy of the source pointer.
13         mov     r3, r14         ; Save a copy of the byte count.
14         
15         mov     #0,  r2         ; Search for the NUL byte.
16         mov     #-1, r3         ; Search until we run out of memory.
17         suntil.b                ; Find the end of the destination string.
18         sub     #1, r1          ; suntil.b leaves r1 pointing to the byte beyond the NUL.
19
20         mov     r14, r3         ; Restore the limit on the number of bytes copied.
21         mov     r5, r2          ; Restore the source pointer.
22         mov     r1, r5          ; Save a copy of the dest pointer.
23         smovu                   ; Copy source to destination.
24
25         add     #0, r14, r3     ; Restore the number of bytes to copy (again), but this time set the Z flag as well.
26         beq     1f              ; If we copied 0 bytes then we already know that the dest string is NUL terminated, so we do not have to do anything.
27         mov     #0, r2          ; Otherwise we must check to see if a NUL byte
28         mov     r5, r1          ;  was included in the bytes that were copied.
29         suntil.b
30         beq     1f              ; Z flag is set if a match was found.
31         add     r14, r5         ; Point at byte after end of copied bytes.
32         mov.b   #0, [r5]        ; Store a NUL there.
33 1:      
34         mov     r4, r1          ; Return the original dest pointer.
35         rts