Meaning of (%eax) in AT&T syntax?

核能气质少年 提交于 2019-12-18 11:18:42

问题


You'll have to excuse me, I'm brand new to x86 assembly, and assembly in general.

So my question is, I have something like:

addl %edx,(%eax)

%eax is a register which holds a pointer to some integer. Let's call it xp

Does this mean that it's saying: *xp = *xp + %edx? (%edx is an integer)

I'm just confused where addl will store the result. If %eax is a pointer to an int, then (%eax) should be the actual value of that int. So would addl store the result of %edx+(%eax) in *xp? I would really love for someone to explain this to me!

I really appreciate any help!


回答1:


Yes, this instruction is doing exactly what you think it's doing.

Most x86 arithmetic instructions take two operands: a source and a destination. In AT&T syntax (used here), the destination is always the right operand. So with an instruction like:

addl %edx, %eax

the values in edx and eax are added together and the result is stored in eax. However, in your example, (%eax) is a memory operand; that's what parentheses mean in AT&T syntax (like square-brackets in NASM syntax).

This means that eax is treated as a pointer, so the right operand is taken from the address pointed to by eax, and the result is stored to the same address.



来源:https://stackoverflow.com/questions/1619131/meaning-of-eax-in-att-syntax

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