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

徘徊边缘 提交于 2019-11-27 01:18:53

It means the address of "here". In here "here" is the byte after the end of the msg string. Any assembler documentation will describe this. Read the documentation.

In this case, the $ means the current address according to the assembler. $ - msg is the current address of the assembler minus the address of msg, which would be the length of the string.

NASM documentation

http://www.nasm.us/doc/nasmdoc3.html#section-3.5

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 $.

http://www.nasm.us/doc/nasmdoc3.html#section-3.2.4

EQU defines a symbol to a given constant value: when EQU is used, the source line must contain a label. The action of EQU is to define the given label name to the value of its (only) operand. This definition is absolute, and cannot change later. So, for example,

message         db      'hello, world' 
msglen          equ     $-message

defines msglen to be the constant 12

Sahil Singh

$ is used to refer to the current address and $$ is used to refer to the address of the start of current section in assembly.

example:

section .text
  Mov A,0x0000
  Mov B,0x0000
  Mov C,0x0000

for 3rd line $ refers to the address of the line itself while $$ refers to the address of the 1st line (where our section started). This convention works for me in nasm.

source:nasm.us

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!