リスト5 リスト6 リスト7


〔リスト5〕可変長自動配列が最適化されて通常の配列に解釈される例(test50.c)
	#include <stdio.h>
	void AllocTbl(int size);
	int main(void)
	{
	 int size;
	 printf("input size ....:");
	 scanf("%d",&size);
	 AllocTbl(size);
	 return;
	}
	void AllocTbl(int size)
	{
	 int size1 = 10;
	 int size2 = 20;
	 char str[size1*size2];
	 str[size+1] = 0;
	 return;
	}


〔リスト6〕最適化なしのコンパイルで生成されたアセンブラ(test50.s)
	 .file "test50.c"
	 .version "01.01"
	gcc2_compiled.:
	  .section .rodata
	.LC0:
	 .string "input size ....:"
	.LC1:
	 .string "%d"
	.text
	 .align 4
	.globl main
	 .type  main,@function
	main:
	 pushl %ebp
	 movl  %esp, %ebp
	 subl  $8, %esp
	 subl  $12, %esp
	 pushl $.LC0
	 call  printf
	 addl  $16, %esp
	 subl  $8, %esp
	 leal  -4(%ebp), %eax
	 pushl %eax
	 pushl $.LC1
	 call  scanf
	 addl  $16, %esp
	 subl  $12, %esp
	 pushl -4(%ebp)
	 call  AllocTbl
	 addl  $16, %esp
	 leave
	 ret
	.Lfe1:
	 .size  main,.Lfe1-main
	 .align 4
	.globl AllocTbl
	 .type  AllocTbl,@function
	AllocTbl:
	 pushl %ebp
	 movl  %esp, %ebp
	 pushl %esi
	 pushl %ebx
	 subl  $16, %esp
	 movl  %esp, %esi
	 movl  $10, -12(%ebp)
	 movl  $20, -16(%ebp)
	 movl  -12(%ebp), %eax
	 movl  %eax, %ebx
	 imull -16(%ebp), %ebx
	 decl  %ebx
	 movl  %ebx, -24(%ebp)
	 movl  $0, -20(%ebp)
	 movl  $8, %eax
	 mull  -24(%ebp)
	 imull $0, -24(%ebp), %ecx
	 addl  %ecx, %edx
	 imull $8, -20(%ebp), %ecx
	 addl  %ecx, %edx
	 movl  %eax, %eax
	 movl  %edx, %edx
	 addl  $8, %eax
	 adcl  $0, %edx
	 leal  1(%ebx), %eax
	 addl  $15, %eax
	 shrl  $4, %eax
	 movl  %eax, %eax
	 sall  $4, %eax
	 subl  %eax, %esp
	 movl  %esp, %edx
	 movl  8(%ebp), %eax
	 incl  %eax
	 movb  $0, (%eax,%edx)
	 movl  %esi, %esp
	 leal  -8(%ebp), %esp
	 popl  %ebx
	 popl  %esi
	 popl  %ebp
	 ret
	.Lfe2:
	 .size  AllocTbl,.Lfe2-AllocTbl
	 .ident "GCC: (GNU) 2.96 20000731 (Red Hat Linux 7.3 2.96-110)"


〔リスト7〕最適化-O3オプションのコンパイルで生成されたアセンブラ(test51.s)
	 .file "test51.c"
	 .version "01.01"
	gcc2_compiled.:
	 .section .rodata.str1.1,"aMS",@progbits,1
	.LC0:
	 .string "input size ....:"
	.LC1:
	 .string "%d"
	.text
	 .align 4
	.globl AllocTbl
	 .type  AllocTbl,@function
	AllocTbl:
	 pushl %ebp
	 movl  %esp, %ebp
	 subl  $8, %esp
	 movl  8(%ebp), %eax
	 movl  %esp, %edx
	 incl  %eax
	 subl  $208, %esp
	 movb  $0, (%esp,%eax)
	 movl  %edx, %esp
	 leave
	 ret
	.Lfe1:
	 .size  AllocTbl,.Lfe1-AllocTbl
	 .align 4
	.globl main
	 .type  main,@function
	main:
	 pushl %ebp
	 movl  %esp, %ebp
	 subl  $20, %esp
	 pushl $.LC0
	 call  printf
	 popl  %edx
	 popl  %ecx
	 leal  -4(%ebp), %eax
	 pushl %eax
	 pushl $.LC1
	 call  scanf
	 popl  %eax
	 pushl -4(%ebp)
	 call  AllocTbl
	 addl  $16, %esp
	 leave
	 ret
	.Lfe2:
	 .size  main,.Lfe2-main
	 .ident "GCC: (GNU) 2.96 20000731 (Red Hat Linux 7.3 2.96-110)"