flat assembler
Message board for the users of flat assembler.
Index
> Windows > Procedure conversion C++ to Fasm |
Author |
|
idle 16 Jan 2011, 22:04
hi Picnic
could you describe verbally what exactly you are going to do ((Timer.QuadPart * 1000) / ticksPerSecond.QuadPart) * 0.001 = Timer / ticksPerSecond the fp-code seems wrong |
|||
16 Jan 2011, 22:04 |
|
Picnic 16 Jan 2011, 23:15
Hi idle,
I see the relationship here, could use some hints about the possible reason. When simplifying the division program is not working. Where you locate the error? p.s pticksPerSecond is a pointer to ticksPerSecond qword lastTimeA is a qword, strats with value 0 |
|||
16 Jan 2011, 23:15 |
|
idle 17 Jan 2011, 01:04
- 1000 * 0.001 = 1, so remove those
- fmul [var1] // fmul [var2] = 1, so remove those - fstp [currentTime] // fld [currentTime] = fld st0 // fstp [currentTime] - fild [Var4] = fild qword[ecx] - fcomp [elapsedTime], could be kept in fpu so - jp .ret, use and ah,01000101b // jnz .ret use frame_rate directly there is a fld1 instruction to load 1.0 into st0 i'm sleepy, sorry if wrong |
|||
17 Jan 2011, 01:04 |
|
Picnic 17 Jan 2011, 23:34
Thanks for the useful tips idle. i'm sleepy too, enough for today.
Code: proc LockFrameRate frame_rate:dword, pticksPerSecond:dword locals Timer dq ? currentTime dq ? elapsedTime dq ? endl invoke QueryPerformanceCounter, addr Timer call TestApi fild qword [Timer] mov eax, [pticksPerSecond] fild qword [eax] fdivp st1, st0 fld st0 fstp qword [currentTime] fsub qword [lastTimeA] fstp qword [elapsedTime] fld1 fidiv dword [frame_rate] fcomp qword [elapsedTime] fnstsw ax test ah, 5 jp .ret fld qword [currentTime] fstp qword [lastTimeA] mov eax, 1 ret .ret: xor eax, eax ret endp |
|||
17 Jan 2011, 23:34 |
|
idle 18 Jan 2011, 08:02
Picnic, avoid memory usage whenever possible.
Sets CF=1 if lastTimeA updated, destroys flags and eax. :)= Code: proc LockFrameRate; frame_rate:dword, pticksPerSecond:dword sub esp,8 invoke QueryPerformanceCounter,esp fild qword[esp] ;Timer add esp,8 mov eax,[esp+8] fild qword[eax] ;ticksPerSecond fdivp st1,st0 ;currentTime fld st0 fsub qword[lastTimeA] ;elapsedTime fld1 fidiv dword[esp+4] ;1/frame_rate fcompp fstsw ax shr ah,1 jc @f fstp st0 ret 8 @@:fstp qword[lastTimeA] ret 8 endp |
|||
18 Jan 2011, 08:02 |
|
Picnic 19 Jan 2011, 09:00
That's more elegant, and likely more efficient, too.
|
|||
19 Jan 2011, 09:00 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.