gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 01:07:50 28 4
gpt4 key购买 nike

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





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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com