C# to MASM difficulty with FILETIME

456 views Asked by At

I have two lines of C# I would like to convert to assembly. I've tried to follow this answer (FILETIME to __int64) without getting a satisfying result.

This is the two lines of C#

System.DateTime dt = System.DateTime.Now;
long x = dt.ToFileTime();

And from the other answer (linked above) I've concluded this should be the assembly code that does the same.

local fTime :FILETIME
local ticks :DWORD

invoke GetLocalTime,addr time
invoke SystemTimeToFileTime,addr time,addr fTime

xor eax,eax
xor ebx,ebx

mov eax,fTime.dwLowDateTime
mov ebx,fTime.dwHighDateTime
sal ebx,32
or ebx,eax
mov ticks,ebx

The output of the C# is 1221229007
The output of my asm is 2882329052

The C# and the assembly was run within seconds from each other, so the diffrence shouldn't be THAT big. Should it?

Where am I wrong?

1

There are 1 answers

2
f2lollpll On BEST ANSWER
invoke GetLocalTime,addr time
invoke SystemTimeToFileTime,addr time,addr fTime

xor eax,eax
xor ebx,ebx

mov eax,fTime.dwLowDateTime
mov ebx,fTime.dwHighDateTime

sal ebx,32 ;shift HighDateTime left 32 bits
add ebx,eax ;add HighDateTime and LowDateTime together

mov edx,ebx ;edx has the ticks?

this seem to work, the or should be an add

found it Here