flat assembler
Message board for the users of flat assembler.

Index > Main > struct question

Author
Thread Post new topic Reply to topic
DenimJeans



Joined: 29 Dec 2023
Posts: 11
DenimJeans 04 Jan 2024, 14:39
Hi everyone, could you please help me understanding structs and arrays:

I have a struct like (hope the definition is correct):

Code:
struct TRIS
        pt1 POINT ?
        ...
ends

tp TRIS 1,2 ; <- error     

how can I initialize the struct ?
also, how can I create an array of them?

like 10x
tp1 ... tp10
Post 04 Jan 2024, 14:39
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 04 Jan 2024, 14:54
To supply multiple items to a single member use angle brackets.
Code:
tp TRIS <1,2>    
Post 04 Jan 2024, 14:54
View user's profile Send private message Visit poster's website Reply with quote
DenimJeans



Joined: 29 Dec 2023
Posts: 11
DenimJeans 04 Jan 2024, 15:07
thanks revolution, indeed I tried all combinations of {[(, but not the angle brackets .. haha

perfect thanks!
and creating an array of the struct via macro to access them later via named label also possible?

so I access them later via
tp1 .. tp100 .....

Code:
mov eax,[tp1+TRIS.pt1.x]
    
??
Post 04 Jan 2024, 15:07
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 04 Jan 2024, 15:25
Code:
tp1: rb sizeof.TRIS * 100    
Post 04 Jan 2024, 15:25
View user's profile Send private message Visit poster's website Reply with quote
DenimJeans



Joined: 29 Dec 2023
Posts: 11
DenimJeans 04 Jan 2024, 15:45
ok, nice, thanks again.
just for completeness:
Code:
struct TRIS
        pt1 POINT 8,9       
ends

t1:
rept 100 {
    local pt
    pt TRIS
}    

would also copy the initialized values (8,9) to the copies and your suggestion initialize with unknown (0) values.

Have a great day, thanks
DJ
Post 04 Jan 2024, 15:45
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1637
Location: Toronto, Canada
AsmGuru62 04 Jan 2024, 19:10
Also, to use structures inside procedures as local variables:
Code:
proc foo uses ebx esi edi, param1:DWORD, param2:DWORD
    local   var1:TRIS
    local   arrayOfThose[16]:TRIS

    ;
    ; load a pointer to a single structure variable into EAX
    ;
    lea     eax, [var1]
    ;
    ; load a structure member of 'var1' into ECX
    ;
    mov     ecx, [eax + TRIS.xxxxxx]
    ;
    ; load pointer to array into ESI
    ;
    lea     esi, [arrayOfThose]
    add     esi, sizeof.TRIS        ; ESI --> next array element
    add     esi, sizeof.TRIS        ; ESI --> next array element
    add     esi, sizeof.TRIS        ; ESI --> next array element
    add     esi, sizeof.TRIS        ; ESI --> next array element

    ; ... you get it?..

    ret
endp
    
Post 04 Jan 2024, 19:10
View user's profile Send private message Send e-mail Reply with quote
DenimJeans



Joined: 29 Dec 2023
Posts: 11
DenimJeans 05 Jan 2024, 07:28
that also nice, thanks AsmGuru62
how can I access for example the 10th element then? like so or is there a simpler way:
Code:
    local arrayOfThose[16]:TRIS 
    lea esi,[arrayOfThose]
    mov eax,10
    mov ecx,sizeof.TRIS
    mul ecx
    add esi ,eax
    mov [esi+TRIS.pt.x],0x11111111
    mov [esi+TRIS.pt.y],0x22222222    


and 2nd question: assigning values to the 10th item would not be possible, right? I need to access them each single by using their members?:
Code:
arrayOfThose[10] <0x111111,0x222222>,0x555555,0x666666 ;wrong?
mov [esi+TRIS.pt.x],0x11111111 ;correct?    
Post 05 Jan 2024, 07:28
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 05 Jan 2024, 08:08
To access the 10th element.
Code:
mov [arrayOfThose + 9 * sizeof.TRIS + TRIS.pt.x],0x11111111 ; first element is index 0, second is 1, etc.    
Post 05 Jan 2024, 08:08
View user's profile Send private message Visit poster's website Reply with quote
DenimJeans



Joined: 29 Dec 2023
Posts: 11
DenimJeans 05 Jan 2024, 09:06
thanks revolution. works now as expected.
and the ".data" section requires to be at the beginning and not end of the assembly, right? Otherwise it does not work for me.
Post 05 Jan 2024, 09:06
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 05 Jan 2024, 09:27
There are no location requirements for any sections. Put them anywhere.
Post 05 Jan 2024, 09:27
View user's profile Send private message Visit poster's website 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.