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