Author Topic: Understanding how NASM macros(?) work  (Read 5902 times)

Offline scmaccal

  • Jr. Member
  • *
  • Posts: 5
Understanding how NASM macros(?) work
« on: October 01, 2013, 05:00:16 PM »
Greetings,

I would like to see how: times 510-($-$$) db 0 and db works from a assembly language point of view. Is there an option that I can add that will produce the assembly code of these NASM macros(?) when I assemble a program? I just tried the -l option but that was not helpful.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Understanding how NASM macros(?) work
« Reply #1 on: October 02, 2013, 04:13:33 AM »
It's just a bunch of zeros - sufficient to pad your bootsector (?) out to 510 bytes. (bytes 511 and 512 are the boot signature) Ndisasm would show them... but would try to disassemble them. A hex dump would show them. Not much to see...

Best,
Frank


Offline scmaccal

  • Jr. Member
  • *
  • Posts: 5
Re: Understanding how NASM macros(?) work
« Reply #2 on: October 02, 2013, 02:44:23 PM »
Frank,

Thank you for replying. I did in fact do a disassemble of the binary in question. You are correct, a bunch of zeros. :) So my question now is how would I go about writing the code that does the same as:
Code: [Select]
times 510-($-$$) db 0 by hand. I suspect you may see a theme with this post and the other one that you were kind enough to answer. I want to use as much Intel syntax as possible in my programs. I am doing this because I want to develop a deeper knowledge of how to program in assembly language without relying on the assembler to do the work for me. If I wanted that I would write in C. ;)

Kind regards,

Scott

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Understanding how NASM macros(?) work
« Reply #3 on: October 02, 2013, 04:24:12 PM »
Hi Scott,

Well, literally:
Code: [Select]
db 0
db 0
db 0
db 0
; enough times
but you could do:
Code: [Select]
db 0, 0, 0, 0, 0 ; enough times
with the same result.

When I can get both remaining brain cells to fire at the same time, I can do things Nasm can't do. Counting bytes isn't one of them. Nasm can count bytes faster and more accurately than I can. If you've got more brain cells than you know what to do with, you can count 'em yourself of course. I've gotta save my strength! :)

Best,
Frank