4

The NASM Documentation describes the special tokens $ and $$:

NASM supports two special tokens in expressions, allowing calculations to involve the current assembly position: the $ and $$ tokens. $ evaluates to the assembly position at the beginning of the line containing the expression; so you can code an infinite loop using JMP $. $$ evaluates to the beginning of the current section; so you can tell how far into the section you are by using ($-$$).

I understand how to overcome the lack of $ in GNU Assembly - by declaring a label on the preceding line and using its address:

xgrndsize      equ     $ - xgrnd

becomes:

xgrnd_end:
                .set       xgrndsize, xgrnd_end - xgrnd

How can I obtain the address of the current section without $$?

user2023370
  • 10,488
  • 6
  • 50
  • 83
  • 3
    GAS has `.` instead of `$`. It's not a lack, just different syntax. (I'm not sure about an equivalent for `$$`, though.) Related: [Calculating padding length with GAS AT&T directives for a boot sector?](https://stackoverflow.com/questions/47859273/calculating-padding-length-with-gas-att-directives-for-a-boot-sector) shows an example of `.space 510-(.-_start)` as an alternative to `$ - $$`. – Peter Cordes Mar 11 '18 at 10:20
  • 3
    I don't think you can get the current section, but you can get any section's address by using its name. – Jester Mar 11 '18 at 12:38

0 Answers0