如何在 NASM 的 BSS 部分创建变量?

How to create a variable in the BSS section in NASM?

我试图在 NASM 的 BSS 部分创建一个变量:

section .bss
    i DD 12345

但是当我试图创建一个目标文件时,我收到了以下警告:

warning: attempt to initialize memory in BSS section `.bss': ignored

我想这是可以理解的,因为 BSS 部分只能包含未初始化的变量。所以我尝试了以下操作:

section .bss
    i DD 0

但我仍然收到相同的警告。

使用RESB和朋友。见 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