2

In nasm (Netwide Assembler), it is possible to find the address of the current instruction with $, and the address of the current section with $$. By using ($-$$) we therefore get the length of the section so far, and with the full instruction:

times 512-($-$$) db 0

we pad the remainder of a sector with zeros. This is typically used in small hello-world programs for OS development.

I have seen that GNU assembler supports constructs like rept to make repetions, and . (dot) can be used to get the current address. But I have not yet figured out exactly how to do the whole thing in gas.

So how can it be done?

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
rubund
  • 7,603
  • 3
  • 15
  • 24
  • 1
    Possibly this answer is what you are looking for? https://stackoverflow.com/a/47859400/3857942 – Michael Petch Jan 28 '18 at 09:45
  • Have you tried `.space 512-(.-begin)` where `begin` is an appropriately defined label? Though, this sort of problem is better solved with a linker script. – fuz Jan 28 '18 at 09:57
  • Thanks to both of you! It seems like a duplicate of the question you link to. Hopefully my way of phrasing the question should make it easier for others to find this answer via search engines. – rubund Jan 28 '18 at 10:17

0 Answers0