NASM Forum > Using NASM
reserving space in nasm code for later data
(1/1)
mik3ca:
What I'm trying to do is reserve a large block of code memory so that I can fill it with data later as the program executes.
Currently I can reserve 1, 2, and 4 bytes of data using db 0h, dw 0h, and dd 0h respectively.
I could do something like db '<insert spaces here>' if I want to manually reserve a block of memory, but that would be a very tedious task if say for example, I want to reserve 16KB of memory because then that would mean I'd have to do db then 16,384 spaces between the quotes and I have no time to be counting that many spaces every hour.
Is there a simpler way to do this in nasm? I'm using version nasm 2.10.04 for linux.
debs3759:
to save x spaces, you can use
--- Code: ---label: times x db 0
--- End code ---
Of course, "label" can be whatever you want, and possible be left out (although that is generally not practical).
You can also use resb, resw, resd to reserve uninitialised space. They would normally be in section .bss, but I imagine they will be OK in your code section.
Frank Kotler:
In Linux, the code section (section .text) is usually read-only, so this won't work well. It would work in .data, but Nasm would complain. The advantage to secrion .bss is that this empty space does not take up space on the disk file.
Best,
Frank
mik3ca:
Debs answer seems to work for me. it was the "times" keyword that I needed.
Navigation
[0] Message Index
Go to full version