Author: tkreuzer
Date: Sat Dec 26 20:34:15 2015
New Revision: 70430
URL:
http://svn.reactos.org/svn/reactos?rev=70430&view=rev
Log:
[CRT]
Fix x86 asm implementation of strlen / wcslen.
Modified:
trunk/reactos/lib/sdk/crt/string/i386/tcslen.inc
Modified: trunk/reactos/lib/sdk/crt/string/i386/tcslen.inc
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/string/i386/tc…
==============================================================================
--- trunk/reactos/lib/sdk/crt/string/i386/tcslen.inc [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/string/i386/tcslen.inc [iso-8859-1] Sat Dec 26 20:34:15
2015
@@ -7,23 +7,34 @@
FUNC _tcslen
FPO 0, 1, 1, 1, 0, FRAME_FPO
+
+ /* Save edi and eflags (according to the x86 ABI, we don't need to do that
+ but since the native function doesn't change the direction flag, we don't
+ either */
push edi
- mov edi, [esp + 8]
+ pushfd
+
+ /* Load the string pointer into edi */
+ mov edi, [esp + 12]
+
+ /* Set eax to 0, since we want to compare with 0 */
xor eax, eax
- test edi, edi
- jz _tcslen_end
+ /* Set ecx to -1 (i.e. 0xFFFFFFFF) */
mov ecx, -1
+
+ /* Clear direction flag */
cld
+ /* Now compare the characters until a 0 is found */
repne _tscas
+ /* Calculate the count (eax = -ecx - 1) */
not ecx
- dec ecx
+ lea eax, [ecx-1]
- mov eax, ecx
-
-_tcslen_end:
+ /* Restore eflags/edi and return the result */
+ popfd
pop edi
ret
ENDFUNC