What's the real meaning of $$ in nasm

前端 未结 1 1028
耶瑟儿~
耶瑟儿~ 2020-12-07 02:42

$$ is defined as current segment address in NASM. But what\'s the real meaning of it? I wrote two asm files to test it:

a.asm

相关标签:
1条回答
  • 2020-12-07 03:29

    $$ is the address of the beginning of the current section. It is a relocatable value (not "scalar" - a word you will find in an error message, but not in the Manual). It is an offset, so doesn't care what's in a segment register.

    • Documentation: https://www.nasm.us/doc/nasmdoc3.html#section-3.5
    • example use case for a boot sector: https://www.nasm.us/doc/nasmdo13.html#section-13.1.3
    • Related: How does $ work in NASM, exactly? (since $$ is usually used with $).

    About the only thing it's useful for is $ - $$, the length of the section so far. $ - $$ is a "scalar" (as is any difference between labels) and can be used in expressions which would otherwise cause Nasm to whine about "not a scalar value".

    The section names "known" to Nasm depend on the output format - "-f obj" doesn't know any at all. .text, .data, and .bss are pretty universal - some output formats know others. Best place to find 'em is in the "output format" chapters in the Manual. http://www.nasm.us if you didn't get the Manual with your download. These names are case sensitive, and the leading '.' is required.

    I have the feeling that there's a "question" in here that I'm missing. What are you actually trying to do?

    0 讨论(0)
提交回复
热议问题