Quiz Entry - updated: 2026.07.14
What does lea 0x1(%rax,%rax,1), %eax compute?
It computes 2*%rax + 1 in one instruction — %rax + %rax*1 + 1 via the offset(base,index,scale) address formula (no memory is touched).
Breaking it down with the memory operand formula offset(base, index, scale):
- offset =
0x1 - base =
%rax - index =
%rax - scale =
1
Result: %rax + %rax * 1 + 1 = 2 * %rax + 1
Where it appears: Recursive binary search functions that encode the search path. Going right returns 2 * recursive_result + 1.
Similar patterns:
| Instruction | Computes |
|---|---|
lea (%rax,%rax,1), %eax |
2 * rax |
lea 0x1(%rax,%rax,1), %eax |
2 * rax + 1 |
lea (%rax,%rax,2), %eax |
3 * rax |
lea 0x5(%rax,%rax,4), %eax |
5 * rax + 5 |
Go deeper: