]> git.sur5r.net Git - cc65/blob - libsrc/common/strlen.s
Minor math optimizations
[cc65] / libsrc / common / strlen.s
1 ;
2 ; Ullrich von Bassewitz, 31.05.1998
3 ;
4 ; Note: strspn & strcspn call internally this function and rely on
5 ; the usage of only ptr2 here! Keep in mind when appling changes
6 ; and check the other implementations too!
7 ;
8 ; int strlen (const char* s);
9 ;
10
11         .export         _strlen
12         .importzp       ptr2
13
14 _strlen:
15         sta     ptr2            ; Save s
16         stx     ptr2+1
17         ldx     #0              ; YX used as counter
18         ldy     #0
19
20 L1:     lda     (ptr2),y
21         beq     L9
22         iny
23         bne     L1
24         inc     ptr2+1
25         inx
26         bne     L1
27
28 L9:     tya                     ; get low byte of counter, hi's all set
29         rts