Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does referencing constants without a dollar sign have a distinct meaning?

I wrote:

mov 60, %rax

GNU as accepted it, although I should have written

mov $60, %rax

Is there any difference between two such calls?

like image 315
marmistrz Avatar asked Dec 03 '22 13:12

marmistrz


2 Answers

Yes; the first loads the value stored in memory at address 60 and stores the result in rax, the second stores the immediate value 60 into rax.

like image 85
davmac Avatar answered Dec 20 '22 03:12

davmac


Just try it...

mov 60,%rax
mov $60,%rax
mov 0x60,%rax


0000000000000000 <.text>:
   0:   48 8b 04 25 3c 00 00    mov    0x3c,%rax
   7:   00 
   8:   48 c7 c0 3c 00 00 00    mov    $0x3c,%rax
   f:   48 8b 04 25 60 00 00    mov    0x60,%rax
  16:   00 

Ewww! Historically the dollar sign meant hex $60 = 0x60, but gas also has a history of screwing up assembly languages...and historically x86 assembly languages allowed 60h to indicate hex, but got an error when I did that.

So with and without the dollar sigh you get a different instruction.

0x8B is a register/memory to register, 0xC7 is an immediate to register. so as davmac answered mov 60,%rax is a mov memory location to register, and mov $60,%rax is mov immediate to register.

like image 36
old_timer Avatar answered Dec 20 '22 04:12

old_timer