Reputation: 315
I've read the documentation of Fasm, but I can't figure out this. In Nasm I'd first declare a struct in ".bss" and then define it in ".data":
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.a, dw 123
at my_struct.b dw, 0x123
at my_struct.c db, "fdsfds"
at my_struct.d db 2222
endstruc
How can I do this in FASM exactly?
; declaring
struct my_struct
.a rw 1
.b rw 1
.c rb 1
.d rb 1
ends
; or maybe this way?
; what's the difference between these 2?
struct my_struct
.a dw ?
.b dw ?
.c db ?
.d db ?
ends
1) Firstly, is that correct? Or should I use the macros "sturc { ... }" If so, how exactly?
2) Second, how can I initialize it in ".data"?
3) also there's a question in my code
Note it's an application for Linux 64
Upvotes: 3
Views: 2409
Reputation: 7051
The struc
in FASM is almost the same as macro
, only named with a label at the front.
The struct
is actually a macro, that makes definitions easier.
If you are using FASM include files where struct
macro is defined, following code will allow you to initialize structures:
; declaring (notice the missing dots in the field names!)
struct my_struct
a dw ?
b dw ?
c db ?
d db ?
ends
; using:
MyData my_struct 123, 123h, 1, 2
You can read more about FASM struct
macro implementation in the Windows programming headers manual.
If you prefer to not use the FASM struct
macro, you still can define initialized structures using the native FASM syntax, following way:
; definition (notice the dots in the field names!)
struc my_struct a, b, c, d {
.a dw a
.b dw b
.c db c
.d db d
}
; in order to be able to use the structure offsets in indirect addressing as in:
; mov al, [esi+mystruct.c]
virtual at 0
my_struct my_struct ?, ?, ?, ?
end virtual
; using:
MyData my_struct 1, 2, 3, 4
Upvotes: 2