What do the dollar ($) and percentage (%) signs represent in x86 assembly?

独自空忆成欢 提交于 2019-11-29 10:52:23

问题


I am trying to understand how the assembly language works for a micro-computer architecture class, and I keep facing different syntaxes in examples:

sub $48, %esp
mov %eax, 32(%esp)

What do these codes mean? What is the 32 operand an addition to the esp register?


回答1:


Thats not Intel syntax, its AT&T syntax, also called GAS syntax.

the $ prefix is for immediates (constants), and the % prefix is for registers (they are required1).

For more about AT&T syntax, see also the [att] tag wiki.


1 Unless the noprefix option is specified, see here & here. But usually noprefix is only used with .intel_syntax noprefix, to get MASM-like syntax.




回答2:


Yes, "32(%esp)" indicates an offset of 32 from %esp.




回答3:


Compared to Intel syntax, AT&T syntax has many differences

  • $ signifies a constant (integer literal). Without it the number is an absolute address
  • % denotes a register
  • The source/destination order is reversed
  • () is used for memory reference, like [] in Intel syntax

So the above snippet is equivalent to

sub esp, 48         ; esp -= 48
mov [esp+32], eax   ; store eax to the value at the address `esp + 32`



回答4:


As @Necrolis said, that's written in AT&T syntax. It means:

subtract 48 from the register esp (the stack pointer).
store the contents of eax to the four bytes starting at (esp + 32).



回答5:


This is AT&T syntax for x86. In AT&T % generally denotes a register while $ is reserved for immediates. If you omit th $ the assembler would interpret the 48 as an address.



来源:https://stackoverflow.com/questions/9196655/what-do-the-dollar-and-percentage-signs-represent-in-x86-assembly

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