Computer
Organization and Design
(Textbook. Click for information.)
 CS 2733/2731
 Computer Organization II
 Fall 2004

 Recitation 5
 Function Calls, Parameters,
 and Automatic and Static Variables

    Week 5: Sep 20-24
 Due (on time): 2004-09-29  23:59:59
 Due (late):        2004-10-03  23:59:59

Recitation 5 must be submitted following directions at: submissions on or before
  • 2004-09-29  23:59:59 (that's Wednesday, 29 September 2004, 11:59:59 pm) for full credit.
  • 2004-10-03  23:59:59 (that's Sunday, 3 October 2004, 11:59:59 pm) for 75% credit.

Outline: This laboratory practices function calls and the use of parameters (including an array as a parameter), and works with the representation of static and automatic variables. You must allocate an array on the stack as an automatic variable. Note that you were given code for one of these functions (writeArray) as part of a course handout about arrays: writeArray. This version of writeArray uses the array index approach, rather than the pointer approach. An earlier handout focused on array versus pointer notation, as discussed in your text, section 3.11, pages 171-174. This example shows two ways to print arrays, though it does not use a function for this: array2.s. Finally, the code below asks you to make use of an array allocated on the stack (the array C below), and the following course handout shows how to do this: array on the stack. (In this code, the line add $sp, $sp, -40 allocated 10 words on the stack. Then the numbers 10, 20, ... are stored into this array, and finally writeArray is used to print them.)


Implementation Notes: Model your MIPS program after the following C program:

Third Program (C) C Run and Output

#include <stdio.h>
int computeArray(int [], int );   
int addUp(int , int , int );
void writeArray(int [], int );
/* global arrays, first initialized */
int B[] = {10, 20, 30, 40, 50,
           60, 70, 80, 90, 100};
int A[10];

void main(void) {
   int n, r;
   scanf("%i", &n);
   writeArray(A, n);
   r = computeArray(A, n);
   printf("%i\n", r);
   writeArray(A, n);
}
int computeArray(int A[], int n) {
   int C[10];
   int i;
   for (i = 0; i < n; i++)   {        
      C[i] = addUp(A[i], B[i], i);
      A[i] = C[i] + 100;
   }
   writeArray(C, n);
   return C[0];
}
int addUp(int x, int y, int z) {
   return x+y+z;
}
void writeArray(int A[], int n) {
   int i;
   for (i = 0; i < n; i++)
      printf("%i ", A[i]);
   printf("\n");
}
% lab5
10        (input)
0 0 0 0 0 0 0 0 0 0
10 21 32 43 54 65 76 87 98 109
10
110 121 132 143 154 165 176 187 198 209
% lab5
6         (input)
0 0 0 0 0 0
10 21 32 43 54 65
10
110 121 132 143 154 165

You must transform this C code faithfully into MIPS assembler code, meaning that you do the following:

Also:


What you should submit: Refer to the submissions directions and to deadlines at the top of this page. The text file that you submit should first have Your Name, the Course Number, and the Recitation Number. The rest of the file should have the following in it, in the order below, and clearly labeled, including at the beginning the appropriate number 1-2.

  Contents of submission for Recitation 5:

Last Name, First Name; Course Number; Recitation Number (5).

  1. MIPS source code for the program.

  2. Log of runs of the program, using spim and the input data shown above for the separate runs, namely, 10 and 6.


Revision date: 2004-06-27. (Please use ISO 8601, the International Standard.)