title: Assembly - Why strtol clobbers %rcx register?
body: <h3>Context :</h3>
  
  <p>Linux 64.</p>
  
  <p>GCC 4.8.2 (with -O3 -march=native)</p>
  
  <p>The x86_64 abi under my left hand, opened at page 21.</p>
  
  <h3>The C code :</h3>
  
  <pre><code>int main (int argc, char ** argv) {
  
       printf("%d %s\n", atoi(argv[2]),argv[1] );
  }
  </code></pre>
  
  <h3>The assembly code :</h3>
  
  <p>(notice that the compiler replaced atoi with strtol by itself)</p>
  
  <pre><code>...
      movl    $10, %edx
      movq    16(%rsi), %rdi
      movq    8(%rsi), %rbx
      xorl    %esi, %esi
      call    strtol
      movl    $.LC0, %edi
      movq    %rbx, %rdx
      movl    %eax, %esi
      xorl    %eax, %eax
      call    printf
      xorl    %eax, %eax
      popq    %rbx
  ...
  </code></pre>
  
  <h3>The question :</h3>
  
  <p><code>%rcx</code> should be reserved for the 4th input integer argument.</p>
  
  <p><code>strtol</code> has 3 input args (respectively registers <code>%rdi</code>, <code>%rsi</code>, <code>%rdx</code>) and one return, <code>%eax</code>.</p>
  
  <p><strong>Why then is <code>%rcx</code> clobbered ?</strong>
  This code won't make it :</p>
  
  <pre><code>...
      movl    $10, %edx
      movq    16(%rsi), %rdi
      movq    8(%rsi), %rcx &lt;-- look I replaced with %ecx
      xorl    %esi, %esi
      call    strtol
      movl    $.LC0, %edi
      movq    %rcx, %rdx &lt;-- look I replaced with %ecx
      movl    %eax, %esi
      xorl    %eax, %eax
      call    printf
      xorl    %eax, %eax
      popq    %rbx
  ...
  </code></pre>
  
  <p>Thanks</p>