Compiler kennenlernen

ein simples C-Programm:

int f (int x, int y) {
  int i; int s = 0;
  for (i = 0; i < x; i++) {
    s = s + y;
  }
}

compilieren mit gcc -S ergibt (für Intel)

	.file	"compute.c"
	.text
.globl f
	.type	f, @function
f:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp
	movl	$0, -8(%ebp)
	movl	$0, -4(%ebp)
.L2:
	movl	-4(%ebp), %eax
	cmpl	8(%ebp), %eax
	jl	.L5
	jmp	.L3
.L5:
	movl	12(%ebp), %eax
	leal	-8(%ebp), %edx
	addl	%eax, (%edx)
	leal	-4(%ebp), %eax
	incl	(%eax)
	jmp	.L2
.L3:
	leave
	ret
	.size	f, .-f
	.section	.note.GNU-stack,"",@progbits
	.ident	"GCC: (GNU) 3.3.3 (SuSE Linux)"

mit gcc für Sparc vergleichen,

mit cc vergleichen (Sun-compiler)



Johannes Waldmann 2006-02-02