Square Brackets ? why are these used in LEA?

喜你入骨 提交于 2021-01-24 08:18:13

问题


In assmebly the square brackets seem to have the same meaning as * in C. They are used to dereference a pointer. Dereferencing a pointer means going to refer to a specific memory location to read or write it. 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], 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. 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.


回答1:


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.

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..



来源:https://stackoverflow.com/questions/58959965/square-brackets-why-are-these-used-in-lea

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