Does referencing constants without a dollar sign h

2019-02-28 15:05发布

问题:

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?

回答1:

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.



回答2:

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.