Author Topic: reserving space in nasm code for later data  (Read 16199 times)

Offline mik3ca

  • Jr. Member
  • *
  • Posts: 30
reserving space in nasm code for later data
« on: January 10, 2021, 04:08:44 PM »
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.

Offline debs3759

  • Global Moderator
  • Full Member
  • *****
  • Posts: 224
  • Country: gb
    • GPUZoo
Re: reserving space in nasm code for later data
« Reply #1 on: January 10, 2021, 07:43:16 PM »
to save x spaces, you can use

 
Code: [Select]
label:    times x db 0
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.
My graphics card database: www.gpuzoo.com

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: reserving space in nasm code for later data
« Reply #2 on: January 10, 2021, 10:41:39 PM »
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




Offline mik3ca

  • Jr. Member
  • *
  • Posts: 30
Re: reserving space in nasm code for later data
« Reply #3 on: January 10, 2021, 11:18:44 PM »
Debs answer seems to work for me. it was the "times" keyword that I needed.