14

What is the meaning of a dollar sign in front of a gnu assembly label?

For example, what is the difference between mov msg, %si and mov $msg, %si

(For more context, I'm playing around with the x86 Bare Metal Examples: https://github.com/cirosantilli/x86-bare-metal-examples/blob/master/bios_hello_world.S)

#include "common.h"
BEGIN
    mov $msg, %si
    mov $0x0e, %ah
loop:
    lodsb
    or %al, %al
    jz halt
    int $0x10
    jmp loop
halt:
    hlt
msg:
    .asciz "hello world"

(What do the dollar ($) and percentage (%) signs represent in assembly intel x86? discusses the general use of % before registers and $ before constants; but, I don't think it lays out the use of $ with labels nearly as clearly as the answer below )

Community
  • 1
  • 1
Zack
  • 6,232
  • 8
  • 38
  • 68
  • 2
    Possible duplicate of [What do the dollar ($) and percentage (%) signs represent in assembly intel x86?](http://stackoverflow.com/questions/9196655/what-do-the-dollar-and-percentage-signs-represent-in-assembly-intel-x86) – Ross Ridge Apr 24 '17 at 17:37

1 Answers1

11

You use $(dollar) sign when addressing a constant, e.g.: movl $1, %eax (put 1 to %eax register) or when handling an address of some variable, e.g.: movl $var, %eax (this means take an address of var label and put it into %eax register). If you don't use dollar sign that would mean "take the value from var label and put it to register".

Artyom
  • 284
  • 2
  • 14
  • 2
    That makes sense. If that is the case, then shouldn't the labels used with jmp also begin with $? – Zack Apr 28 '17 at 19:11
  • 2
    Why can't you use "jmp $loop" (jmp with $). Would it do something different? Is is valid syntax or not? And what exactly would be stored in eax if you use "movl var, %eax"? Is it even valid syntax? Is it perhaps equivalent to movl ($var), %eax? – Coder Nr 23 Aug 01 '18 at 07:40