2eccf70d695caf87b016c6d69f06f526e55f683b
[fw/sdcc] / device / lib / z80 / strlen.s
1         .area   _CODE
2
3         .globl _strlen
4
5 ; The Z80 has the cpir instruction, which is perfect for implementing strlen().
6
7 _strlen:
8         push    ix
9         ld      ix, #0
10         add     ix, sp
11         ld      l, 4(ix)
12         ld      h, 5(ix)
13         xor     a, a
14         ld      b, a
15         ld      c, a
16         cpir
17         ld      hl, #-1
18         sbc     hl, bc  ; C flag still cleared from xor above.
19         pop     ix
20         ret
21