flat assembler
Message board for the users of flat assembler.
Index
> Windows > memory mapped by structure |
Author |
|
slav 23 Apr 2004, 20:49
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 |
|||
23 Apr 2004, 20:49 |
|
slav 23 Apr 2004, 20:57
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.
|
|||
23 Apr 2004, 20:57 |
|
HarryTuttle 26 Apr 2004, 06:04
I very VERY THANK YOU !!!
very smart solution:) _________________ Microsoft: brings power of yesterday to computers of today. |
|||
26 Apr 2004, 06:04 |
|
Tomasz Grysztar 26 Apr 2004, 06:28
You can even do "virtual at edi" in such case.
|
|||
26 Apr 2004, 06:28 |
|
HarryTuttle 08 Nov 2004, 12:27
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. |
|||
08 Nov 2004, 12:27 |
|
Madis731 08 Nov 2004, 18:50
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 Last edited by Madis731 on 09 Nov 2004, 14:42; edited 1 time in total |
|||
08 Nov 2004, 18:50 |
|
HarryTuttle 09 Nov 2004, 00:01
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. |
|||
09 Nov 2004, 00:01 |
|
beppe85 09 Nov 2004, 11:59
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. |
|||
09 Nov 2004, 11:59 |
|
vid 09 Nov 2004, 13:59
LPSTR is "long pointer to string", LPCSTR is "long pointer to constant string" so both are pointer, and thus they are doublewords (DD)
|
|||
09 Nov 2004, 13:59 |
|
Madis731 09 Nov 2004, 16:48
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. |
|||
09 Nov 2004, 16:48 |
|
beppe85 11 Nov 2004, 10:20
Additionally, the cache-misses that would occur do it not worth.
|
|||
11 Nov 2004, 10:20 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.