flat assembler
Message board for the users of flat assembler.

Index > Main > MASM to FASM, ADDR?

Author
Thread Post new topic Reply to topic
calpol2004



Joined: 16 Dec 2004
Posts: 110
calpol2004
I've currently got problems with porting MASM's ADDR to what the FASM equivalent is:

I have a MASM example for which the key parts look like this:

Code:
_timer STRUC
    frequency                            dq      ?
    resolution                            REAL4  ?
    performance_timer_start        dq      ?
    performance_timer_elapsed   dq      ?
_timer ENDS

...

timer       _timer      <>  

...

invoke  QueryPerformanceFrequency,addr timer.frequency      
    


And i've ported it like this (with and without brackets):

Code:
TimerFrequency:                 dq ?
TimerResolution:                dd ?
TimerStart:                     dq ?
TimerElapsed:                   dq ?   

...

invoke  QueryPerformanceFrequency,[TimerFrequency]

    


from looking in OllyDgb the MASM example just has 1 PUSH for an address. But i tried doing this any way to no avail:

Code:
invoke  QueryPerformanceFrequency,dword[TimerFrequency],dword[TimerFrequency+4]
    


The return indicates theres something wrong or that my computer does not support the performance counter. Which i know it does since i've been able able to run other applications which use the performance counter.

Anyone know exactly how MASM's ADDR works? or worked with this particular functions before?
Post 22 Jan 2008, 15:03
View user's profile Send private message MSN Messenger Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
The correct way is
Code:
include 'win32ax.inc'
start:
  invoke QueryPerformanceFrequency, timerFrequency
  test   eax, eax
  jz     hardwareNotAvailable

  invoke MessageBox, 0, "QueryPerformanceFrequency returned successfully", "OK", 0
  ret

hardwareNotAvailable:
  invoke  MessageBox, 0, "Hardware not available", "Error", 0
  ret

align 8 ; Failed to me without this!!
timerFrequency dq ?

.end start    


Last edited by LocoDelAssembly on 22 Jan 2008, 15:49; edited 1 time in total
Post 22 Jan 2008, 15:40
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
BTW, is documented somewhere that LARGE_INTEGER must be aligned? Because there is no warns at that respect on http://msdn2.microsoft.com/en-us/library/ms644905(VS.85).aspx
Post 22 Jan 2008, 15:48
View user's profile Send private message Reply with quote
calpol2004



Joined: 16 Dec 2004
Posts: 110
calpol2004
Thankyou very much. It works Smile.

Perculiar solution though. does it make sure that the memory is stored at an address which is a multiple of 8?

Hmm, i shall have to scour the docs once more . Confused.
Post 22 Jan 2008, 18:50
View user's profile Send private message MSN Messenger Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
http://bobmoore.mvps.org/Win32/w32tip75.htm

I have tried to step into the SYSCALL with WinDbg as a kernel debugger attached to a VirtualPC but the step into is not possible and I don't know how to stop at kernel mode Sad
Post 22 Jan 2008, 20:12
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
If your going to Implement some timing functions, Here's some articles that might interest you:
http://www.mvps.org/directx/indexes/game_timing.htm
QueryPerformanceCounter is covered, and how to use it in your games/gfx coding. there is also another method discussed for older OS compatibility.
Post 22 Jan 2008, 20:15
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
calpol2004 wrote:

Perculiar solution though. does it make sure that the memory is stored at an address which is a multiple of 8?

Not really, but If you want to save a few cycles, it would be good to put an 'align 8' just before the variable. Or a string of Quad sized variables.
Post 22 Jan 2008, 20:24
View user's profile Send private message Reply with quote
calpol2004



Joined: 16 Dec 2004
Posts: 110
calpol2004
i always thought align 8 was just an optimization that made sure that the memory was taken from the ram from the start of the variable so that the I/O controller doesn't have to throw away the unwanted adjacent bytes.

I remember reading something about it in "art of assembly" about how reading from addressed which are multiples of 4 or 2 is faster that odd numbers, but shouldnt it still work anyway?

And that is an interesting article about game timings, i've always updated the same amount each fps. which is dum since if the pc isn't good enough it will play the game in slow motion. calculating the distance the object should of moved by knowing the last time the frame was drawn is much more logical.
Post 23 Jan 2008, 12:25
View user's profile Send private message MSN Messenger Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
I don't understand why functions like InterlockedIncrement warns you about alignment requirements while this one says absolutely nothing and even the MVP seems to be somewhat surprised since he spent hours to find the solution and guessed what was the problem rather than pointing to documentation.

[edit]I misunderstood madmatt response so now I edited to make my post context independent[/edit]


Last edited by LocoDelAssembly on 24 Jan 2008, 15:36; edited 1 time in total
Post 23 Jan 2008, 16:50
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
calpol2004 wrote:
i always thought align 8 was just an optimization that made sure that the memory was taken from the ram from the start of the variable so that the I/O controller doesn't have to throw away the unwanted adjacent bytes.

I remember reading something about it in "art of assembly" about how reading from addressed which are multiples of 4 or 2 is faster that odd numbers, but shouldnt it still work anyway?

And that is an interesting article about game timings, i've always updated the same amount each fps. which is dum since if the pc isn't good enough it will play the game in slow motion. calculating the distance the object should of moved by knowing the last time the frame was drawn is much more logical.


I should clarify, for the application you posted, alignment wouldn't give you any real benefit. I'm not sure, but I think alignment has something to do with the way the CPU fetch's data, whether it has to do one 8-byte fetch vs 2 4-byte fetches. I would agree with "art of assembly" that aligned data is better than unaligned data, especially in the case of MMX/SSE/SSE2 operations. Most CPU instructions can work with unaligned data, only in certain SSE instructions require that data be aligned.
Post 24 Jan 2008, 11:51
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.