how does LEA and several instruction work?
This question already has an answer here:
The first two load the contents of 32 bits pointed to by bx
into ds
and si
(or es
and di
).
The second two are the same because the values are literals. If, however they were:
lea di,[bx]
mov di,[bx]
then your expectation would be right: the former putting the address bx
into di
and the latter putting the 16 bits pointed to by bx
into di
.
For more information on both, see this question for les
/ lds
and this question for mov
/ lea
.
LEA doesn't actually load anything from memory. It just sets a sum of up to two source registers (one may be multiplied) and an immediate value to a destination register. For example "lea bp, [bx*2+si+3]" sets to the bp register the sum of bx multiplied by two plus si plus 3.
LDS and LES, to the contrary, load values from memory to the pair of registers: one segment register (DS or ES) and one general register. There are also versions for the other registers: LFS, LGS and LSS for FS, GS and SS segment registers respectively (introduced in 80386).
So these instructions load "far" pointer - a pointer consisting of a 16-bit segment selector and a 16-bit (or a 32-bit, depending on mode) offset, so the total far pointer size was 32-bit in 16-bit mode and 48-bit in 32-bit mode.
These are extremely useful instructions for 16-bit mode, be it 16-bit real mode or 16-bit protected mode.
Under 32-bit mode, there is no need in these instructions since all segment registers are essentially point to the same locations, so there is no need to load segment registers.
Under 64-bit modes, these instructions are not implemented, their opcode gave access violations. Since Intel's implementation of VEX - "vector extensions - (SSE2), Intel took their opcodes of LDS and LES and started using them for VEX prefixes. As a result, 256-bit AVX (YMM) registers are only available in 64-bit mode.
链接地址: http://www.djcxy.com/p/72366.html上一篇: Qt Creator汇编输出
下一篇: LEA和几条指令如何工作?