Project Part 4: Code Generation

Goal

In contrast to the last year we will not require to write a compiler to produce executable code. But, you should at least learn a little bit about code generation.

Therefore, we require in this last exercise that you translate the two sample C- programs Fibonacci numbers:

  1. Recursive: fibrec.c-
  2. With arrays: fibarr.c-
into executable code for BVM.

Deadline

You have to hand in your answers no later than Friday November 22nd 2002 at 10:15 am.

Contents

The answers handed in must include:

Example

Input might be the following:

int foo(i) {
  int a, b;
  return i;
}
int main() {
  int a[10];
  foo(a[0]);
}

which should give the following output:

;foo(i) {
.function foo(I)I
.locals 3
.stack 1
;  int a, b;
   iconst_0
   istore 1
   iconst_0
   istore 2
;  return i;
	iload 0
	ireturn
;}
	iconst_0
	ireturn
;main() {
.function main()I
.locals 1
.stack 2
;  int a[10];
	ldc_w 10
	newarray
	astore 0
;  foo(a[0]);
	aload 0
	ldc_w 0
	iaload
	invokestatic foo(I)I
	pop
;}
	iconst_0
	ireturn

Dokumentasjon