[CRT]
[reactos.git] / reactos / lib / sdk / crt / string / i386 / tcslen.inc
1
2 #include "tchar.h"
3 #include <asm.inc>
4
5 PUBLIC _tcslen
6 .code
7
8 FUNC _tcslen
9 FPO 0, 1, 1, 1, 0, FRAME_FPO
10
11 /* Save edi and eflags (according to the x86 ABI, we don't need to do that
12 but since the native function doesn't change the direction flag, we don't
13 either */
14 push edi
15 pushfd
16
17 /* Load the string pointer into edi */
18 mov edi, [esp + 12]
19
20 /* Set eax to 0, since we want to compare with 0 */
21 xor eax, eax
22
23 /* Set ecx to -1 (i.e. 0xFFFFFFFF) */
24 mov ecx, -1
25
26 /* Clear direction flag */
27 cld
28
29 /* Now compare the characters until a 0 is found */
30 repne _tscas
31
32 /* Calculate the count. For n characters, we do (n + 1) comparisons. Initial
33 value of ecx was -1, so end value of ecx is (-1 - (n + 1)) = -(n + 2).
34 => n = -ecx - 2 = ~ecx - 1 */
35 not ecx
36 lea eax, [ecx - 1]
37
38 /* Restore eflags/edi and return the result */
39 popfd
40 pop edi
41 ret
42 ENDFUNC
43
44 END
45 /* EOF */