简体   繁体   English

C指针和AT&T Movl语法

[英]C Pointers & AT&T Movl Syntax

I'm trying to understand the difference between these two commands in AT&T assembly language. 我试图了解AT&T汇编语言中这两个命令之间的区别。

movl    %edx, %eax
movl    (%ebx), %eax

I understand that the first command takes the value in %edx and puts that value in %eax. 我知道第一个命令将值放入%edx,并将该值放入%eax。 My understanding is that the second one is ...something... to do with pointers. 我的理解是第二个是与指针有关的东西。 But wouldn't %ebx be the address and whatever value it contains be the value at that address? 但是%ebx是不是地址,它包含的值是该地址的值?

I've looked a lot of different tutorials, wiki articles, powerpoints, and stack overflow posts, but I can't find anyone that's clearly explained it. 我看过很多不同的教程,Wiki文章,PowerPoint和堆栈溢出帖子,但找不到任何明确解释的人。 The best I've seen is at http://www.scs.stanford.edu/nyu/04fa/notes/l2.pdf . 我见过的最好的网站http://www.scs.stanford.edu/nyu/04fa/notes/l2.pdf

They give the example 他们举个例子

movl    %edx, %eax    //edx = eax
movl    (%ebx), %eax  //edx = *((int32_t*) ebx)

Which confirms I was right about the first, but the second they are typecasting ebx as a pointer or..? 哪一个确认我对第一个是正确的,但是第二个它们正在将ebx作为指针或..类型转换? It's part of an assignment for class which I accidentally came across the answer while searching for existing questions. 这是课堂作业的一部分,我在寻找现有问题时不小心碰到了答案。 The assignment is almost identical to C, Assembly : understanding the switch condition, edx eax ecx and Pointers in Assembly , but honestly I didn't read those because I don't want to learn what the answers are from the posts, I want to learn how to do it and check my work against them. 分配几乎与C,Assembly相同:了解开关条件,edx eax ecxAssembly中的Pointers ,但是说实话,我没有阅读这些内容,因为我不想从帖子中了解答案,我想学习如何做,并对照他们检查我的工作。

Thanks if you can help!! 谢谢您的帮助!

http://en.wikipedia.org/wiki/X86_assembly_language#Syntax http://en.wikipedia.org/wiki/X86_assembly_language#Syntax

The ATT syntax uses source before destination, so ATT语法在目标之前使用源

movl %edx, %eax

is equivalent to 相当于

eax = edx

The more complicated example 更复杂的例子

movl (%ebx), %eax

is equivalent to 相当于

eax = *((int32 *) ebx;

The reason for the int32 is that the instruction has the letter l at the end (that's a lower case L). 使用int32的原因是该指令的末尾有字母l (即小写L)。 Different letters specify different types, but l specifies a signed 32-bit number. 不同的字母指定不同的类型,但是l指定一个带符号的32位数字。 The parentheses around (%ebx) indicate that an effective address is being specified. 圆括号(%ebx)表示正在指定有效地址。 An effective address has only one mandatory element (the BASE address), and 3 optional elements. 一个有效地址只有一个必需元素( BASE地址)和3个可选元素。 In your example, only the mandatory base address is supplied. 在您的示例中,仅提供了必需的基本地址。 When given an instruction with an effective address, the address is computed as follows 当给出具有有效地址的指令时,该地址的计算如下

address = base + index * scale + displacement

In the C version of the statement, casting ebx to an (int32 *) converts the value in ebx to a pointer that points to an int32 at the effective address, and then dereferencing that pointer reads the 32-bit number at that address. 在该语句的C版本中,将ebx强制转换为(int32 *)会将ebx的值转换为指向有效地址处的int32的指针,然后取消对该指针的引用以读取该地址处的32位数字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM