Volume 3: General-Purpose and System Instructions - Stanford ...
Volume 3: General-Purpose and System Instructions - Stanford ... Volume 3: General-Purpose and System Instructions - Stanford ...
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
- Page 162 and 163: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 164 and 165: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 166 and 167: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 168 and 169: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 170 and 171: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 172 and 173: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 174 and 175: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 176 and 177: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 178 and 179: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 180 and 181: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 182 and 183: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 184 and 185: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 186 and 187: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 188 and 189: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 190 and 191: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 192 and 193: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 194 and 195: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 196 and 197: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 198 and 199: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 200 and 201: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 202 and 203: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 204 and 205: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 206 and 207: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 208 and 209: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 210 and 211: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 214 and 215: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 216 and 217: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 218 and 219: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 220 and 221: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 222 and 223: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 224 and 225: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 226 and 227: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 228 and 229: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 230 and 231: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 232 and 233: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 234 and 235: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 236 and 237: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 238 and 239: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 240 and 241: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 242 and 243: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 244 and 245: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 246 and 247: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 248 and 249: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 250 and 251: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 252 and 253: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 254 and 255: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 256 and 257: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 258 and 259: AMD64 Technology 24594 Rev. 3.10 Fe
- Page 260 and 261: AMD64 Technology 24594 Rev. 3.10 Fe
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