flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Linux > About structs

Author
Thread Post new topic Reply to topic
jorido



Joined: 23 Jan 2017
Posts: 35
About structs
I've read the documentation but I can't figure out this. In Nasm I'd first declare a struct in ".bss" and then define it in ".data":


Code:

                section ".bss"

                struc my_struct
                    .a resw 1
                    .b resw 1
                    .c resb 1
                    .d resb 1
                endstruc


                section ".data"

                my_struct_var1 istruc my_struct
                    at my_struct.adw 123
                    at my_struct.b dw0x123
                    at my_struct.c db"fdsfds"
                    at my_struct.d db 2222
                endstruc





How can I do this in FASM exactly?


Code:

        ; declaring

        struct my_struct
            .a rw 1
            .b rw 1
            .c rb 1
            .d rb 1
        ends

        ; or
        ; what's the difference between these 2?
        
        struct my_struct
            .a dw ?
            .b dw ?
            .c db ?
            .d db ?
        ends




1) Is that correct? Or should I use the macros "sturc { ... }" If so, how exactly?

2) How can I initialize it in ".data"?

3) also there's a question in my code


It's for Linux x64
Post 30 Jan 2017, 08:35
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14790
Location: Lost in translation
struc is the fasm native version, struct is the fasm high-level macro.

In fasm you can declare struc's anywhere before you use them no matter the current section, it makes no difference.

Code:
;declare
struc my_struc a,b,c,d {
        .a dw a
        .b dw b
        .c db c
        .d db d
}

;instantiate
my_label my_struc 0x3456,0x9876,'X','r'

;access
mov ax,[my_label.a]

Post 31 Jan 2017, 03:10
View user's profile Send private message Visit poster's website Reply with quote
jorido



Joined: 23 Jan 2017
Posts: 35
Can "struc" be used interchangeably with "struct" everywhere then?
Post 31 Jan 2017, 06:03
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14790
Location: Lost in translation
No. They are different things.

For example:
struc uses curly brackets, struct doesn't.
struc uses dots, struct doesn't.
struc allows embedded instructions, struct doesn't
etc.
Post 31 Jan 2017, 06:08
View user's profile Send private message Visit poster's website Reply with quote
jorido



Joined: 23 Jan 2017
Posts: 35
I mean, when I want to is merely define a simple structure with a few fields:


Code:

MyStruct:
  var1 'aaa'
  var2 ?
  var3 ?
  var4 123





can "struc" be used interchangeably with "struct"?
Post 31 Jan 2017, 08:37
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14790
Location: Lost in translation
No. Both the syntax and the operation are different.
Post 31 Jan 2017, 09:12
View user's profile Send private message Visit poster's website Reply with quote
jorido



Joined: 23 Jan 2017
Posts: 35
What those differences are? And when should be 1st and when 2nd?
Post 31 Jan 2017, 13:09
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14790
Location: Lost in translation
struc defines a new macro with all the normal features of a macro, except that it requires a label first, but otherwise there is no difference. You can make it do almost anything you need. If you have special or unusual requirements then this might be the one you want.

struct is already a macro with a whole lot of extra processing to define things like the size of each element, and it allows union and various other things. But the usage is mostly fixed. You can't make it do special processing for example, but it can already do many things so it might be just what you need for a particular purpose.

To decide which one to use it depends upon what you need from it. It would be too complex to try to enumerate all the various situations that could come up. Your question is very broad. If you have a particular use case then please ask about that and we can try to help you.
Post 31 Jan 2017, 13:36
View user's profile Send private message Visit poster's website Reply with quote
jorido



Joined: 23 Jan 2017
Posts: 35
Thanks.
Post 31 Jan 2017, 14:33
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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.