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.
Sample usages of
.
Minimal explicit example:
Common combo for string lengths:
s_len =
syntax explained at Is there a difference between equals sign assignment "x = 1" and ".equ x, 1" or ".set x, 1" in GNU Gas assembly?Infinite loop:
There is a useful comparison between gas and NASM here: http://www.ibm.com/developerworks/linux/library/l-gas-nasm/index.html
See in particular this part, which I think addresses your question:
Listing 2 also introduces the concept of a location counter (line 6). NASM provides a special variable (the $ and $$ variables) to manipulate the location counter. In GAS, there is no method to manipulate the location counter and you have to use labels to calculate the next storage location (data, instruction, etc.). For example, to calculate the length of a string, you would use the following idiom in NASM:
The $ gives the current value of the location counter, and subtracting the value of the label (all variable names are labels) from this location counter gives the number of bytes present between the declaration of the label and the current location. The equ directive is used to set the value of the variable STR_SIZE to the expression following it. A similar idiom in GAS looks like this:
The end label (pstr_end) gives the next location address, and subtracting the starting label address gives the size. Also note the use of .set to initialize the value of the variable STR_SIZE to the expression following the comma. A corresponding .equ can also be used. There is no alternative to GAS's set directive in NASM.
Excerpt from
info as
(GNU Binutils 2.21.90):