问题
I tried to create a variable in the BSS section in NASM:
section .bss
i DD 12345
But when trying to create an object file I got the following warning:
warning: attempt to initialize memory in BSS section `.bss': ignored
Which is understandable I suppose since the BSS section can only contain uninitialized variables. So I attempted the following:
section .bss
i DD 0
But I still get the same warning.
回答1:
Use RESB
and friends. See the nasm manual:
3.2.2 RESB and Friends: Declaring Uninitialized Data
RESB, RESW, RESD, RESQ, REST, RESO, RESY and RESZ are designed to be used in the BSS section of a module: they declare uninitialized storage space. Each takes a single operand, which is the number of bytes, words, doublewords or whatever to reserve. As stated in section 2.2.7, NASM does not support the MASM/TASM syntax of reserving uninitialized space by writing DW ? or similar things: this is what it does instead. The operand to a RESB-type pseudo-instruction is a critical expression: see section 3.8.
For example:
buffer: resb 64 ; reserve 64 bytes
来源:https://stackoverflow.com/questions/27909823/how-to-create-a-variable-in-the-bss-section-in-nasm