Volume 3: General-Purpose and System Instructions - Stanford ...

Volume 3: General-Purpose and System Instructions - Stanford ... Volume 3: General-Purpose and System Instructions - Stanford ...

scs.stanford.edu
from scs.stanford.edu More from this publisher
13.07.2015 Views

AMD64 Technology 24594 Rev. 3.10 February 2005LEALoad Effective AddressComputes the effective address of a memory location (second operand) and stores it ina general-purpose register (first operand).The address size of the memory location and the size of the register determine thespecific action taken by the instruction, as follows:• If the address size and the register size are the same, the instruction stores theeffective address as computed.• If the address size is longer than the register size, the instruction truncates theeffective address to the size of the register.• If the address size is shorter than the register size, the instruction zero-extendsthe effective address to the size of the register.If the second operand is a register, an undefined-opcode exception occurs.The LEA instruction is related to the MOV instruction, which copies data from amemory location to a register, but LEA takes the address of the source operand,whereas MOV takes the contents of the memory location specified by the sourceoperand. In the simplest cases, LEA can be replaced with MOV. For example:lea eax, [ebx]has the same effect as:mov eax, ebxHowever, LEA allows software to use any valid ModRM and SIB addressing mode forthe source operand. For example:lea eax, [ebx+edi]loads the sum of the EBX and EDI registers into the EAX register. This could not beaccomplished by a single MOV instruction.The LEA instruction has a limited capability to perform multiplication of operands ingeneral-purpose registers using scaled-index addressing. For example:lea eax, [ebx+ebx*8]loads the value of the EBX register, multiplied by 9, into the EAX register. Possiblevalues of multipliers are 2, 4, 8, 3, 5, and 9.The LEA instruction is widely used in string-processing and array-processing toinitialize an index register (rSI or rDI) before performing string instructions such as182 LEA

24594 Rev. 3.10 February 2005 AMD64 TechnologyMOVSx. It is also used to initialize the rBX register before performing the XLATinstruction in programs that perform character translations. In data structures, theLEA instruction can calculate addresses of operands stored in memory, and inparticular, addresses of array or string elements.Mnemonic Opcode DescriptionLEA reg16, mem 8D /r Store effective address in a 16-bit register.LEA reg32, mem 8D /r Store effective address in a 32-bit register.LEA reg64, mem 8D /r Store effective address in a 64-bit register.Related InstructionsMOVrFLAGS AffectedNoneExceptionsVirtualException Real 8086 Protected Cause of ExceptionInvalid opcode, #UD X X X The source operand was a register.LEA 183

AMD64 Technology 24594 Rev. 3.10 February 2005LEALoad Effective AddressComputes the effective address of a memory location (second oper<strong>and</strong>) <strong>and</strong> stores it ina general-purpose register (first oper<strong>and</strong>).The address size of the memory location <strong>and</strong> the size of the register determine thespecific action taken by the instruction, as follows:• If the address size <strong>and</strong> the register size are the same, the instruction stores theeffective address as computed.• If the address size is longer than the register size, the instruction truncates theeffective address to the size of the register.• If the address size is shorter than the register size, the instruction zero-extendsthe effective address to the size of the register.If the second oper<strong>and</strong> is a register, an undefined-opcode exception occurs.The LEA instruction is related to the MOV instruction, which copies data from amemory location to a register, but LEA takes the address of the source oper<strong>and</strong>,whereas MOV takes the contents of the memory location specified by the sourceoper<strong>and</strong>. In the simplest cases, LEA can be replaced with MOV. For example:lea eax, [ebx]has the same effect as:mov eax, ebxHowever, LEA allows software to use any valid ModRM <strong>and</strong> SIB addressing mode forthe source oper<strong>and</strong>. For example:lea eax, [ebx+edi]loads the sum of the EBX <strong>and</strong> EDI registers into the EAX register. This could not beaccomplished by a single MOV instruction.The LEA instruction has a limited capability to perform multiplication of oper<strong>and</strong>s ingeneral-purpose registers using scaled-index addressing. For example:lea eax, [ebx+ebx*8]loads the value of the EBX register, multiplied by 9, into the EAX register. Possiblevalues of multipliers are 2, 4, 8, 3, 5, <strong>and</strong> 9.The LEA instruction is widely used in string-processing <strong>and</strong> array-processing toinitialize an index register (rSI or rDI) before performing string instructions such as182 LEA

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!