Is there a symbol that represents the current address in GNU GAS assembly?

Excerpt from info as (GNU Binutils 2.21.90), or online in the GAS manual: https://sourceware.org/binutils/docs/as/Dot.html

5.4 The Special Dot Symbol

The special symbol . refers to the current address that as is
assembling into. Thus, the expression melvin: .long . defines
melvin to contain its own address.

Assigning a value to . is treated the same as a .org directive.
Thus, the expression .=.+4 is the same as saying .space 4.

msg:    .ascii "Hello World!\n"       # not zero-terminated, use .asciz for that
msglen = . - msg                      # A .equ directive would be equivalent

This is a GAS version of the same idiom used in NASM (len equ $ - symbol) to get the assembler to calculate the length of something for you.

Leave a Comment