Difference between “%register” and “(%register)” in x86 assembly AT&T syntax?

牧云@^-^@ 提交于 2020-01-04 05:58:23

问题


So far my current understanding is something along the lines of: movq %rdi, %rax will move the value from the register %rdi to the register %rax

and movq (%rdi), %rax will move the value from memory at (%rdi) to the register %rax

However, I'm having trouble understanding what this actually means functionally. In what instance will these two assembly lines end with a different result?


回答1:


It will yield a different result every time the memory at adress (%rdi) does not contain its own adress. In other words, almost always. And when not, it's just a coincidence or a consequence of very unusual code.

Some C to demonstrate the equivalent question "When will the two printf statements print the same result?"

#include <stdio.h>

int main()
{
  int a,*p;
  int b=5;
  p=&b;

  a=*p;
  printf("%d\n", a);
  a=(int)p;
  printf("%d\n", a);
}

And, yes, this yields the warning cast from pointer to integer of different size but that's beside the point.



来源:https://stackoverflow.com/questions/46679574/difference-between-register-and-register-in-x86-assembly-att-syntax

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