assembly - GNU GAS 汇编中是否有代表当前地址的符号?

标签 assembly gnu gnu-assembler memory-address

我很想知道是否有任何特殊的 GAS 语法可以实现与 NASM 示例中相同的效果:

SECTION .data       

    msg:    db "Hello World",10,0  ; the 0-terminated string.
    len:    equ $-msg              ; "$" means current address.

特别是我对代表当前地址的符号 $ 感兴趣。

最佳答案

摘自 info as (GNU Binutils 2.21.90),或在线查看 GAS 手册: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

这是相同 idiom used in NASM (len equ $ - symbol) 的 GAS 版本让汇编器为您计算某物的长度。

关于assembly - GNU GAS 汇编中是否有代表当前地址的符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8987767/

相关文章:

c 文件中内联汇编代码的编译错误,可能与分支有关

linux - 在关联文件中增加新版本的版本号(文档)

html - 我可以在我的 Joomla 网站中使用 GNU GPL 字体 (@fontface) 吗?

c - 64 位 GCC 混合 32 位和 64 位指针

assembly - 在程序集 x86 中对齐

c++ - sizeof(*this) 给出了错误的值

foreach - GNU Make 失败,foreach->eval->call

visual-studio - Microsoft 汇编程序到 GNU 汇编程序的转换

gcc - GNU 汇编宏

在汇编段错误中调用 C 函数