[英]About declaring and initializing a structure in Fasm assembly
I've read the documentation of Fasm, but I can't figure out this. 我已经阅读了Fasm的文档,但我无法弄清楚这一点。 In Nasm I'd first declare a struct in ".bss" and then define it in ".data":
在Nasm中,我首先在“.bss”中声明一个结构,然后在“.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? 我怎样才能在FASM中完成这项工作?
; 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? 1)首先,这是正确的吗? Or should I use the macros "sturc { ... }" If so, how exactly?
或者我应该使用宏“sturc {...}”如果是这样,究竟是怎么回事?
2) Second, how can I initialize it in ".data"? 2)其次,如何在“.data”中初始化它?
3) also there's a question in my code 3)我的代码中也有一个问题
Note it's an application for Linux 64 请注意,它是Linux 64的应用程序
The struc
in FASM is almost the same as macro
, only named with a label at the front. 该
struc
在FASM是几乎相同macro
,只有在正面的标签命名。
The struct
is actually a macro, that makes definitions easier. struct
实际上是一个宏,使定义更容易。
If you are using FASM include files where struct
macro is defined, following code will allow you to initialize structures: 如果您正在使用FASM包含定义了
struct
宏的文件,则以下代码将允许您初始化结构:
; 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. 您可以在Windows编程头文件手册中阅读有关FASM
struct
macro实现的更多信息。
If you prefer to not use the FASM struct
macro, you still can define initialized structures using the native FASM syntax, following way: 如果您不想使用FASM
struct
宏,您仍然可以使用本机FASM语法定义初始化结构,方法如下:
; 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.