title: local storage on the stack
body: <p>I have learned that there are some common cases of local storage on the stack</p>
  
  <p><strong>case 1</strong>: There are not enough registers to hold all of the local data</p>
  
  <p><strong>case 2</strong>: The address operator '&amp;' is applied to a local variable, and hence we must be able to generate an address for it</p>
  
  <p><strong>case 3</strong>: Some of the local variables are arrays of structures and hence must be accessed by array or structure reference.</p>
  
  <p>In the practice problem there are some codes</p>
  
  <pre><code>long call_proc()
  {
   long x1=1; int x2= 2;
   short x3=3; char x4=4;
   proc(x1,&amp;x1,x2,&amp;x2,x3,&amp;x3,x4,&amp;x4);
   return (x1+x2)*(x3-x4);
  }
  
  &lt;generated assembly code&gt;
  
  call_proc:
  subq $32, %rsp
  movq $1, 24(%rsp)
  movl $2, 20(%rsp)
  movw $3, 18(%rsp)
  movb $4, 17(%rsp)
  leaq 17(%rsp), %rax
  movq %rax, 8(%rsp)
  movl $4, (%rsp)
  leaq 18(%rsp), %r9
  movl $3, %r8d
  leaq 20(%rsp), %rcx
  movl $2, %edx
  leaq 24(%rsp), %rsi
  movl $1, %edi
  call proc
  .....
  </code></pre>
  
  <p>Q1. In this practice, Is it applied case2 not case1 according to that kind of cases?</p>
  
  <p>Q2. If it is correct case2, Can I get some examples about case1? </p>
  
  <p>Q3. By assuming that code I think it is not necessary for all local variable to be saved in stack like x1, x2, x3, x4. Is it reasonable assuming?</p>