title: Subtracting registers with an LEA instruction?
body: <p>Does the LEA instruction support negative displacement?</p>
  <pre><code>mov rax, 1
  lea rsi, [rsp - rax]
  </code></pre>
  <p>When I use the above code in my asm file I got the error:</p>
  <pre><code>$ nasm -f macho64 test.asm
  $ error: invalid effective address
  </code></pre>
  <p>I Know that we can do pointer arithmetic like this in C:</p>
  <pre><code>void foo(char *a, size_t b) {
      *(a - b) = 1;
  }
  </code></pre>
  <p>then I assume that:</p>
  <pre><code>lea rsi, [rsp - rax]    
  </code></pre>
  <p>will work.</p>
  <p>And I also try to see what the GCC compiler do by using:</p>
  <pre><code>$ gcc -S foo.c // foo.c has the function foo(above) in it
  </code></pre>
  <p>but my asm knowleage is not enough for me the understand the asm output
  from the GCC compiler.</p>
  <p>Can anyone explain why:</p>
  <pre><code>lea rsi, [rsp - rax]    ;; invalid effective address
  </code></pre>
  <p>does not work. And I'm using these to achieve the samething:</p>
  <pre><code>;; assume rax has some positive number
  neg rax    
  lea rsi, [rsp + rax]
  neg rax
  </code></pre>
  <p>or</p>
  <pre><code>sub rsp, rax
  mov rsi, rsp
  add rsp, rax
  </code></pre>
  <p>What is a more standard way of doing it?</p>
  <p>I'm using NASM version 2.11.08 compiled on Nov 26 2015 on MAC OSX 10.11</p>
  <p>Thank you in advance for your help!</p>