flat assembler
Message board for the users of flat assembler.

Index > Main > Question about "virtual"

Author
Thread Post new topic Reply to topic
ghostreaper



Joined: 07 Apr 2011
Posts: 2
ghostreaper
I don't really know when and how to use "virtual", in other words, what situation I have to use it.
And the snippet below:
Code:
struc EXCEPTION_POINTERS {
    .ExceptionRecord dd ?  ; pointer to EXCEPTION_RECORD
    .ContextRecord   dd ?  ; pointer to CONTEXT
}

virtual at 0
    EXCEPTION_POINTERS EXCEPTION_POINTERS
end virtual    


what does the "virtual" do exactly?
I'm really confused about using it.
Post 23 Aug 2011, 07:59
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Used this way with "struc", it defines symbols EXCEPTION_POINTERS.ExceptionRecord = 0 and EXCEPTION_POINTERS.ContextRecord = 4. Without this, you couldn't do something like "mov eax, [ebx + EXCEPTION_POINTERS.ContextRecord]", because "EXCEPTION_POINTERS.ContextRecord" symbol wouldn't be defined. "struc" doesn't define it, it is only a special kind of macro. FASM is very lowlevel assembler, and uses this kind of "trickery" quite often, in order to be very powerful by having only handful of simple features, which can be combined to build expected features.

"virtual" itself defines all labels inside it, but not the data. You don't need to really understand this, as long as you only use it for structures.
Post 23 Aug 2011, 08:45
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1409
Location: Toronto, Canada
AsmGuru62
I use virtual to generate code for structures in IDE I am developing:
Code:
virtual at 0
RECT:
  .Left   INT32 ?
     .Top    INT32 ?
     .Right  INT32 ?
     .Bottom INT32 ?
     .size   =$
end virtual
    

In this case, I can access the members of a structure:
Code:
macro RECT_WIDTH r32_width, r32_pRect
{
       mov     r32_width, [r32_pRect + RECT.Right]
 sub     r32_width, [r32_pRect + RECT.Left]
}
    

Or allocate memory for the structure using .size member:
Code:
invoke       HeapAlloc, [hAllocator], HEAP_NO_SERIALIZE, RECT.size
    
Post 23 Aug 2011, 13:23
View user's profile Send private message Send e-mail Reply with quote
ghostreaper



Joined: 07 Apr 2011
Posts: 2
ghostreaper
thank you all of you very much.I got it!
Post 07 Sep 2011, 07: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.

Powered by rwasa.