assembly - nasm 汇编语言中的 $ 是什么?

标签 assembly nasm

这个问题在这里已经有了答案:





What does the dollar sign ($) mean in x86 assembly when calculating string lengths like "$ - label"? [duplicate]

(3 个回答)


3年前关闭。




这是我的汇编级代码...

section .text
global _start
_start  mov eax, 4
        mov ebx, 1
        mov ecx, mesg
        mov edx, size
        int 0x80
exit:   mov eax, 1
        int 0x80
section .data
mesg    db      'KingKong',0xa
size    equ     $-mesg

输出:
root@bt:~/Arena# nasm -f elf a.asm -o a.o
root@bt:~/Arena# ld -o out a.o
root@bt:~/Arena# ./out 
KingKong
size equ $-mesg行中的$是多少.有人请解释一下$使用的符号...

最佳答案

$指示汇编器进行时的“当前位置”。在这种情况下,它用于存储 mesg 的长度字符串。

size equ $-msg

说“制作标签 size 并将其设置为等于当前位置减去 mesg 标签的位置”。由于“当前位置”是字符串 "KingKong\n"末尾的一个,size设置为该长度(9 个字符)。

来自 documentation :

NASM supports two special tokens in expressions, allowing calculations to involve the current assembly position: the $ and $$ tokens. $ evaluates to the assembly position at the beginning of the line containing the expression; so you can code an infinite loop using JMP $. $$ evaluates to the beginning of the current section; so you can tell how far into the section you are by using ($-$$).

关于assembly - nasm 汇编语言中的 $ 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17900262/

相关文章:

sorting - 打开文件,删除零,排序 - NASM

assembly - 警告 : label alone on a line without a colon might be in error

c - 试图从 linux 内核理解一段内联臂程序集

assembly - 如何从软盘运行简单的操作系统?

assembly - 将指令转换为汇编代码 lods 和 stos 以便 NASM 可以编译

assembly - 我可以使用二进制在汇编中编写整数常量吗?

c++ - 程序集显示大量重复代码?

c - 了解反汇编的 C 代码(特别是像 var_28 = dword ptr -28h 之类的东西)(二进制炸弹实验室)

macos - 为什么 Apple 使用 R8l 作为字节寄存器而不是 R8b?

c++ - 循环展开和循环平铺