title: How to get the size of nasm-assembled instructions in boot sector?
body: <p>I am assembling a program with nasm to fit in the boot sector (512 bytes max).</p>
  <p>e.g. <code>nasm -f bin boot.asm -o boot.bin</code></p>
  <p>The last two lines of the program pad the remaining space with 0 and add the magic bytes:</p>
  <pre><code>times 510 - ($-$$) db 0 ; Pad the remaining of the first 510 bytes with 0
  dw 0xaa55               ; Magic bytes required at end of boot sector
  </code></pre>
  <p>The outputted <code>boot.bin</code> file is always 512 bytes (expected), so I cannot trivially look at the size of <code>boot.bin</code> to get the size of the meaningful (non-padding and non-magic bytes) instructions.</p>
  <p>I imagine it would work to print <code>($-$$)</code> at assembly time (similar to <code>#warning</code> or <code>#pragma message</code> for gcc), but I cannot find any way to print at nasm assembly time.</p>
  <p>Is there a clean or straightforward way to know the size of the instructions before padding?</p>
  <p>It would be nice to avoid hacky methods like printing at runtime or searching backwards through <code>boot.bin</code> looking for a non-zero value.</p>