我很想知道是否有任何特殊的 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 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
这是相同 idiom used in NASM (len equ $ - symbol
) 的 GAS 版本让汇编器为您计算某物的长度。
关于assembly - GNU GAS 汇编中是否有代表当前地址的符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8987767/