Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

For example, if we were writing a simple hello world type program, the .data section might contain something like:

section .data  msg     db      'Enter something: ' len     equ     $ - msg 

What does the $ in this example represent, and why does $ - msg equal the length of the string?

like image 589
InvalidBrainException Avatar asked Apr 28 '12 06:04

InvalidBrainException


People also ask

What is a label in x86?

A label can be placed at the beginning of a statement. During assembly, the label is assigned the current value of the active location counter and serves as an instruction operand. There are two types of lables: symbolic and numeric.

What is '%' in assembly language?

This is AT&T syntax for x86. In AT&T % generally denotes a register while $ is reserved for immediates. If you omit th $ the assembler would interpret the 48 as an address.

What does #$ mean in assembly?

The dollar $ sign simply means the value after it is given in hex. No dollar would mean it is in decimal. i.e. lda #$ff. is the same as.

What does JMP mean in assembly?

In the x86 assembly language, the JMP instruction performs an unconditional jump. Such an instruction transfers the flow of execution by changing the program counter.


1 Answers

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.

like image 82
Will Hartung Avatar answered Sep 30 '22 11:09

Will Hartung