nasm“尝试初始化 bss 部分中的内存”

问题描述 投票:0回答:2

我试图获得组装的基本感觉,这是我的代码:

section .text
   global _start     ;must be declared for linker (ld)

section  .bss
   num resb 5

_start:             ;tells linker entry point
   mov  edx,len     ;message length
   mov  ecx,msg     ;message to write
.
.
.

程序未编译,并显示错误消息“警告:尝试初始化 BSS 部分‘.bss'中的内存:已忽略”。

我没有找到有用的答案,有人可以告诉我出了什么问题吗?

assembly nasm
2个回答
1
投票

您的

section .bss
需要位于文本部分之后或之前。您现在正在做的是将代码放入
bss
部分。相反,你应该这样做:

section .rodata
    msg: db "Hello"
    len: equ $-msg

section .bss
    num resb 5

section .text
    global _start

_start:
    mov ecx, msg
    mov edx, len
.
.
.

0
投票

我遇到了一些具体问题,但我会发布它,以防它对某人有帮助。

我声明了以下结构:

struc ctx_t
    .next: resd 1
    .prev: resd 1
    .a:    resd 1
    .c:    resd 1
endstruc

一段时间后,我添加了一个

.b
成员:

struc ctx_t
    .next: resd 1
    .prev: resd 1
    .a:    resd 1
    .b:    resd 1
    .c:    resd 1
endstruc

但忘记在另一个文件上编辑结构的实际定义:

section .bss

    first_ctx:
        istruc ctx_t
            at ctx_t.next, resd 1
            at ctx_t.prev, resd 1
            at ctx_t.a,    resd 1
            ; Missing b!
            at ctx_t.c,    resd 1
        iend

汇编器向我发出这些警告(全部在

ctx_t.c
行):

src/file.asm:9: warning: attempt to initialize memory in BSS section `.bss': ignored [-w+other]
src/file.asm:9: warning: attempt to initialize memory in BSS section `.bss': ignored [-w+other]
src/file.asm:9: warning: attempt to initialize memory in BSS section `.bss': ignored [-w+other]
src/file.asm:9: warning: attempt to initialize memory in BSS section `.bss': ignored [-w+other]
© www.soinside.com 2019 - 2024. All rights reserved.