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

InvalidBrainException picture InvalidBrainException · Apr 28, 2012 · Viewed 53.3k times · Source

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?

Answer

Will Hartung picture Will Hartung · Apr 28, 2012

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.