What is the "dot symbol" (.) in assembly and what is it useful for?
. is the location counter — it always equals the address of the very spot the assembler is currently writing to.
* The location counter advances one byte per emitted character; subtracting the start label yields the string length as a compile-time constant. *
Think of the assembler as walking left-to-right through your file, placing bytes into memory and advancing a cursor. That cursor's address is .. Because you can do arithmetic with it, you can compute things like a string's length at assembly time, with zero runtime cost:
hstr:
.ascii "Hello, world!\n"
hlen = . - hstr
Step by step:
hstr:records the current address (say0x1000)..ascii "Hello, world!\n"writes 14 bytes — the location counter advances to0x100E.- Now
.equals0x100E, sohlen = . - hstr = 0x100E - 0x1000 = 14.
hlen becomes a compile-time constant baked into the binary — no runtime strlen() needed. Edit the string and reassemble, and hlen updates itself automatically.
Tip: This is exactly how the classic hand-written "Hello, world" passes a count to the write syscall without hardcoding a magic number.
Go deeper:
Using as — the GNU Assembler manual — the location counter '.' and assemble-time arithmetic in the manual.
GNU Assembler (Wikipedia) — GAS overview.