0

Consider this: leaq 20(%rdi),%rsi subq %rdi, %rsi

Why would %rsi hold 20? Shouldn't it hold address of %rdi+20 - %rdi ? Thanks in advance

  • 2
    Try to reason about what `%rdi` + `20` - `%rdi` will be. `x = a + b - a` if `b` is `20` and we don't know `a`, can we still say something about `x`? – Erik Eidt Aug 24 '21 at 17:37
  • Suppose rdi holds the value 12345. Then `leaq 20(%rdi), %rsi` loads `rsi` with the address of the byte which is at address `%rdi+20` - which is just another way of saying "it loads rsi with the number `%rdi+20`, i.e. the number 12365". Subtract 12345 and you have 20. – Nate Eldredge Aug 24 '21 at 17:37
  • I assume the reason this isn't obvious is that you think there's some kind of "address of" going on, or that LEA has something to do with memory. It's not, it's just a shift-and-add instruction. – Peter Cordes Aug 24 '21 at 17:44

0 Answers0