Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of dollar sign in gnu assembly labels

Tags:

gcc

assembly

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 )

like image 786
Zack Avatar asked Apr 24 '17 15:04

Zack


1 Answers

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

like image 104
Artyom Avatar answered Nov 16 '22 17:11

Artyom