Author Topic: Dynamics Structs  (Read 22122 times)

Philippe RIO

  • Guest
Dynamics Structs
« on: May 01, 2008, 01:07:49 PM »
Hello, I would like solething like this :

invoke   g_slice_alloc0,STRUCTURE_1_SIZE
         mov   [lpStruct_1],eax

invoke   g_slice_alloc0,STRUCTURE_2_SIZE
         mov   edx,[lpStruct_1]
         mov   ([edx.lpPointerOnStruct_2),eax

The first line allocates a structure. This structure has a pointer to an other structure.
In the first structure I want to store the pointer onto the second.

STRUCT   STRUTURE_1
    lpPointerOnStruct_2  resd 1
    dwSomething          resd 1
ENDS

STRUCT   STRUCTURE_2
     dwSomeData_1    resd  1
     dwSomeData_2    resd  1
ENDS

How can I do ?

nobody

  • Guest
Re: Dynamics Structs
« Reply #1 on: May 03, 2008, 06:11:53 AM »
"mov [edx + lpPointerOnStruct_2], eax" should do it. You'll sometimes see Nasm structures defined like:

struc my_structure
.foo resb 1
.bar resb 1
endstruc

... so that the member names don't have to be unique - but the "." does *not* work like C syntax! "my_structure.foo" is *just* the offset! You'll need "my_instance + my_structure.foo" (or "reg + my_structure.foo). Where logic calls for "+", Nasm uses "+", generally, unlike some assemblers/compilers that use "." or "[]" as an alias.

Best,
Frank

Philippe RIO

  • Guest
Re: Dynamics Structs
« Reply #2 on: May 04, 2008, 09:50:08 AM »
Ok and noww ho do you lake it in your DATA segment. The following structure are statics, but also can be addresse dynamically, on can I access to them in those cases ?

On MASM we made something like this :

STRUCT STRUCTURE_2
dwSomeData_1 resd 1
dwSomeData_2 resd 1
ENDS

STRUCT STRUTURE_1
lpPointerOnStruct_2 resd 1
dwSomething resd 1
ENDS

S2 STRUCTURE_2 <>
S1 STRUCTURE_1

-------------------------------------------------

And the last question :

STRUCT STRUCTURE_3
dwValue_1 resd 1
dwValue 2 resd 1
ENDS

S4 STRUCTURE_4
   SS3 S3 <>               ; That is the problem
   dwValue_1  resd ?
ENDS

If there were more operators for structs that would be a good idea. Anno question about STRUCTURE SIZE and MEMBERS size... SIZEOF/LENGTHOF, RECORD...

Thanks for your help