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

本小妞迷上赌 提交于 2019-12-19 10:23:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!