nasm中$$的真正含义是什么 [英] What's the real meaning of $$ in nasm

查看:607
本文介绍了nasm中$$的真正含义是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$$被定义为NASM中的当前段地址.但是它的真正含义是什么?我编写了两个asm文件进行测试:

$$ 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

a.asm

extern another

[section .text]
global _start
_start:
    mov ebx, $$
    call another

b.asm

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

使用gdb调试最终文件test,我发现尽管我用相同的名称定义了两个部分,但两个文件中的$$是不同的.所以我想:

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:

  1. 一旦我在文件中定义了一个节,$$的值就是该节的起始地址.与$$无关 所谓的段寄存器(cs,ss,fs,gs等).
  2. 如果我在另一个文件中定义了另一个具有相同名称的部分,则将其解释为不同的部分.但是,如果在同一个文件中定义了两个具有相同名称的节,则它们之间是否还有其他节定义,则始终将其解释为具有相同$$值的同一节.如下所示,两个.text部分完全相同.

  1. 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).
  2. 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

  • 我猜有一些NASM可以识别的部分名称,并在编译时将它们放在正确的位置.例如.data,那么NASM可以识别并使用它们执行某些操作的节名称是什么?非常感谢!

  • 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!

    推荐答案

    $$是当前部分开头的地址.它是可重定位的值(不是标量"-您会在错误消息中找到的单词,但在手册中找不到).这是一个偏移量,因此不必关心段寄存器中的内容.

    $$ is the address of the beginning of the current section. It is a relocatable value (not "scalar" - a word you will find in an error message, but not in the Manual). It is an offset, so doesn't care what's in a segment register.

    • Documentation: https://www.nasm.us/doc/nasmdoc3.html#section-3.5
    • example use case for a boot sector: https://www.nasm.us/doc/nasmdo12.html#section-12.1.3
    • Related: How does $ work in NASM, exactly? (since $$ is usually used with $).

    关于它唯一有用的是$ - $$,这是到目前为止的部分长度. $ - $$是一个标量"(标签之间的任何区别),可用于会导致Nasm抱怨不是标量值"的表达式中.

    About the only thing it's useful for is $ - $$, the length of the section so far. $ - $$ is a "scalar" (as is any difference between labels) and can be used in expressions which would otherwise cause Nasm to whine about "not a scalar value".

    Nasm的已知"部分名称取决于输出格式-"-f obj"一点也不知道. .text.data.bss非常通用-一些输出格式了解其他格式.找到'em'的最佳位置是在手册的输出格式"章节中. http://www.nasm.us (如果未随下载内容获得手册).这些名称区分大小写,并以."开头.是必需的.

    The section names "known" to Nasm depend on the output format - "-f obj" doesn't know any at all. .text, .data, and .bss are pretty universal - some output formats know others. Best place to find 'em is in the "output format" chapters in the Manual. http://www.nasm.us if you didn't get the Manual with your download. These names are case sensitive, and the leading '.' is required.

    我感觉这里缺少一个问题".您实际上想做什么?

    I have the feeling that there's a "question" in here that I'm missing. What are you actually trying to do?

    这篇关于nasm中$$的真正含义是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆