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

前端 未结 2 903
野的像风
野的像风 2021-01-22 05:41

I wrote:

mov 60, %rax

GNU as accepted it, although I should have written

mov $60, %rax

Is there

相关标签:
2条回答
  • 2021-01-22 06:27

    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.

    0 讨论(0)
  • 2021-01-22 06:36

    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.

    0 讨论(0)
提交回复
热议问题