From: Timo Kreuzer Date: Sat, 26 Dec 2015 20:34:15 +0000 (+0000) Subject: [CRT] X-Git-Tag: ReactOS-0.4.0~19^2~5 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=654e3f77437a9027838cfc35ff0ff3764ac4a9a7 [CRT] Fix x86 asm implementation of strlen / wcslen. svn path=/trunk/; revision=70430 --- diff --git a/reactos/lib/sdk/crt/string/i386/tcslen.inc b/reactos/lib/sdk/crt/string/i386/tcslen.inc index b5256d586c9..1f3842f5c33 100644 --- a/reactos/lib/sdk/crt/string/i386/tcslen.inc +++ b/reactos/lib/sdk/crt/string/i386/tcslen.inc @@ -7,23 +7,34 @@ PUBLIC _tcslen 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 - - mov eax, ecx + lea eax, [ecx-1] -_tcslen_end: + /* Restore eflags/edi and return the result */ + popfd pop edi ret ENDFUNC