I am curious to know is there any special GAS syntax to achieve the same like in NASM example:
SECTION .data
msg: db "Hello World",10,0 ; the 0-terminated string.
len: equ $-msg ; "$" means current address.
Especially I'm interested in the symbol $
representing the current address.
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 thatas
is assembling into. Thus, the expressionmelvin: .long .
definesmelvin
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
is GAS version of the same idiom used in NASM (len equ $ - symbol
) idiomatic way to get the assembler to calculate the length of something for you.