
CS 2734
Computer Organization II -- Spring 2001
Laboratory 4 [Feb 5, 7]:
Simple program
and simple array
-
Prior to the laboratory, you should do the following:
-
Make a separate directory for laboratory 4 and put all of
the code that you develop for this lab in that directory.
-
Write two MIPS programs:
-
The first is a program that prints the first 20 Fibonacci
numbers on a line, with a space between each one, [Note: the Fibonacci
numbers are the sequence 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ..., each
number the sum of the two previous ones.]
-
Modify the first program into a second that allocates space
for an integer array (A) of size 20 and stores the first 20 Fibonacci numbers
into this array. Then it should print the numbers in this array, on one
line with a blank between each one.
-
Be sure to thoroughly document your programs following the
style of the programs discussed in class.
-
Implementation Notes:
-
The first program can be based on the following C program:
four06% cat lab4_1.c
#include <stdio.h>
void main(void)
{
int F0, F1, F2;
int i, last;
F0 = 0; F1 = 1;
i = 0; last = 20;
do {
F2 = F0 + F1;
printf("%i ", F0);
F0 = F1;
F1 = F2;
i = i + 1;
} while (i < last);
printf("\n");
}
four06% cc -o lab4_1 lab4_1.c
four06% lab4_1
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181
four06%
The second program can be based on the following C program:
four06% cat lab4_2.c
#include <stdio.h>
void main(void)
{
int A[20];
int i, last;
A[0] = 0; A[1] = 1;
i = 2; last = 20;
do {
A[i] = A[i-1] + A[i-2];
i = i + 1;
} while (i < last);
i = 0;
do {
printf("%i ", A[i]);
i = i + 1;
} while (i < last);
printf("\n");
}
four06% cc -o lab4_2 lab4_2.c
four06% lab4_2
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181
four06%
For Checkoff:
-
Handle each program separately, finishing the first before
the second. Get a printout of each program. Give the program to the
lab instructor before he starts your check-off procedure.
-
Run your program for the lab instructor and let him see that
you got the correct values.
Revision date: 2001-02-02.
(Please use ISO
8601, the International Standard.)