peterparker
peterparker

Reputation: 57

nasm "attempt to initialize memory in bss section"

I am trying to get a basic feel for assembly, here is my code:

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
.
.
.

The program does not compile with the error message "warning: attempt to initialize memory in BSS section `.bss': ignored ".

I did not find helpful answers on SO, can someone tell me what's wrong?

Upvotes: 4

Views: 2461

Answers (2)

trxgnyp1
trxgnyp1

Reputation: 428

I had a bit of a specific problem, but I will post it in case it helps someone.

I declared the following struct:

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

And after some time I added a .b member:

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

But forgot to edit the actual definition of the struct on another file:

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

And the assembler was giving me these warnings (all on the ctx_t.c line):

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]

Upvotes: 2

Markian
Markian

Reputation: 342

Your section .bss needs to be after or before your text section. What you are doing right now is putting you code in the bss section. Instead, you should do:

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

section .bss
    num resb 5

section .text
    global _start

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

Upvotes: 2

Related Questions