Assembly 关于在Fasm程序集中声明和初始化结构

Assembly 关于在Fasm程序集中声明和初始化结构,assembly,fasm,Assembly,Fasm,我已经阅读了Fasm的文档,但我无法理解这一点。在Nasm中,我首先在“.bss”中声明一个结构,然后在“.data”中定义它: 在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

我已经阅读了Fasm的文档,但我无法理解这一点。在Nasm中,我首先在“.bss”中声明一个结构,然后在“.data”中定义它:

在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) 首先,这是正确的吗?或者我应该使用宏“sturc{…}”,如果是,具体如何使用

2) 第二,如何在“.data”中初始化它

3) 我的代码中还有一个问题


注意,它是一个用于Linux 64的应用程序,FASM中的
struc
几乎与
macro
相同,只是前面有一个标签

结构实际上是一个宏,使定义更容易

如果您使用的是定义了
struct
宏的FASM include文件,则以下代码将允许您初始化结构:

; 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
您可以在手册中阅读有关FASM
struct
宏实现的更多信息

如果不想使用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

我会推荐FASM mesage板作为更好的答案我不知道nasm,但通常“rb/rw/rd”只“保留”一个字节/字/双字,根本不接触它(未初始化)。“db?/dw?/dd?”也是如此。要对其进行初始化,必须使用“db/dw/dd value”,例如
dw 2000
(word with value 2000)或
db 20
(字节20)<代码>rw 2000将保留2000块words@Torito我不熟悉所有的骗子,所以我不会一概而论。我只能假设所有人(大多数?)都是一样的them@Tommylee2k,我认为你是对的(错的?)。
; 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