1/* 2Copyright (c) 2009 Nick Clifton <nickc@redhat.com> 3 */ 4#include <picolibc.h> 5 6 .file "strlen.S" 7 8 .section .text 9 10 .global _strlen 11 .type _strlen,@function 12_strlen: 13#ifdef __RX_DISALLOW_STRING_INSNS__ 14 mov r1, r4 15 161: mov.b [r1+], r5 17 cmp #0, r5 18 bne 1b 19 20 sub #1, r1 21 sub r4, r1 22 rts 23#else 24 add #0, r1, r4 ; Save a copy of the string start address and set the condition flags. 25 beq null_string ; Test for a NULL pointer. 26 mov #-1, r3 ; Set a limit on the number of bytes examined. 27 mov #0, r2 ; Stop searching when we find a NUL byte. 28 suntil.b ; Search until *r1 == r2 29 sub #1, r1 ; suntil.b leaves r1 pointing to the byte beyond the match. 30null_string: 31 sub r4, r1 ; Compute the length. 32 rts 33#endif 34 .size _strlen, . - _strlen 35