リスト1 リスト2 リスト3 リスト4


〔リスト1〕可変長自動配列を使った例(test48.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)
	{
	 char str[size];
	 str[size+1] = 0;
	 return;
	}


〔リスト2〕test48.cから生成されたアセンブラ(test48.s)
	 .file "test48.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  8(%ebp), %ebx
	 decl  %ebx
	 movl  %ebx, -16(%ebp)
	 movl  $0, -12(%ebp)
	 movl  $8, %eax
	 mull  -16(%ebp)
	 imull $0, -16(%ebp), %ecx
	 addl  %ecx, %edx
	 imull $8, -12(%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)"


〔リスト3〕通常の自動配列を使った例(test49.c)
	#include <stdio.h>
	void AllocTbl(int size);
	int main(void)
	{
	 int size;
	 printf("input size but less than 10000....:");
	 scanf("%d",&size);
	 AllocTbl(size);
	 return;
	}
	void AllocTbl(int size)
	{
	 char str[10001];
	 str[size+1] = 0;
	 return;
	}


〔リスト4〕test49.cから生成されたアセンブラ(test49.s)
	 .file "test49.c"
	 .version "01.01"
	gcc2_compiled.:
	  .section .rodata
	 .align 32
	.LC0:
	 .string "input size but less than 10000....:"
	.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
	 subl  $10024, %esp
	 movl  8(%ebp), %eax
	 incl  %eax
	 leal  -10024(%ebp), %edx
	 movl  %edx, %edx
	 movb  $0, (%eax,%edx)
	 leave
	 ret
	.Lfe2:
	 .size  AllocTbl,.Lfe2-AllocTbl
	 .ident "GCC: (GNU) 2.96 20000731 (Red Hat Linux 7.3 2.96-110)"