Menu

Dynamics Structs

2008-05-01
2013-06-04
  • Philippe RIO

    Philippe RIO - 2008-05-01

    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/Anonymous

      "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

      Philippe RIO - 2008-05-04

      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 <OFFSET S2,TRUE>

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

      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

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.