title: Why does gcc generate verbose assembly code?
body: <p>I have a question about assembly code generated by GCC (-S option). 
  Since, I am new to assembly language and know very little about it, the question will be very primitive. Still, I hope somebody will answer:</p>
  
  <p>Suppose, I have this C code:</p>
  
  <pre><code>main(){
  
      int x = 15; 
  
      int y = 6;
  
      int z = x - y;
  
  
      return 0;
  }
  </code></pre>
  
  <p>If we look at the assembly code (especially the part corresponding to int z = x - y ), we see:</p>
  
  <p>main:</p>
  
  <pre><code>...
  subl    $16, %esp
  movl    $15, -4(%ebp)
  movl    $6, -8(%ebp)
  movl    -8(%ebp), %eax
  movl    -4(%ebp), %edx
  movl    %edx, %ecx
  subl    %eax, %ecx
  movl    %ecx, %eax
  movl    %eax, -12(%ebp)
  ...
  </code></pre>
  
  <p>Why doesn't GCC generate something like this, which is less copying things around.</p>
  
  <p>main:</p>
  
  <pre><code>...
  movl    $15, -4(%ebp)
  movl    $6, -8(%ebp)
  movl    -8(%ebp), %edx          
  movl    -4(%ebp), %eax          
  subl    %edx, %eax              
  movl    %eax, -12(%ebp)
  ...
  </code></pre>
  
  <p>P.S.</p>
  
  <p>Linux zion-5 2.6.32-21-generic #32-Ubuntu SMP Fri Apr 16 08:10:02 UTC 2010 i686 GNU/Linux
  gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)</p>