LOGBOOK

HELP

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.

For the same operand (%rdi,%rsi,4), lea stores the computed address itself while mov dereferences it and stores MEM 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:

  1. 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
  1. 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:

From Quiz: REVE1 / Assembly Patterns & GDB | Updated: Jul 06, 2026