为什么在 LEA 中使用方括号? [英] Why are Square Brackets used in LEA?
问题描述
在汇编中,方括号[]
似乎与C 编程语言中的*
具有相同的含义.它们用于取消引用指针.取消引用指针意味着要引用特定的内存位置来读取或写入它.
In assembly, the square brackets []
seem to have the same meaning as *
in C programming language. They are used to dereference a pointer.
Dereferencing a pointer means going to refer to a specific memory location to read or write it.
因此,在 MOV
的情况下使用方括号是非常合乎逻辑的.但他们也将其用于 LEA 的合乎逻辑的原因是什么?
So, it is quite logical to use square brackets in the case of a MOV
.
But what is the logical reason why they also use it for LEA?
LEA EAX, [EBP -4]
, 看起来像是取消引用一个指针,EBP - 4
,来引用指向的内存位置,但它不会读取值包含在位置而不是地址中.
LEA EAX, [EBP -4]
, looks like dereferencing a pointer, EBP - 4
, to refer to the pointed memory location but it will not read the value contained in the location but rather the address.
我对此有点困惑.你能给我一个正确的思考方式吗?LEA
与取消引用的概念有什么联系吗?显然不是为了读取内存,而主要是指内存位置不是为了它的值,而是为了它的地址.我不希望这成为一个哲学问题.
I'm a little confused about this. Could you give me the right way to think about this?
Does LEA
have any connection with the concept of dereferencing?
Clearly not intended as a memory reading, but mostly as referring to a location of memory not for its value, but for its address.
I wouldn't want this to become a philosophical question.
推荐答案
LEA
指令被设计成一个内存访问指令——因此可以执行所有 寻址模式. 当然,正如您所注意到的,区别在于 LEA
加载有效地址"而不是该位置的内存值.
The LEA
instruction is designed to look like a memory access instruction — so can perform all the addressing modes. The difference, of course, as you're noting is that LEA
loads the "effective address" rather than a memory value from that location.
因此,LEA
类似于内存访问操作,但具体而言,在 C 术语中,是获取地址——就像 C 中的 &a[i]
. 就像在带有 &
的 C 中一样,LEA
的结果总是一个指针大小的值,而不是我们可以获取/存储字节、字等的实际访问.
Thus, LEA
is similar to memory access operations, but specifically, in C terms, is taking the address — so like &a[i]
in C. Like in C with &
, the result of LEA
is always a pointer sized value rather than with real accesses where we can fetch/store a byte, word, etc..
这篇关于为什么在 LEA 中使用方括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!