Quiz Entry - updated: 2026.07.06
What does the lea instruction do and how is it different from mov?
lea computes the address and stores the address itself; mov with the same operand would instead read the memory at that address.
* lea keeps the computed address; mov with the same operand instead loads the value stored there. *
# rax = rdi + rsi*4 (just math, no memory access)
lea (%rdi,%rsi,4), %rax
# rax = MEM[rdi + rsi*4] (reads from memory)
mov (%rdi,%rsi,4), %rax
Common uses:
- Fast arithmetic — multiply and add in one instruction:
# rax = rdi * 3
lea (%rdi,%rdi,2), %rax
# rax = rdi * 5 + 7
lea 7(%rdi,%rdi,4), %rax
- Address computation — get pointer to array element:
# rax = &A[i]
lea (%rdi,%rsi,4), %rax
Key property: lea never accesses memory and never modifies flags.
Go deeper:
LEA instruction reference — confirms LEA computes the effective address, touches no memory, and affects no flags.
x86 instruction listings (Wikipedia) — places LEA among mov and the addressing-mode instructions for comparison.