flat assembler
Message board for the users of flat assembler.

Index > Windows > memory mapped by structure

Author
Thread Post new topic Reply to topic
HarryTuttle



Joined: 26 Sep 2003
Posts: 211
Location: Poland
HarryTuttle
I want to GlobalAlloc a buffer and after received a massage I'd like to mapped the memory by custom structure to make easier retrieving some information from it.

I saw somewhere(It was on this page i think) that idea but now it looks like just I am blind and can't catch the previous information about so called "virtual structures" with is very wanted.
I tryed to search it but without success.

please 4 help!
regards,

Harry

_________________
Microsoft: brings power of yesterday to computers of today.
Post 22 Apr 2004, 13:35
View user's profile Send private message Reply with quote
slav



Joined: 21 Apr 2004
Posts: 5
Location: Spain
slav
Some rather quick example...

Code:

; Vrtual block that will help with offsets
virtual at 0
    DummyStruct YOURGREATSTRUCT
end virtual

; Then after allocating some memory with GlobalAlloc you can 'map' it
; in this way

    mov edi, [PtrToBuffer]
    mov [edi+DummyStruct.OneOfTheStructFields],6996

    


i hope you get the idea
Post 23 Apr 2004, 20:49
View user's profile Send private message Reply with quote
slav



Joined: 21 Apr 2004
Posts: 5
Location: Spain
slav
I think it could be hard to follow if you're not use to virtual blocks so here comes a little explanation... what your are doing this way (with the virtual bocks) is defining labels to memory positions. If you state that this block begins at 0 memory position those labels are just the offsets to the different fields of the struct.
Post 23 Apr 2004, 20:57
View user's profile Send private message Reply with quote
HarryTuttle



Joined: 26 Sep 2003
Posts: 211
Location: Poland
HarryTuttle
I very VERY THANK YOU !!!
very smart solution:)

_________________
Microsoft: brings power of yesterday to computers of today.
Post 26 Apr 2004, 06:04
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7737
Location: Kraków, Poland
Tomasz Grysztar
You can even do "virtual at edi" in such case.
Post 26 Apr 2004, 06:28
View user's profile Send private message Visit poster's website Reply with quote
HarryTuttle



Joined: 26 Sep 2003
Posts: 211
Location: Poland
HarryTuttle
everything ok when all the data are in DD format but what's going on the string?

Code:


struc ARRAY_MY
{

.first_name rb 16
.last_name rb 12
.age dd ?
}
...
virtual at 0
 my_array ARRAY_MY
end virtual
...
.code
inv GlobalAlloc,GMEM_FIXE,0x0ff
mov [h_mem],eax

mov edi,[h_mem]
mov [edi+my_array.age],19  ;<sets the age but how to set last name ?
...
    


best regards,
h.

_________________
Microsoft: brings power of yesterday to computers of today.
Post 08 Nov 2004, 12:27
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
I think the first thing I can think of is
Code:
    push edi ebx edx
    mov  ebx,...;Point ebx here to your string
the_loop:
    mov dl,byte [ebx]
    mov byte[edi+myarray.first_name],dl
    inc edi
    inc ebx
    cmp dl,0
    jne the_loop
    pop edx ebx edi
    

There are string copying routines but haven't had the time to dig into them.
Maybe someone here thinks of a shorter (AND faster) way to do that Razz


Last edited by Madis731 on 09 Nov 2004, 14:42; edited 1 time in total
Post 08 Nov 2004, 18:50
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
HarryTuttle



Joined: 26 Sep 2003
Posts: 211
Location: Poland
HarryTuttle
I thought about that:
Code:
LPTSTR lstrcpy(

    LPTSTR lpString1,  // address of buffer 
    LPCTSTR lpString2  // address of string to copy 
   );
    

but your code likes me more because of lack of import

very thank You!

_________________
Microsoft: brings power of yesterday to computers of today.
Post 09 Nov 2004, 00:01
View user's profile Send private message Reply with quote
beppe85



Joined: 23 Oct 2004
Posts: 181
beppe85
AFAIK you cannot use the REP prefixes to this job, as you don't know string length ahead.

Code:
        push    edi, esi
    mov     esi, // what to write
       mov     edi, // and where
@@:
        lodsb   // perhaps we can use just movsb
    stosb   // if it sets al also

   test    al, al
      jnz     @b
@@:
       pop     edi, esi
    

This is an example of using x86 string movement, but is better to use simpler instructions(mov/inc as Madis731 used).

Again, because string length is not known until after copying, it's hard, if not impossible, to apply loop unrolling.

To make better, just not copying at all. Very Happy
Post 09 Nov 2004, 11:59
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
LPSTR is "long pointer to string", LPCSTR is "long pointer to constant string" so both are pointer, and thus they are doublewords (DD)
Post 09 Nov 2004, 13:59
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
I think the only way to know the length is to do two passes:
Code:
push eax esi ecx
    mov  esi,ptString ;Point esi here to your string
    mov  al,0
    or   ecx,-1              ;Near infinity
    add  edi,myarray.first_name
    push edi               ;Preserve array pointer
    cld                      ; cleardirection?
    repe scasb             ;Find the end
    mov  ecx,edi       ;Save the finish
    pop  edi
    sub  ecx,edi    ;Calculate difference
    ;### ecx=length, esi:edi=source:destination
    rep  movsb
pop ecx esi eax 
    

but now the code seems more complicated than before
two 'macro-instructions' with repeat feel slow, but I have
not tested them so I can't be sure.
Post 09 Nov 2004, 16:48
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
beppe85



Joined: 23 Oct 2004
Posts: 181
beppe85
Additionally, the cache-misses that would occur do it not worth.
Post 11 Nov 2004, 10:20
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 YouTube, Twitter.

Website powered by rwasa.