For me, it just seems like a funky MOV. What's its purpose and when should I use it?
相关问题
- Null-terminated string, opening file for reading
- What's the difference between 0 and dword 0?
- Translate the following machine language code (0x2
- Where can the code be more efficient for checking
- NASM x86 print integer using extern printf
相关文章
- Is it possible to run 16 bit code in an operating
- How to generate assembly code with gcc that can be
- Select unique/deduplication in SSE/AVX
- Optimising this C (AVR) code
- Why does the latency of the sqrtsd instruction cha
- Difference in ABI between x86_64 Linux functions a
- On a 64 bit machine, can I safely operate on indiv
- x86 instruction encoding tables
Maybe just another thing about LEA instruction. You can also use LEA for fast multiplying registers by 3, 5 or 9.
The 8086 has a large family of instructions which accept a register operand and an effective address, perform some computations to compute the offset part of that effective address, and perform some operation involving the register and the memory referred to by the computed address. It was fairly simple to have one of the instructions in that family behave as above except for skipping that actual memory operation. This, the instructions:
were implemented almost identically internally. The difference is a skipped step. Both instructions work something like:
As for why Intel thought this instruction was worth including, I'm not exactly sure, but the fact that it was cheap to implement would have been a big factor. Another factor would have been the fact that Intel's assembler allowed symbols to be defined relative to the BP register. If
fnord
was defined as a BP-relative symbol (e.g. BP+8), one could say:If one wanted to use something like stosw to store data to a BP-relative address, being able to say
was more convenient than:
Note that forgetting the world "offset" would cause the contents of location [BP+8], rather than the value 8, to be added to DI. Oops.
it because instead you write the code
you can simply write
The LEA instruction can be used to avoid time consuming calculations of effective addresses by the CPU. If an address is used repeatedly it is more effective to store it in a register instead of calculating the effective address every time it is used.
LEA : just an "arithmetic" instruction..
MOV transfers data between operands but lea is just calculating
Despite all the explanations, LEA is an arithmetic operation:
It's just that its name is extremelly stupid for a shift+add operation. The reason for that was already explained in the top rated answers (i.e. it was designed to directly map high level memory references).