什么是NASM汇编语言$? [英] What is $ in nasm assembly language?
问题描述
这是我的汇编级code ...
This is my assembly level code ...
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
什么是行的$大小EQU $ -mesg
。有人请解释一下关于使用 $
符号...
What is the $ in the line size equ $-mesg
. Some one please explain the about the $
symbol used ...
推荐答案
$
表示汇编的当前位置,因为它去一起。在这种情况下,它用于存储 MESG
字符串的长度。
$
indicates the 'current location' of the assembler as it goes along. In this case it's used to store the length of the mesg
string.
size equ $-msg
说做一个标签尺寸
并设置它等于到当前位置减去 MESG
标签的位置。由于当前位置一个过去字符串金刚\\ n,年底尺寸
设置为长度(9个字符)。
Says "make a label size
and set it equal to the current location minus the location of the mesg
label". Since the 'current location' is one past the end of the string "KingKong\n", size
is set to that length (9 characters).
从文档:
NASM支持前pressions两个特殊的记号,让计算涉及到当前的安装位置:在 $
和 $
标记。 $
计算为在包含前pression行开始的装配位置;所以你可以code。使用 JMP $
无限循环。 $
评估当前节的开始;所以你可以告诉你是多么遥远的部分用($ - $$)。
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 usingJMP $
.$$
evaluates to the beginning of the current section; so you can tell how far into the section you are by using($-$$)
.
这篇关于什么是NASM汇编语言$?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!