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

标签 assembly fasm

我读过 Fasm 的文档,但我不明白这一点。在 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

我怎样才能在 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中的strucmacro几乎相同,只是在前面加上一个标签来命名。

struct 实际上是一个宏,它使定义更容易。

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

您可以在 Windows programming headers 中阅读有关 FASM struct 宏实现的更多信息。手册。

如果您不想使用 FASM struct 宏,您仍然可以使用 native 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

关于assembly - 关于在 Fasm 程序集中声明和初始化结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41929091/

相关文章:

组装拼图-二元炸弹

assembly - .double 类型的变量是否存储在两个寄存器中?

assembly - PPC clrlwi 命令 - 值数字是否包含在掩码中?

windows - Fasm x64 消息框

assembly - 有好的 NASM/FASM 教程吗?

x86 - 汇编程序 : Using "Flat assembler" how do I produce EXE files (compile, 链接..)?

assembly - 如何避免使用PUSH而不使用POP?

linux - NASM中的printf最简单的工作示例失败

assembly - 用汇编语言编写,兼容性如何发挥作用?

assembly - 在堆栈中创建命名变量