$$
is defined as current segment address in NASM. But what's the real meaning of it? I wrote two asm
files to test it:
a.asm
extern another
[section .text]
global _start
_start:
mov ebx, $$
call another
b.asm
[section .text]
global another
another:
mov eax, $$
ret
compile
nasm -f elf a.asm -g
nasm -f elf b.asm -g
ld -o test a.o b.o
Using gdb to debug the final file test
, I found that though I defined two sections with the same name, the $$
is different in both file. So I guess that:
- Once I defined a section in a file, the value of
$$
is the starting address of that section. And $$
has nothing to do with
the so-called segment registers(cs,ss, fs, gs, .etc).
If I have defined the another section with the same name in other file, it's interpreted as a different section. But if the two sections with the same name are defined in the same file, whether there are other section definitions between them, it's always interpreted as the same section, with the same $$
value. Such as follows, the two .text
sections are just the same.
[section .text]
global _start
_start:
mov ebx, $$
[section .d]
d:
mov ecx, $$
[section .text]
another:
mov eax, $$
ret
I guess there are some section names that NASM can recognize and put them to the right place when compiling. Such as .data
, then what are these section names that NASM can recognize and do something with them? Thanks a lot!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…