What does the dollar sign ($) mean in x86 assembly when calculating string lengths like "$ - label"? [duplicate]

For example, if we were writing a simple hello world type program, the .data section might contain something like:

section .data

msg     db      'Enter something: '
len     equ     $ - msg

What does the $ in this example represent, and why does $ - msg equal the length of the string?


In this case, the $ means the current address according to the assembler. $ - msg is the current address of the assembler minus the address of msg, which would be the length of the string.


NASM documentation

http://www.nasm.us/doc/nasmdoc3.html#section-3.5

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 $.

http://www.nasm.us/doc/nasmdoc3.html#section-3.2.4

EQU defines a symbol to a given constant value: when EQU is used, the source line must contain a label. The action of EQU is to define the given label name to the value of its (only) operand. This definition is absolute, and cannot change later. So, for example,

message         db      'hello, world' 
msglen          equ     $-message

defines msglen to be the constant 12