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

徘徊边缘 提交于 2019-12-04 05:33:58

问题


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.



来源:https://stackoverflow.com/questions/42727668/does-referencing-constants-without-a-dollar-sign-have-a-distinct-meaning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!