[CRT]
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Sat, 26 Dec 2015 20:34:15 +0000 (20:34 +0000)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Sat, 26 Dec 2015 20:34:15 +0000 (20:34 +0000)
Fix x86 asm implementation of strlen / wcslen.

svn path=/trunk/; revision=70430

reactos/lib/sdk/crt/string/i386/tcslen.inc

index b5256d5..1f3842f 100644 (file)
@@ -7,23 +7,34 @@ PUBLIC _tcslen
 \r
 FUNC _tcslen\r
     FPO 0, 1, 1, 1, 0, FRAME_FPO\r
+\r
+    /* Save edi and eflags (according to the x86 ABI, we don't need to do that\r
+       but since the native function doesn't change the direction flag, we don't\r
+       either */\r
     push edi\r
-    mov edi, [esp + 8]\r
+    pushfd\r
+\r
+    /* Load the string pointer into edi */\r
+    mov edi, [esp + 12]\r
+\r
+    /* Set eax to 0, since we want to compare with 0 */\r
     xor eax, eax\r
-    test edi, edi\r
-    jz _tcslen_end\r
 \r
+    /* Set ecx to -1 (i.e. 0xFFFFFFFF) */\r
     mov ecx, -1\r
+\r
+    /* Clear direction flag */\r
     cld\r
 \r
+    /* Now compare the characters until a 0 is found */\r
     repne _tscas\r
 \r
+    /* Calculate the count (eax = -ecx - 1) */\r
     not ecx\r
-    dec ecx\r
-\r
-    mov eax, ecx\r
+    lea eax, [ecx-1]\r
 \r
-_tcslen_end:\r
+    /* Restore eflags/edi and return the result */\r
+    popfd\r
     pop edi\r
     ret\r
 ENDFUNC\r